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