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