BUILD.gn 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. # Copyright 2019 The Chromium Authors. All rights reserved.
  2. # Use of this source code is governed by a BSD-style license that can be
  3. # found in the LICENSE file.
  4. import("dav1d_generated.gni")
  5. import("//build/config/compiler/compiler.gni")
  6. import("//build/config/sanitizers/sanitizers.gni")
  7. import("//third_party/nasm/nasm_assemble.gni")
  8. # MemorySanitizer can't handle assembly, https://crbug.com/928357.
  9. enable_nasm = (current_cpu == "x86" || current_cpu == "x64") && !is_msan
  10. if (is_win) {
  11. platform_config_root = "config/win/$current_cpu"
  12. } else if (is_msan) {
  13. assert(current_cpu == "x64" && (is_linux || is_chromeos),
  14. "Only Linux X64 MSAN is supported")
  15. platform_config_root = "config/linux-noasm/$current_cpu"
  16. } else if (current_cpu == "riscv64") {
  17. platform_config_root = "config/linux-noasm/$current_cpu"
  18. } else {
  19. # Linux configuration files seem to work on Mac, so just reuse them.
  20. platform_config_root = "config/linux/$current_cpu"
  21. }
  22. # Clang LTO doesn't respect stack alignment and clang-cl doesn't support setting
  23. # the stack alignment, so we must use the platform's default alignment in those
  24. # cases; https://crbug.com/928743.
  25. if (current_cpu == "x86" || current_cpu == "x64") {
  26. if (use_thin_lto || is_win) {
  27. needs_stack_alignment = false
  28. # The defaults are stack_alignment=4 for x86 and stack_alignment=16 for x64.
  29. } else {
  30. # The compiler flags, as well as the stack alignment values, all mirror
  31. # upstream's meson.build setup:
  32. # https://chromium.googlesource.com/external/github.com/videolan/dav1d/+/master/meson.build
  33. needs_stack_alignment = true
  34. if (current_cpu == "x86") {
  35. stack_alignment = 16
  36. if (!is_clang) {
  37. # Values used by GCC.
  38. preferred_stack_boundary = 4
  39. incoming_stack_boundary = 2
  40. }
  41. } else if (current_cpu == "x64") {
  42. stack_alignment = 32
  43. if (!is_clang) {
  44. # Values used by GCC.
  45. preferred_stack_boundary = 5
  46. incoming_stack_boundary = 4
  47. }
  48. }
  49. if (is_clang) {
  50. stackalign_flag = "-mstack-alignment=$stack_alignment"
  51. stackrealign_flag = "-mstackrealign"
  52. } else {
  53. # Assume GCC for now.
  54. stackalign_flag = "-mpreferred-stack-boundary=$preferred_stack_boundary"
  55. stackrealign_flag = "-mincoming-stack-boundary=$incoming_stack_boundary"
  56. }
  57. }
  58. } else {
  59. needs_stack_alignment = false
  60. }
  61. config("public_dav1d_config") {
  62. include_dirs = [ "version" ]
  63. # Disable internal dav1d logs in the official build to save storage.
  64. if (is_official_build) {
  65. defines = [ "CONFIG_LOG=0" ]
  66. } else {
  67. defines = [ "CONFIG_LOG=1" ]
  68. }
  69. if (needs_stack_alignment) {
  70. defines += [ "STACK_ALIGNMENT=$stack_alignment" ]
  71. }
  72. if (!is_android && !is_win) {
  73. defines += [ "HAVE_PTHREAD_GETAFFINITY_NP=1" ]
  74. }
  75. # Don't let dav1d export any symbols. Otherwise the verify_order step on macOS
  76. # can fail since these exports end up in the final Chromium binary.
  77. defines += [ "DAV1D_API=" ]
  78. }
  79. config("dav1d_config") {
  80. configs = [ ":public_dav1d_config" ]
  81. include_dirs = [
  82. "libdav1d",
  83. "libdav1d/include",
  84. "libdav1d/include/dav1d",
  85. platform_config_root,
  86. ]
  87. if (is_win && !is_clang) {
  88. include_dirs += [ "libdav1d/include/compat/msvc" ]
  89. }
  90. }
  91. dav1d_copts = [
  92. "-D_FILE_OFFSET_BITS=64",
  93. "-D_POSIX_C_SOURCE=200112L",
  94. ]
  95. if (is_win) {
  96. if (!is_clang) {
  97. dav1d_copts += [ "/wd4028" ]
  98. }
  99. } else {
  100. dav1d_copts += [ "-std=c99" ]
  101. if (needs_stack_alignment) {
  102. dav1d_copts += [ stackalign_flag ]
  103. }
  104. if (is_mac || is_ios) {
  105. dav1d_copts += [ "-D_DARWIN_C_SOURCE" ]
  106. }
  107. if (is_linux || is_chromeos || is_android || current_os == "aix") {
  108. if (!is_clang) {
  109. dav1d_copts += [ "-D_GNU_SOURCE" ]
  110. }
  111. }
  112. }
  113. if (enable_nasm) {
  114. nasm_assemble("dav1d_asm") {
  115. sources = x86_asm_sources
  116. inputs = [
  117. "libdav1d/src/ext/x86/x86inc.asm",
  118. "$platform_config_root/config.asm",
  119. ]
  120. include_dirs = [
  121. "libdav1d/src/",
  122. platform_config_root,
  123. ]
  124. nasm_flags = [
  125. "-P",
  126. rebase_path("$platform_config_root/config.asm", root_build_dir),
  127. ]
  128. defines = []
  129. if (needs_stack_alignment) {
  130. defines += [ "STACK_ALIGNMENT=$stack_alignment" ]
  131. }
  132. # Necessary to ensure macOS symbols end up with a _ prefix.
  133. if (is_mac || is_ios) {
  134. defines += [ "PREFIX" ]
  135. }
  136. }
  137. }
  138. source_set("dav1d_headers") {
  139. configs -= [ "//build/config/compiler:chromium_code" ]
  140. configs += [
  141. "//build/config/compiler:no_chromium_code",
  142. ":dav1d_config",
  143. ]
  144. sources = c_headers
  145. }
  146. static_library("dav1d_entrypoints") {
  147. configs -= [ "//build/config/compiler:chromium_code" ]
  148. configs += [
  149. "//build/config/compiler:no_chromium_code",
  150. ":dav1d_config",
  151. ]
  152. sources = entry_point_sources
  153. cflags = dav1d_copts
  154. if (is_win) {
  155. sources += [ "libdav1d/src/win32/thread.c" ]
  156. }
  157. if (needs_stack_alignment) {
  158. cflags += [ stackrealign_flag ]
  159. }
  160. deps = [ ":dav1d_headers" ]
  161. }
  162. static_library("dav1d_8bit") {
  163. configs -= [ "//build/config/compiler:chromium_code" ]
  164. configs += [
  165. "//build/config/compiler:no_chromium_code",
  166. ":dav1d_config",
  167. ]
  168. sources = template_sources
  169. if (current_cpu == "x86" || current_cpu == "x64") {
  170. sources += x86_template_sources
  171. } else if (current_cpu == "arm") {
  172. sources += arm_template_sources
  173. } else if (current_cpu == "arm64") {
  174. sources += arm_template_sources
  175. } else if (current_cpu == "ppc64") {
  176. sources += ppc64_template_sources
  177. }
  178. cflags = dav1d_copts
  179. cflags += [ "-DBITDEPTH=8" ]
  180. deps = [ ":dav1d_headers" ]
  181. }
  182. static_library("dav1d_10bit") {
  183. configs -= [
  184. "//build/config/compiler:chromium_code",
  185. # Disable coverage for the 10 bit version to avoid confusing the
  186. # instrumentation about which version of the library is being run.
  187. # dav1d_10 bit was selected for this, as it's less used than dav1d_8bit,
  188. # which still has coverage enabled. See crbug.com/1030350.
  189. "//build/config/coverage:default_coverage",
  190. ]
  191. configs += [
  192. "//build/config/compiler:no_chromium_code",
  193. ":dav1d_config",
  194. ]
  195. sources = template_sources
  196. if (current_cpu == "x86" || current_cpu == "x64") {
  197. sources += x86_template_sources
  198. } else if (current_cpu == "arm") {
  199. sources += arm_template_sources
  200. } else if (current_cpu == "arm64") {
  201. sources += arm_template_sources
  202. } else if (current_cpu == "ppc64") {
  203. sources += ppc64_template_sources
  204. }
  205. cflags = dav1d_copts
  206. cflags += [ "-DBITDEPTH=16" ]
  207. deps = [ ":dav1d_headers" ]
  208. }
  209. if (current_cpu == "x86" || current_cpu == "x64") {
  210. static_library("dav1d_x86") {
  211. sources = [
  212. "libdav1d/src/x86/cpu.c",
  213. "libdav1d/src/x86/cpu.h",
  214. "libdav1d/src/x86/refmvs_init.c",
  215. ]
  216. # x86/msac.h redefines macros in msac.h if x86/msac.h is included and
  217. # HAVE_ASM is 0, so we must exclude msac_init.c if !enable_nasm. Also, it
  218. # is only used for x64.
  219. if (enable_nasm && current_cpu == "x64") {
  220. sources += [ "libdav1d/src/x86/msac_init.c" ]
  221. }
  222. configs -= [ "//build/config/compiler:chromium_code" ]
  223. configs += [
  224. "//build/config/compiler:no_chromium_code",
  225. ":dav1d_config",
  226. ]
  227. cflags = dav1d_copts
  228. deps = [ ":dav1d_headers" ]
  229. allow_circular_includes_from = [ ":dav1d_headers" ]
  230. }
  231. } else if (current_cpu == "arm" || current_cpu == "arm64") {
  232. static_library("dav1d_arm") {
  233. sources = [
  234. "libdav1d/src/arm/cpu.c",
  235. "libdav1d/src/arm/cpu.h",
  236. "libdav1d/src/arm/refmvs_init.c",
  237. ]
  238. # These are not template based so should only be built once.
  239. if (current_cpu == "arm") {
  240. sources += arm32_asm_sources
  241. } else if (current_cpu == "arm64") {
  242. sources += arm64_asm_sources
  243. }
  244. configs -= [ "//build/config/compiler:chromium_code" ]
  245. configs += [
  246. "//build/config/compiler:no_chromium_code",
  247. ":dav1d_config",
  248. ]
  249. # Necessary to ensure macOS symbols end up with a _ prefix.
  250. if (is_mac || is_ios) {
  251. defines = [ "PREFIX" ]
  252. }
  253. cflags = dav1d_copts
  254. deps = [ ":dav1d_headers" ]
  255. allow_circular_includes_from = [ ":dav1d_headers" ]
  256. }
  257. } else if (current_cpu == "ppc64") {
  258. static_library("dav1d_ppc64") {
  259. sources = [
  260. "libdav1d/src/ppc/cpu.c",
  261. "libdav1d/src/ppc/cpu.h",
  262. ]
  263. configs -= [ "//build/config/compiler:chromium_code" ]
  264. configs += [
  265. "//build/config/compiler:no_chromium_code",
  266. ":dav1d_config",
  267. ]
  268. cflags = dav1d_copts
  269. deps = [ ":dav1d_headers" ]
  270. allow_circular_includes_from = [ ":dav1d_headers" ]
  271. }
  272. }
  273. static_library("dav1d") {
  274. sources = c_sources
  275. configs -= [ "//build/config/compiler:chromium_code" ]
  276. configs += [
  277. "//build/config/compiler:no_chromium_code",
  278. ":dav1d_config",
  279. ]
  280. cflags = dav1d_copts
  281. deps = [
  282. ":dav1d_10bit",
  283. ":dav1d_8bit",
  284. ":dav1d_entrypoints",
  285. ":dav1d_headers",
  286. ]
  287. public_configs = [ ":public_dav1d_config" ]
  288. if (current_cpu == "x86" || current_cpu == "x64") {
  289. deps += [ ":dav1d_x86" ]
  290. if (enable_nasm) {
  291. deps += [ ":dav1d_asm" ]
  292. }
  293. } else if (current_cpu == "arm" || current_cpu == "arm64") {
  294. deps += [ ":dav1d_arm" ]
  295. } else if (current_cpu == "ppc64") {
  296. deps += [ ":dav1d_ppc64" ]
  297. }
  298. }