xref: /aosp_15_r20/external/angle/gni/angle.gni (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1# Copyright 2019 The ANGLE Project 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
5import("//build_overrides/angle.gni")
6
7declare_args() {
8  is_ggp = false
9
10  # Extract native libs in ANGLE apk. Useful for flamegraph generation.
11  angle_extract_native_libs = false
12
13  # Display mode for ANGLE vulkan display, could be 'simple' or 'headless', default is 'simple'.
14  angle_vulkan_display_mode = "simple"
15
16  # Defaults to capture building to $root_out_dir/angle_libs/with_capture.
17  # Switch on to build capture to $root_out_dir.
18  angle_with_capture_by_default = false
19
20  # Enables OpenCL support, off by default.
21  angle_enable_cl = false
22
23  angle_restricted_traces = []
24
25  # Don't build dEQP by default.
26  build_angle_deqp_tests = false
27
28  build_angle_end2end_tests_aosp = false
29}
30
31declare_args() {
32  # Only bundle traces in the APK if we're building a subset
33  restricted_traces_outside_of_apk = is_android && angle_restricted_traces == []
34
35  # Enables OpenCL testing support
36  angle_enable_cl_testing = angle_enable_cl && (is_linux || is_android)
37}
38
39if (angle_has_build) {
40  import("//build/config/dcheck_always_on.gni")
41  import("//build/config/ozone.gni")  # import the ozone_platform_x11 variable
42  import("//build/config/sanitizers/sanitizers.gni")
43  import("//build_overrides/build.gni")
44  import("//testing/test.gni")
45  if (is_android) {
46    import("//build/config/android/config.gni")
47  }
48
49  if (is_win) {
50    import("//build/config/win/visual_studio_version.gni")
51  }
52
53  if (is_chromeos) {
54    angle_vulkan_display_mode = "offscreen"
55  } else if (is_castos || ozone_platform_headless) {
56    angle_vulkan_display_mode = "headless"
57  }
58
59  declare_args() {
60    angle_use_gbm = ozone_platform_gbm
61    angle_use_x11 = ozone_platform_x11 && !is_ggp && (is_linux || is_chromeos)
62    angle_use_wayland =
63        ozone_platform_wayland && !is_ggp && is_linux && !is_castos
64    angle_use_vulkan_display = (is_linux || is_chromeos) && !is_ggp
65  }
66} else {
67  declare_args() {
68    is_ubsan = false
69    is_tsan = false
70    is_asan = false
71    is_lsan = false
72    build_with_chromium = false
73    dcheck_always_on = false
74    angle_use_x11 = (is_linux || is_chromeos) && !is_ggp
75    angle_use_wayland = is_linux && !is_ggp
76    use_ozone = false
77    ozone_platform_gbm = false
78    ozone_platform_wayland = false
79    ozone_platform_headless = false
80    use_fuzzing_engine = false
81    is_apple = is_mac || is_ios
82  }
83
84  declare_args() {
85    angle_use_vulkan_display = (is_linux || is_chromeos) && !is_ggp
86  }
87}
88
89if (!defined(checkout_angle_internal)) {
90  checkout_angle_internal = false
91}
92
93if (!defined(checkout_angle_restricted_traces)) {
94  checkout_angle_restricted_traces = false
95}
96
97# Subdirectory to place data files (e.g. layer JSON files).
98angle_data_dir = "angledata"
99
100declare_args() {
101  angle_assert_always_on = dcheck_always_on
102
103  if (current_cpu == "arm64" || current_cpu == "x64" ||
104      current_cpu == "mips64el" || current_cpu == "s390x" ||
105      current_cpu == "ppc64" || current_cpu == "loong64" ||
106      current_cpu == "riscv64") {
107    angle_64bit_current_cpu = true
108  } else if (current_cpu == "arm" || current_cpu == "x86" ||
109             current_cpu == "mipsel" || current_cpu == "s390" ||
110             current_cpu == "ppc" || current_cpu == "loong32") {
111    angle_64bit_current_cpu = false
112  } else {
113    assert(false, "Unknown current CPU: $current_cpu")
114  }
115
116  # Indicate if the rapidJSON library is available to build with in third_party/.
117  angle_has_rapidjson = angle_has_build
118
119  angle_is_winappsdk = false
120
121  # Windows App SDK is a separate dependency from nuget.org that needs to
122  # be pre-processed before being used.
123  winappsdk_dir = ""
124}
125
126declare_args() {
127  # By default we enable debug layers when asserts are turned on.
128  angle_debug_layers_enabled = is_debug || angle_assert_always_on
129
130  if (!is_android) {
131    ndk_api_level_at_least_26 = false
132  } else {
133    ndk_api_level_at_least_26 =
134        (!angle_64bit_current_cpu && android32_ndk_api_level >= 26) ||
135        (angle_64bit_current_cpu && android64_ndk_api_level >= 26)
136  }
137
138  # Vulkan loader is statically linked on Mac. http://anglebug.com/40096682
139  angle_shared_libvulkan = !is_mac
140
141  # There's no "is_winuwp" helper in BUILDCONFIG.gn, so we define one ourselves
142  # Windows App SDK is almost UWP but for Win32, so we want all the same things
143  angle_is_winuwp = (is_win && target_os == "winuwp") || angle_is_winappsdk
144
145  angle_is_msvc = is_win && !is_clang
146
147  # Default to using "_angle" suffix on Android
148  if (is_android) {
149    angle_libs_suffix = "_angle"
150  } else {
151    angle_libs_suffix = ""
152  }
153
154  # Currently Windows on Arm doesn't support OpenGL or Vulkan.
155  is_win_arm64 = is_win && target_cpu == "arm64"
156
157  # Frame capture code is enabled by default if rapidjson is available.
158  angle_has_frame_capture = angle_has_rapidjson
159}
160
161declare_args() {
162  # By default, ANGLE is using a thread pool for parallel compilation.
163  # Activating the delegate worker results in posting the tasks using the
164  # embedder API. In Chromium code base, it results in sending tasks to the
165  # worker thread pool.
166  angle_delegate_workers = build_with_chromium
167
168  # True if we are building inside an ANGLE checkout.
169  angle_standalone = !build_with_chromium
170
171  angle_enable_d3d9 = is_win && !angle_is_winuwp
172  angle_enable_d3d11 = is_win
173  angle_enable_gl =
174      (ozone_platform_gbm || ozone_platform_wayland || !is_linux ||
175       ((angle_use_x11 && !is_chromeos) || angle_use_wayland || is_castos)) &&
176      !is_fuchsia && !angle_is_winuwp && !is_ggp && !is_win_arm64 && !is_ios
177
178  angle_enable_vulkan =
179      angle_has_build &&
180      ((is_win && !angle_is_winuwp) ||
181       ((is_linux || is_chromeos) &&
182        (angle_use_x11 || angle_use_wayland || angle_use_vulkan_display)) ||
183       is_android || is_fuchsia || is_ggp || is_mac)
184
185  # When set to true, ANGLE will not use VK_KHR_surface and VK_KHR_swapchain
186  # extensions. Content can be rendered only off-screen.
187  angle_use_vulkan_null_display = build_with_chromium && is_fuchsia
188
189  # Disable null backend to save space for official build.
190  angle_enable_null = !is_official_build
191  angle_enable_gl_desktop_backend = !is_android && !is_ios
192
193  # http://anglebug.com/40096506
194  angle_enable_metal = is_apple
195
196  # Enables the OpenCL pass-through back end
197  angle_enable_cl_passthrough = angle_enable_cl
198
199  # Disable WGPU backend.
200  # Currently disabled on Android, Fuschia, WinUWP, and Win MSVC. X11 required on Linux.
201  # anglebug.com/42266968
202  angle_enable_wgpu =
203      !is_official_build && !(is_android || is_fuchsia || angle_is_winuwp) &&
204      (!is_win || is_clang) && (!is_linux || angle_use_x11) &&
205      defined(angle_dawn_dir)
206}
207
208declare_args() {
209  # ASTC emulation is only built on standalone non-android builds
210  angle_has_astc_encoder = angle_has_build && angle_standalone && !is_android
211}
212
213declare_args() {
214  angle_test_enable_system_egl = false
215}
216
217# OpenCL is not supported on Windows UWP, because the CL headers include DX9, which is not
218# supported by UWP. A workaround might be possible if CL support on UWP is required.
219assert(!angle_is_winuwp || !angle_enable_cl,
220       "OpenCL is not supported on Windows UWP")
221
222assert(!angle_is_winappsdk || winappsdk_dir != "",
223       "No path to Windows App SDK was provided using 'winappsdk_dir'")
224
225if (!angle_enable_cl) {
226  angle_enable_cl_passthrough = false
227}
228
229if (!defined(checkout_angle_mesa)) {
230  checkout_angle_mesa = false
231}
232
233declare_args() {
234  # Currently SwiftShader's Vulkan front-end doesn't build on Android.
235  # Disabled by default on MSVC because of compiler warnings/errors.
236  angle_enable_swiftshader =
237      angle_enable_vulkan && !is_android && !is_ggp && is_clang
238
239  # Translator backend support:
240  angle_enable_hlsl = angle_enable_d3d9 || angle_enable_d3d11
241  angle_enable_essl = angle_enable_gl || use_ozone
242  angle_enable_glsl = angle_enable_gl || use_ozone
243  angle_enable_trace = false
244  angle_enable_trace_android_logcat = false
245  angle_enable_trace_events = false
246  angle_dump_pipeline_cache_graph = false
247
248  angle_always_log_info = false
249
250  # Unwind backtrace support. This feature is currently only implemented
251  # on Android for debugging purposes. Disabled by default.
252  angle_enable_unwind_backtrace_support = false
253
254  # Memory allocation logging support. This feature is for debugging only.
255  # Disabled by default.
256  angle_enable_memory_alloc_logging = false
257
258  # Disable the layers in ubsan builds because of really slow builds.
259  # Vulkan Validation Layers require Android NDK API level 26, i.e. Oreo, due to
260  # Vulkan Validation Layers compatibility issues, see http://crrev/c/1405714.
261  # This is disabled in the Chromium build because the current build toolchain
262  # for APKs and bundles expect a single .so file in trichrome builds. See
263  # https://bugs.chromium.org/p/angleproject/issues/detail?id=8398 for details.
264  angle_enable_vulkan_validation_layers =
265      angle_enable_vulkan && !is_ubsan && !is_tsan && !is_asan &&
266      angle_debug_layers_enabled &&
267      (!is_android || (ndk_api_level_at_least_26 && !build_with_chromium))
268  angle_enable_vulkan_api_dump_layer =
269      angle_enable_vulkan && angle_debug_layers_enabled && angle_standalone &&
270      !is_apple && (is_linux || is_android)
271
272  # ISpriteVisual windows cannot be validated and can lead to crashes if an invalid window is
273  # provided to ANGLE. Disable them for non-standalone ANGLE builds. crbug.com/1176118
274  angle_enable_d3d11_compositor_native_window =
275      angle_enable_d3d11 && angle_standalone
276
277  # Disable performance counter output by default
278  angle_enable_perf_counter_output = false
279
280  # Directory where to find wayland source files
281  angle_wayland_dir = "$angle_root/third_party/wayland"
282
283  angle_vulkan_headers_dir = "$angle_root/third_party/vulkan-headers/src"
284  angle_vulkan_loader_dir = "$angle_root/third_party/vulkan-loader/src"
285  angle_vulkan_tools_dir = "$angle_root/third_party/vulkan-tools/src"
286  angle_vulkan_validation_layers_dir =
287      "$angle_root/third_party/vulkan-validation-layers/src"
288  angle_lunarg_vulkantools_dir =
289      "$angle_root/third_party/lunarg-vulkantools/src"
290
291  angle_build_vulkan_system_info = angle_has_build && !angle_is_winuwp
292
293  # Enable overlay by default when debug layers are enabled.  This is currently only implemented on
294  # Vulkan.
295  angle_enable_overlay = angle_enable_vulkan && angle_debug_layers_enabled
296
297  angle_build_mesa = false
298}
299
300declare_args() {
301  angle_enable_cgl = angle_enable_gl && is_mac
302
303  angle_enable_apple_translator_workarounds =
304      is_apple && (angle_enable_glsl || use_fuzzing_engine)
305
306  angle_has_histograms = angle_has_build
307
308  # True if we want to build the ANGLE test suites. On by default in most configs.
309  angle_build_tests = angle_has_build
310}
311
312declare_args() {
313  angle_enable_renderdoc = angle_enable_vulkan_validation_layers
314}
315
316if (!defined(angle_zlib_compression_utils_dir)) {
317  angle_zlib_compression_utils_dir = "//third_party/zlib/google"
318}
319
320angle_common_configs = [
321  angle_root + ":angle_asserts_config",
322  angle_root + ":constructor_and_destructor_warnings",
323  angle_root + ":extra_warnings",
324  angle_root + ":internal_config",
325  angle_root + ":angle_uwp_env",
326]
327
328angle_remove_configs = []
329
330if (angle_has_build) {
331  angle_remove_configs += [ "//build/config/compiler:default_include_dirs" ]
332
333  if (is_clang && !is_nacl) {
334    angle_remove_configs += [ "//build/config/clang:find_bad_constructs" ]
335  }
336
337  if (!is_debug && !is_fuchsia) {
338    # default->optimize_max (e.g. Android defaults to -Oz, optimize_max is -O2)
339    angle_remove_configs += [ "//build/config/compiler:default_optimization" ]
340    angle_common_configs += [ "//build/config/compiler:optimize_max" ]
341  }
342}
343
344set_defaults("angle_executable") {
345  configs = angle_common_configs
346  public_configs = []
347  suppressed_configs = angle_remove_configs
348  data_deps = []
349}
350
351set_defaults("angle_shared_library") {
352  configs = angle_common_configs
353  public_configs = []
354  suppressed_configs = angle_remove_configs
355}
356
357set_defaults("angle_source_set") {
358  configs = angle_common_configs
359  public_configs = []
360  suppressed_configs = angle_remove_configs
361}
362
363set_defaults("angle_static_library") {
364  configs = angle_common_configs
365  public_configs = []
366  suppressed_configs = angle_remove_configs
367}
368
369set_defaults("angle_test") {
370  # Gtest itself can't pass all the strict warning filters.
371  configs = angle_common_configs - [
372              "$angle_root:constructor_and_destructor_warnings",
373              "$angle_root:extra_warnings",
374            ] + [ "$angle_root/src/tests:angle_maybe_has_histograms" ] +
375            [ "$angle_root/src/tests:angle_enable_renderdoc" ]
376
377  public_configs = []
378  public_deps = []
379  sources = []
380  data = []
381  defines = []
382  deps = []
383  data_deps = []
384  suppressed_configs = angle_remove_configs
385}
386
387template("angle_executable") {
388  executable(target_name) {
389    forward_variables_from(invoker,
390                           "*",
391                           [
392                             "configs",
393                             "suppressed_configs",
394                             "visibility",
395                           ])
396
397    # Needed because visibility is global.
398    forward_variables_from(invoker, [ "visibility" ])
399
400    configs += invoker.configs
401    configs -= invoker.suppressed_configs
402
403    if (angle_has_build && is_win) {
404      data_deps += [ "//build/win:runtime_libs" ]
405    }
406
407    if (is_ios) {
408      check_includes = false
409    }
410  }
411}
412
413template("angle_shared_library") {
414  # On ios, define an ios_framework_bundle instead of a shared library.
415  # ios_framework_bundle doesn't automatically link, so we have to create
416  # a group that links and bundles the framework as well.
417  target_type = "shared_library"
418  internal_target_name = target_name
419  if (is_ios) {
420    target_type = "ios_framework_bundle"
421    internal_target_name = target_name + "_framework"
422  }
423  target(target_type, internal_target_name) {
424    forward_variables_from(invoker,
425                           "*",
426                           [
427                             "configs",
428                             "suppressed_configs",
429                             "visibility",
430                           ])
431
432    # Needed because visibility is global.
433    forward_variables_from(invoker, [ "visibility" ])
434
435    configs += invoker.configs
436    configs -= invoker.suppressed_configs
437
438    if (is_apple) {
439      # If a "build with ARC" config is present, remove it.
440      if (filter_include(configs, [ "//build/config/compiler:enable_arc" ]) !=
441          []) {
442        configs -= [ "//build/config/compiler:enable_arc" ]
443      }
444    }
445
446    public_configs += [ angle_root + ":shared_library_public_config" ]
447
448    if (is_android) {
449      configs += [ angle_root + ":build_id_config" ]
450      configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
451    }
452    if (is_ios) {
453      info_plist = "$angle_root/util/ios/Info.plist"
454
455      # shared libraries are hidden inside ios_framework_bundle, but we include headers from them
456      # Specifically, libGLESv1_CM includes headers from libGLESv2
457      check_includes = false
458    }
459  }
460  if (is_ios) {
461    group(target_name) {
462      forward_variables_from(invoker,
463                             [
464                               "testonly",
465                               "visibility",
466                             ])
467      public_deps = [
468        ":${internal_target_name}+bundle",
469        ":${internal_target_name}+link",
470      ]
471    }
472  }
473}
474
475template("angle_source_set") {
476  source_set(target_name) {
477    forward_variables_from(invoker,
478                           "*",
479                           [
480                             "configs",
481                             "suppressed_configs",
482                             "visibility",
483                           ])
484
485    # Needed because visibility is global.
486    forward_variables_from(invoker, [ "visibility" ])
487
488    configs += invoker.configs
489    configs -= invoker.suppressed_configs
490
491    if (is_apple) {
492      # If a "build with ARC" config is present, remove it.
493      if (filter_include(configs, [ "//build/config/compiler:enable_arc" ]) !=
494          []) {
495        configs -= [ "//build/config/compiler:enable_arc" ]
496      }
497    }
498  }
499}
500
501template("angle_static_library") {
502  static_library(target_name) {
503    forward_variables_from(invoker,
504                           "*",
505                           [
506                             "configs",
507                             "suppressed_configs",
508                             "visibility",
509                           ])
510
511    # Needed because visibility is global.
512    forward_variables_from(invoker, [ "visibility" ])
513
514    configs += invoker.configs
515    configs -= invoker.suppressed_configs
516
517    if (is_apple) {
518      # If a "build with ARC" config is present, remove it.
519      if (filter_include(configs, [ "//build/config/compiler:enable_arc" ]) !=
520          []) {
521        configs -= [ "//build/config/compiler:enable_arc" ]
522      }
523    }
524  }
525}
526
527if (angle_standalone || build_with_chromium || build_angle_end2end_tests_aosp) {
528  template("angle_test") {
529    test(target_name) {
530      forward_variables_from(invoker,
531                             "*",
532                             [
533                               "configs",
534                               "data",
535                               "public_deps",
536                             ])
537
538      configs += invoker.configs
539      configs -= invoker.suppressed_configs
540
541      if (is_apple) {
542        # If a "build with ARC" config is present, remove it.
543        if (filter_include(configs, [ "//build/config/compiler:enable_arc" ]) !=
544            []) {
545          configs -= [ "//build/config/compiler:enable_arc" ]
546        }
547      }
548
549      if (is_ios) {
550        # shared libraries are hidden inside ios_framework_bundle, but we include headers from them
551        check_includes = false
552      }
553
554      public_deps = invoker.public_deps + [
555                      "$angle_root:angle_common",
556                      "$angle_root:includes",
557                      "$angle_root/src/tests:angle_test_expectations",
558                      "$angle_root/util:angle_test_utils",
559                      "//testing/gmock",
560                      "//testing/gtest",
561                      "//third_party/googletest:gmock",
562                      "//third_party/googletest:gtest",
563                    ]
564      if (angle_has_rapidjson) {
565        public_deps += [ "$angle_root/third_party/rapidjson:rapidjson" ]
566      }
567
568      data = invoker.data + [
569               "$angle_root/src/tests/py_utils/android_helper.py",
570               "$angle_root/src/tests/py_utils/angle_path_util.py",
571               "$angle_root/src/tests/py_utils/angle_test_util.py",
572               "//testing/scripts/common.py",
573               "//testing/xvfb.py",
574             ]
575
576      if (angle_has_rapidjson) {
577        sources += [
578          "$angle_root/src/tests/test_utils/runner/HistogramWriter.h",
579          "$angle_root/src/tests/test_utils/runner/TestSuite.cpp",
580          "$angle_root/src/tests/test_utils/runner/TestSuite.h",
581        ]
582      }
583
584      if (angle_has_histograms) {
585        sources +=
586            [ "$angle_root/src/tests/test_utils/runner/HistogramWriter.cpp" ]
587        deps += [
588          "//third_party/catapult/tracing/tracing:histogram",
589          "//third_party/catapult/tracing/tracing:reserved_infos",
590        ]
591      }
592
593      if (is_mac) {
594        if (angle_enable_metal) {
595          # On macOS, compiling Metal shader sometimes takes very long time due to internal caching
596          # mechanism. This hooking library is a way to bypass this caching mechanism.
597          data_deps += [ "$angle_root/src/libANGLE/renderer/metal/file_hooking:metal_shader_cache_file_hooking" ]
598        }
599        if (angle_enable_cgl) {
600          configs += [ "$angle_root:supports_automatic_graphics_switching" ]
601        }
602      }
603
604      if ((is_linux && !is_chromeos) ||
605          (build_with_chromium && is_chromeos_lacros && !is_chromeos_device)) {
606        use_xvfb = true
607      }
608
609      if ((is_linux || is_chromeos) && !is_component_build) {
610        # Set rpath to find shared libs in a non-component build.
611        configs += [ "//build/config/gcc:rpath_for_built_shared_libraries" ]
612      }
613
614      if (is_android) {
615        public_configs += [ "$angle_root:build_id_config" ]
616        configs -= [ "//build/config/android:hide_all_but_jni" ]
617        use_default_launcher = false
618        generate_final_jni = false
619        android_manifest_template = "$angle_root/src/tests/test_utils/runner/android/java/AndroidManifest.xml.jinja2"
620
621        deps += [
622          "$angle_root/src/tests:native_test_java",
623          "$angle_root/src/tests:native_test_support_android",
624        ]
625      }
626      if (is_ios) {
627        # We use a special main function on iOS to initialize UIKit before the normal main runs.
628        ldflags = [
629          "-e",
630          "_ios_main",
631        ]
632        sources += [ "$angle_root/util/ios/ios_main.mm" ]
633      }
634
635      if (angle_has_build && is_win) {
636        data_deps += [ "//build/win:runtime_libs" ]
637      }
638    }
639  }
640}
641
642if (angle_enable_cl) {
643  # need the llvm build flags
644  import("$angle_clspv_dir/gn/build/llvm_buildflags.gni")
645}
646