1# Copyright (c) 2013 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 5# ============================================================================= 6# WHAT IS THIS FILE? 7# ============================================================================= 8# 9# This is the master GN build configuration. This file is loaded after the 10# build args (args.gn) for the build directory and after the toplevel ".gn" 11# file (which points to this file as the build configuration). 12# 13# This file will be executed and the resulting context will be used to execute 14# every other file in the build. So variables declared here (that don't start 15# with an underscore) will be implicitly global. 16 17# ============================================================================= 18# PLATFORM SELECTION 19# ============================================================================= 20# 21# There are two main things to set: "os" and "cpu". The "toolchain" is the name 22# of the GN thing that encodes combinations of these things. 23# 24# Users typically only set the variables "target_os" and "target_cpu" in "gn 25# args", the rest are set up by our build and internal to GN. 26# 27# There are three different types of each of these things: The "host" 28# represents the computer doing the compile and never changes. The "target" 29# represents the main thing we're trying to build. The "current" represents 30# which configuration is currently being defined, which can be either the 31# host, the target, or something completely different (like nacl). GN will 32# run the same build file multiple times for the different required 33# configuration in the same build. 34# 35# This gives the following variables: 36# - host_os, host_cpu, host_toolchain 37# - target_os, target_cpu, default_toolchain 38# - current_os, current_cpu, current_toolchain. 39# 40# Note the default_toolchain isn't symmetrical (you would expect 41# target_toolchain). This is because the "default" toolchain is a GN built-in 42# concept, and "target" is something our build sets up that's symmetrical with 43# its GYP counterpart. Potentially the built-in default_toolchain variable 44# could be renamed in the future. 45# 46# When writing build files, to do something only for the host: 47# if (current_toolchain == host_toolchain) { ... 48 49check_mac_system_and_cpu_script = 50 rebase_path("//build/scripts/check_mac_system_and_cpu.py") 51check_darwin_system_result = 52 exec_script(check_mac_system_and_cpu_script, [ "system" ], "string") 53 54if (check_darwin_system_result != "") { 55 check_mac_host_cpu_result = 56 exec_script(check_mac_system_and_cpu_script, [ "cpu" ], "string") 57 if (check_mac_host_cpu_result != "") { 58 host_cpu = "arm64" 59 } 60} 61 62declare_args() { 63 product_name = "" 64 device_name = "" 65} 66 67declare_args() { 68 using_hb_new = true 69} 70 71declare_args() { 72 preloader_output_dir = "//out/preloader/${product_name}" 73} 74 75declare_args() { 76 enable_lto_O0 = false 77} 78 79declare_args() { 80 enable_gn_2021 = true 81} 82 83declare_args() { 84 is_llvm_build = false 85} 86 87declare_args() { 88 rustc_codecheck = false 89} 90 91product_build_config = 92 read_file("${preloader_output_dir}/build_config.json", "json") 93 94global_parts_info = 95 read_file("${preloader_output_dir}/parts_config.json", "json") 96 97if (!is_llvm_build) { 98 napi_white_list = read_file( 99 "//developtools/integration_verification/tools/deps_guard/rules/NO-Depends-On-NAPI/whitelist.json", 100 "json") 101} 102 103product_company = product_build_config.product_company 104device_company = product_build_config.device_company 105device_build_path = product_build_config.device_build_path 106target_os = product_build_config.target_os 107target_cpu = product_build_config.target_cpu 108product_toolchain = product_build_config.product_toolchain_label 109if (product_toolchain == "") { 110 product_toolchain = "//build/toolchain/ohos:ohos_clang_$target_cpu" 111} 112if (defined(product_build_config.ext_root_proc_conf_path)) { 113 ext_root_proc_conf_path = product_build_config.ext_root_proc_conf_path 114} else { 115 ext_root_proc_conf_path = "" 116} 117if (defined(product_build_config.ext_critical_proc_conf_path)) { 118 ext_critical_proc_conf_path = product_build_config.ext_critical_proc_conf_path 119} else { 120 ext_critical_proc_conf_path = "" 121} 122if (defined(product_build_config.ext_sanitizer_check_list_path)) { 123 ext_sanitizer_check_list_path = 124 product_build_config.ext_sanitizer_check_list_path 125} else { 126 joint_check_list_path = "//vendor/${product_company}/${product_name}/security_config/sanitizer_check_list.gni" 127 sanitize_list_exist = 128 exec_script(rebase_path("//build/scripts/check_file_exist.py"), 129 [ rebase_path("${joint_check_list_path}") ], 130 "string") 131 if (sanitize_list_exist != "") { 132 ext_sanitizer_check_list_path = joint_check_list_path 133 } 134} 135if (defined(product_build_config.enable_ramdisk)) { 136 enable_ramdisk = product_build_config.enable_ramdisk 137} else { 138 enable_ramdisk = false 139} 140if (defined(product_build_config.chipprod_config_path)) { 141 chipprod_config_path = product_build_config.chipprod_config_path 142 import("${chipprod_config_path}/chip_product_list.gni") 143} else { 144 chip_product_list = [] 145} 146 147if (defined(product_build_config.ext_sdk_config_file)) { 148 ext_sdk_config_file = product_build_config.ext_sdk_config_file 149} 150 151if (defined(product_build_config.ext_ndk_config_file)) { 152 ext_ndk_config_file = product_build_config.ext_ndk_config_file 153} 154 155if (defined(product_build_config.enable_absystem)) { 156 enable_absystem = product_build_config.enable_absystem 157} else { 158 enable_absystem = false 159} 160 161if (defined(product_build_config.enable_mesa3d)) { 162 enable_mesa3d = product_build_config.enable_mesa3d 163} else { 164 enable_mesa3d = false 165} 166 167if (defined(product_build_config.build_selinux)) { 168 build_selinux = product_build_config.build_selinux 169} else { 170 build_selinux = false 171} 172 173if (defined(product_build_config.build_seccomp)) { 174 build_seccomp = product_build_config.build_seccomp 175} else { 176 build_seccomp = false 177} 178 179if (defined(product_build_config.support_jsapi)) { 180 support_jsapi = product_build_config.support_jsapi 181} else { 182 if (defined(global_parts_info) && !defined(global_parts_info.arkui_napi)) { 183 support_jsapi = false 184 } else { 185 support_jsapi = true 186 } 187} 188if (defined(product_build_config.ext_sign_hap_py_path)) { 189 sign_hap_py_path = product_build_config.ext_sign_hap_py_path 190} 191if (target_os == "") { 192 target_os = "ohos" 193} 194 195if (target_cpu == "") { 196 if (target_os == "ohos" || target_os == "android" || target_os == "ios") { 197 target_cpu = "arm" 198 } else { 199 target_cpu = host_cpu 200 } 201} 202 203if (current_cpu == "") { 204 current_cpu = target_cpu 205} 206if (current_os == "") { 207 current_os = target_os 208} 209 210declare_args() { 211 is_mini_system = false 212 is_small_system = false 213 is_standard_system = false 214} 215 216if (is_mini_system) { 217 os_level = "mini" 218} 219if (is_small_system) { 220 os_level = "small" 221} 222if (is_standard_system) { 223 os_level = "standard" 224} 225 226declare_args() { 227 is_large_system = !(is_standard_system || is_small_system || is_mini_system) 228} 229 230is_lite_system = is_mini_system || is_small_system 231 232# ============================================================================= 233# BUILD FLAGS 234# ============================================================================= 235# 236# This block lists input arguments to the build, along with their default 237# values. 238# 239# If a value is specified on the command line, it will overwrite the defaults 240# given in a declare_args block, otherwise the default will be used. 241# 242# YOU SHOULD ALMOST NEVER NEED TO ADD FLAGS TO THIS FILE. GN allows any file in 243# the build to declare build flags. If you need a flag for a single component, 244# you can just declare it in the corresponding BUILD.gn file. 245# 246# - If your feature is a single target, say //components/foo, you can put 247# a declare_args() block in //components/foo/BUILD.gn and use it there. 248# Nobody else in the build needs to see the flag. 249# 250# - Defines based on build variables should be implemented via the generated 251# build flag header system. See //build/buildflag_header.gni. You can put 252# the buildflag_header target in the same file as the build flag itself. You 253# should almost never set "defines" directly. 254# 255# - If your flag toggles a target on and off or toggles between different 256# versions of similar things, write a "group" target that forwards to the 257# right target (or no target) depending on the value of the build flag. This 258# group can be in the same BUILD.gn file as the build flag, and targets can 259# depend unconditionally on the group rather than duplicating flag checks 260# across many targets. 261# 262# - If a semi-random set of build files REALLY needs to know about a define and 263# the above pattern for isolating the build logic in a forwarding group 264# doesn't work, you can put the argument in a .gni file. This should be put 265# in the lowest level of the build that knows about this feature (which should 266# almost always be outside of the //build directory!). 267# 268# Other flag advice: 269# 270# - Use boolean values when possible. If you need a default value that expands 271# to some complex thing in the default case (like the location of the 272# compiler which would be computed by a script), use a default value of -1 or 273# the empty string. Outside of the declare_args block, conditionally expand 274# the default value as necessary. 275# 276# - Use a name like "use_foo" or "is_foo" (whatever is more appropriate for 277# your feature) rather than just "foo". 278# 279# - Write good comments directly above the declaration with no blank line. 280# These comments will appear as documentation in "gn args --list". 281# 282# - Don't call exec_script inside declare_args. This will execute the script 283# even if the value is overridden, which is wasteful. See first bullet. 284 285declare_args() { 286 # Set to enable the official build level of optimization. This has nothing 287 # to do with branding, but enables an additional level of optimization above 288 # release (!is_debug). This might be better expressed as a tri-state 289 # (debug, release, official) but for historical reasons there are two 290 # separate flags. 291 is_official_build = false 292 293 # Whether we're a traditional desktop unix. 294 is_desktop_linux = current_os == "linux" 295 296 # Set to true when compiling with the Clang compiler. 297 is_clang = current_os != "linux" || 298 (current_cpu != "s390x" && current_cpu != "s390" && 299 current_cpu != "ppc64" && current_cpu != "ppc" && 300 current_cpu != "mips" && current_cpu != "mips64") 301 302 # Allows the path to a custom target toolchain to be injected as a single 303 # argument, and set as the default toolchain. 304 custom_toolchain = "" 305 306 # This should not normally be set as a build argument. It's here so that 307 # every toolchain can pass through the "global" value via toolchain_args(). 308 host_toolchain = "" 309 310 # target platform 311 target_platform = "phone" 312 313 # Whether it is test. 314 is_test = false 315 316 # Whether it is double framework. 317 is_double_framework = false 318 319 # build for cross platform 320 is_arkui_x = false 321} 322 323declare_args() { 324 use_musl = true 325} 326 327declare_args() { 328 is_emulator = false 329} 330 331asdk_libs_dir = "//prebuilts/asdk_libs" 332 333# Whether it is a phone product. 334is_phone_product = "${target_platform}" == "phone" 335 336# Whether it is a ivi product. 337is_ivi_product = "${target_platform}" == "ivi" 338 339is_wearable_product = "${target_platform}" == "wearable" 340 341is_intellitv_product = "${target_platform}" == "intellitv" 342 343if ((target_os == "ohos" && target_cpu == "x86_64") || 344 device_company == "emulator") { 345 is_emulator = true 346} 347 348# different host platform tools directory. 349if (host_os == "linux") { 350 host_platform_dir = "linux-x86_64" 351} else if (host_os == "mac") { 352 if (host_cpu == "arm64") { 353 host_platform_dir = "darwin-arm64" 354 } else { 355 host_platform_dir = "darwin-x86_64" 356 } 357} else { 358 assert(false, "Unsupported host_os: $host_os") 359} 360 361declare_args() { 362 # Debug build. Enabling official builds automatically sets is_debug to false. 363 is_debug = false 364} 365 366declare_args() { 367 # Profile build. Enabling official builds automatically sets is_profile to false. 368 is_profile = false 369} 370 371declare_args() { 372 # The runtime mode ("debug", "profile", "release") 373 runtime_mode = "release" 374} 375 376declare_args() { 377 # Enable mini debug info, it will add .gnu_debugdata 378 # section in each stripped sofile 379 380 # Currently, we don't publish ohos-adapted python on m1 platform, 381 # So that we disable mini debug info on m1 platform until 382 # ohos-adapted python publishing on m1 platform 383 if (host_os == "mac") { 384 full_mini_debug = false 385 } else { 386 full_mini_debug = true 387 } 388} 389 390declare_args() { 391 # Full Debug mode. Setting optimize level to "-O0" and symbol level to "-g3". 392 # It should be used with "is_debug" 393 ohos_full_debug = false 394} 395 396declare_args() { 397 # Specifies which components use the DEBUG compilation level 398 # Using this arg like this, --gn-args 'enable_debug_components="component1,component2"' 399 enable_debug_components = "" 400} 401 402declare_args() { 403 # We use this arg to split "enable_debug_components" to a list 404 debug_components = string_split(enable_debug_components, ",") 405} 406 407declare_args() { 408 build_xts = false 409} 410 411declare_args() { 412 # Component build. Setting to true compiles targets declared as "components" 413 # as shared libraries loaded dynamically. This speeds up development time. 414 # When false, components will be linked statically. 415 # 416 # For more information see 417 # https://chromium.googlesource.com/chromium/src/+/master/docs/component_build.md 418 is_component_build = true 419} 420 421declare_args() { 422 enable_adlt = false 423 adlt_exe = "" 424 allowed_lib_list = "" 425 adlt_lib_name = "" 426} 427 428assert(!(is_debug && is_official_build), "Can't do official debug builds") 429 430# ============================================================================== 431# TOOLCHAIN SETUP 432# ============================================================================== 433# 434# Here we set the default toolchain, as well as the variable host_toolchain 435# which will identify the toolchain corresponding to the local system when 436# doing cross-compiles. When not cross-compiling, this will be the same as the 437# default toolchain. 438# 439# We do this before anything else to make sure we complain about any 440# unsupported os/cpu combinations as early as possible. 441 442if (host_toolchain == "") { 443 # This should only happen in the top-level context. 444 # In a specific toolchain context, the toolchain_args() 445 # block should have propagated a value down. 446 447 if (host_os == "linux") { 448 if (target_os != "linux") { 449 host_toolchain = "//build/toolchain/linux:clang_$host_cpu" 450 } else if (is_clang) { 451 host_toolchain = "//build/toolchain/linux:clang_$host_cpu" 452 } else { 453 host_toolchain = "//build/toolchain/linux:$host_cpu" 454 } 455 } else if (host_os == "mac") { 456 host_toolchain = "//build/toolchain/mac:clang_$host_cpu" 457 } else if (host_os == "win") { 458 if (target_cpu == "x86" || target_cpu == "x64") { 459 if (is_clang) { 460 host_toolchain = "//build/toolchain/win:win_clang_$target_cpu" 461 } else { 462 host_toolchain = "//build/toolchain/win:$target_cpu" 463 } 464 } else if (is_clang) { 465 host_toolchain = "//build/toolchain/win:win_clang_$host_cpu" 466 } else { 467 host_toolchain = "//build/toolchain/win:$host_cpu" 468 } 469 } else { 470 assert(false, "Unsupported host_os: $host_os") 471 } 472} 473 474if (is_standard_system) { 475 _default_toolchain = "" 476 477 if (target_os == "ohos") { 478 assert(host_os == "linux" || host_os == "mac", 479 "ohos builds are only supported on Linux and Mac hosts.") 480 _default_toolchain = product_toolchain 481 } else if (target_os == "linux") { 482 if (is_clang) { 483 _default_toolchain = "//build/toolchain/linux:clang_$target_cpu" 484 } else { 485 _default_toolchain = "//build/toolchain/linux:$target_cpu" 486 } 487 } else if (target_os == "android") { 488 assert(host_os == "linux" || host_os == "mac", 489 "AOSP builds are only supported on Linux and Mac hosts.") 490 _default_toolchain = "//build_plugins/toolchain/aosp:aosp_clang_$target_cpu" 491 } else if (target_os == "ios") { 492 _default_toolchain = "//build_plugins/toolchain/ios:ios_clang_$target_cpu" 493 import("//build_plugins/config/ios/ios_sdk.gni") # For use_ios_simulator 494 if (use_ios_simulator) { 495 if (target_cpu == "arm64") { 496 _default_toolchain = "//build_plugins/toolchain/ios:ios_clang_arm64_sim" 497 } else { 498 _default_toolchain = "//build_plugins/toolchain/ios:ios_clang_x64_sim" 499 } 500 } 501 } else { 502 assert(false, "Unsupported target_os: $target_os") 503 } 504 505 # If a custom toolchain has been set in the args, set it as default. Otherwise, 506 # set the default toolchain for the platform (if any). 507 if (custom_toolchain != "") { 508 set_default_toolchain(custom_toolchain) 509 } else if (_default_toolchain != "") { 510 set_default_toolchain(_default_toolchain) 511 } 512} 513 514# ============================================================================= 515# OS DEFINITIONS 516# ============================================================================= 517# 518# We set these various is_FOO booleans for convenience in writing OS-based 519# conditions. 520# 521# - is_ohos, is_chromeos, and is_win should be obvious. 522# - is_mac is set only for desktop Mac. 523# - is_posix is true for mac and any Unix-like system (basically everything 524# except Windows). 525# - is_linux is true for desktop Linux and ChromeOS. 526# 527# Do not add more is_* variants here for random lesser-used Unix systems like 528# aix or one of the BSDs. If you need to check these, just check the 529# current_os value directly. 530 531if (current_os == "win" || current_os == "winuwp") { 532 is_aix = false 533 is_ohos = false 534 is_chromeos = false 535 is_linux = false 536 is_mac = false 537 is_nacl = false 538 is_posix = false 539 is_win = true 540 is_mingw = false 541 is_android = false 542 is_ios = false 543} else if (current_os == "mac") { 544 is_aix = false 545 is_ohos = false 546 is_chromeos = false 547 is_linux = false 548 is_mac = true 549 is_nacl = false 550 is_posix = true 551 is_win = false 552 is_mingw = false 553 is_android = false 554 is_ios = false 555} else if (current_os == "ohos") { 556 is_aix = false 557 is_ohos = true 558 is_chromeos = false 559 is_linux = false 560 is_mac = false 561 is_nacl = false 562 is_posix = true 563 is_win = false 564 is_mingw = false 565 is_android = false 566 is_ios = false 567} else if (current_os == "linux") { 568 is_aix = false 569 is_ohos = false 570 is_chromeos = false 571 is_linux = true 572 is_mac = false 573 is_nacl = false 574 is_posix = true 575 is_win = false 576 is_mingw = false 577 is_android = false 578 is_ios = false 579} else if (current_os == "mingw") { 580 is_aix = false 581 is_ohos = false 582 is_chromeos = false 583 is_linux = false 584 is_mac = false 585 is_nacl = false 586 is_posix = true 587 is_win = false 588 is_mingw = true 589 is_android = false 590 is_ios = false 591} else if (current_os == "android") { 592 is_aix = false 593 is_ohos = false 594 is_chromeos = false 595 is_linux = false 596 is_mac = false 597 is_nacl = false 598 is_posix = true 599 is_win = false 600 is_mingw = false 601 is_android = true 602 is_ios = false 603} else if (current_os == "ios") { 604 is_aix = false 605 is_ohos = false 606 is_chromeos = false 607 is_linux = false 608 is_mac = false 609 is_nacl = false 610 is_posix = true 611 is_win = false 612 is_mingw = false 613 is_android = false 614 is_ios = true 615} 616 617# ============================================================================= 618# SOURCES FILTERS 619# ============================================================================= 620# 621# These patterns filter out platform-specific files when assigning to the 622# sources variable. The magic variable |sources_assignment_filter| is applied 623# to each assignment or appending to the sources variable and matches are 624# automatically removed. 625# 626# Note that the patterns are NOT regular expressions. Only "*" and "\b" (path 627# boundary = end of string or slash) are supported, and the entire string 628# must match the pattern (so you need "*.cc" to match all .cc files, for 629# example). 630 631# DO NOT ADD MORE PATTERNS TO THIS LIST, see set_sources_assignment_filter call 632# below. 633sources_assignment_filter = [] 634 635if (!is_win && !is_mingw) { 636 sources_assignment_filter += [ 637 "*_win.cc", 638 "*_win.h", 639 "*_win_unittest.cc", 640 "*\bwin/*", 641 "*.def", 642 ] 643} 644if (!is_mac || !is_ios) { 645 sources_assignment_filter += [ 646 "*_mac.h", 647 "*_mac.cc", 648 "*_mac.mm", 649 "*_mac_unittest.h", 650 "*_mac_unittest.cc", 651 "*_mac_unittest.mm", 652 "*\bmac/*", 653 "*_cocoa.h", 654 "*_cocoa.cc", 655 "*_cocoa.mm", 656 "*_cocoa_unittest.h", 657 "*_cocoa_unittest.cc", 658 "*_cocoa_unittest.mm", 659 "*\bcocoa/*", 660 ] 661} 662if (!is_linux && !is_ohos && !is_android && !is_ios) { 663 sources_assignment_filter += [ 664 "*_linux.h", 665 "*_linux.cc", 666 "*_linux_unittest.h", 667 "*_linux_unittest.cc", 668 "*\blinux/*", 669 ] 670} 671if (!is_ohos) { 672 sources_assignment_filter += [] 673} 674 675#set_sources_assignment_filter(sources_assignment_filter) 676if (is_standard_system) { 677 file_exist = exec_script(rebase_path("//build/scripts/check_file_exist.py"), 678 [ rebase_path("//${device_build_path}/config.gni") ], 679 "string") 680 if (file_exist != "") { 681 import("//${device_build_path}/config.gni") 682 } 683 684 # ============================================================================= 685 # TARGET DEFAULTS 686 # ============================================================================= 687 # 688 # Set up the default configuration for every build target of the given type. 689 # The values configured here will be automatically set on the scope of the 690 # corresponding target. Target definitions can add or remove to the settings 691 # here as needed. 692 # 693 # WHAT GOES HERE? 694 # 695 # Other than the main compiler and linker configs, the only reason for a config 696 # to be in this list is if some targets need to explicitly override that config 697 # by removing it. This is how targets opt-out of flags. If you don't have that 698 # requirement and just need to add a config everywhere, reference it as a 699 # sub-config of an existing one, most commonly the main "compiler" one. 700 701 # Holds all configs used for running the compiler. 702 default_compiler_configs = [ 703 "//build/config:feature_flags", 704 "//build/config/compiler:afdo", 705 "//build/config/compiler:afdo_optimize_size", 706 "//build/config/compiler:compiler", 707 "//build/config/compiler:compiler_arm_fpu", 708 "//build/config/compiler:compiler_arm_thumb", 709 "//build/config/compiler:chromium_code", 710 "//build/config/compiler:default_include_dirs", 711 "//build/config/compiler:default_optimization", 712 "//build/config/compiler:default_stack_frames", 713 "//build/config/compiler:default_symbols", 714 "//build/config/compiler:export_dynamic", 715 "//build/config/compiler:no_exceptions", 716 "//build/config/compiler:no_rtti", 717 "//build/config/compiler:runtime_library", 718 "//build/config/compiler:thin_archive", 719 "//build/config/compiler:no_common", 720 "//build/config/coverage:default_coverage", 721 "//build/config/sanitizers:default_sanitizer_flags", 722 "//build/config/security:default_security_configs", 723 "//build/config/rust:rust_config", 724 "//build/config:predefined_macro", 725 ] 726 727 if (is_ohos) { 728 default_compiler_configs += [ 729 "//build/config/ohos:default_orderfile_instrumentation", 730 "//build/config/gcc:symbol_visibility_inline_hidden", 731 ] 732 } 733 734 if (is_clang) { 735 default_compiler_configs += [ 736 "//build/config/clang:find_bad_constructs", 737 "//build/config/clang:extra_warnings", 738 ] 739 } 740 741 if (is_ohos && is_clang && target_cpu == "arm64") { 742 default_compiler_configs += 743 [ "//build/config/security:stack_protector_ret_strong_config" ] 744 } 745 746 # Debug/release-related defines. 747 if (is_debug) { 748 default_compiler_configs += [ "//build/config:debug" ] 749 } else { 750 default_compiler_configs += [ "//build/config:release" ] 751 } 752 753 if (is_android) { 754 default_compiler_configs += [ 755 "//build_plugins/config/aosp:default_orderfile_instrumentation", 756 "//build_plugins/config/aosp:lld_pack_relocations", 757 "//build/config/gcc:symbol_visibility_inline_hidden", 758 ] 759 } 760 761 # Static libraries and source sets use only the compiler ones. 762 default_static_library_configs = default_compiler_configs 763 default_source_set_configs = default_compiler_configs 764 765 # Executable defaults. 766 default_executable_configs = default_compiler_configs + [ 767 "//build/config:default_libs", 768 "//build/config:executable_config", 769 ] 770 if (is_android) { 771 default_executable_configs += [ "//build_plugins/config/aosp:default_libs" ] 772 } 773 774 # Shared library and loadable module defaults (also for components in component 775 # mode). 776 default_shared_library_configs = default_compiler_configs + [ 777 "//build/config:default_libs", 778 "//build/config:shared_library_config", 779 ] 780 if (is_android) { 781 default_shared_library_configs += 782 [ "//build_plugins/config/aosp:default_libs" ] 783 } 784} 785 786# Lite OS use different buildconfig.gn 787if (is_lite_system) { 788 import("//build/lite/ohos_var.gni") 789 import("${device_config_path}/config.gni") 790 target_arch_cflags = board_cflags 791 if (board_arch != "") { 792 target_arch_cflags += [ "-march=$board_arch" ] 793 } 794 if (board_cpu != "") { 795 target_arch_cflags += [ "-mcpu=$board_cpu" ] 796 } 797 798 arch = "arm" 799 if (ohos_kernel_type == "liteos_a") { 800 target_triple = "$arch-liteos-ohos" 801 } else if (ohos_kernel_type == "linux") { 802 target_triple = "$arch-linux-ohos" 803 } 804 805 if (defined(board_configed_sysroot) && board_configed_sysroot != "") { 806 ohos_current_sysroot = board_configed_sysroot 807 } 808 809 # Only gcc available for liteos_m. 810 if (ohos_kernel_type == "liteos_m" || ohos_kernel_type == "linux") { 811 use_board_toolchain = true 812 } 813 814 toolchain_cmd_suffix = "" 815 if (host_os == "win") { 816 toolchain_cmd_suffix = ".exe" 817 } 818 819 # enable ccache if ccache installed. 820 if (ohos_build_enable_ccache) { 821 compile_prefix = "ccache " 822 } else { 823 compile_prefix = "" 824 } 825 826 # Load board adapter dir from board config. 827 if (board_adapter_dir != "") { 828 ohos_board_adapter_dir = board_adapter_dir 829 ohos_vendor_adapter_dir = board_adapter_dir 830 } 831 832 # Set current toolchain with to board configuration. 833 if (board_toolchain != "" && use_board_toolchain) { 834 ohos_build_compiler = board_toolchain_type 835 if (board_toolchain_path != "") { 836 compile_prefix += "${board_toolchain_path}/${board_toolchain_prefix}" 837 } else { 838 compile_prefix += "${board_toolchain_prefix}" 839 } 840 set_default_toolchain("//build/lite/toolchain:${board_toolchain}") 841 if (board_toolchain_type == "gcc") { 842 default_compiler_configs = [] 843 ohos_current_cc_command = "${compile_prefix}gcc$toolchain_cmd_suffix" 844 ohos_current_cxx_command = "${compile_prefix}g++$toolchain_cmd_suffix" 845 ohos_current_ar_command = "${compile_prefix}ar$toolchain_cmd_suffix" 846 ohos_current_ld_command = ohos_current_cc_command 847 ohos_current_strip_command = 848 "${compile_prefix}strip$toolchain_cmd_suffix --strip-unneeded" 849 default_compiler_configs += [ "//build/lite/config:gcc_opt" ] 850 } else if (board_toolchain_type == "clang") { 851 default_compiler_configs = [] 852 ohos_current_cc_command = "${compile_prefix}clang$toolchain_cmd_suffix" 853 ohos_current_cxx_command = "${compile_prefix}clang++$toolchain_cmd_suffix" 854 compile_prefix += "llvm-" 855 ohos_current_ar_command = "${compile_prefix}ar$toolchain_cmd_suffix" 856 ohos_current_ld_command = ohos_current_cc_command 857 ohos_current_strip_command = 858 "${compile_prefix}strip$toolchain_cmd_suffix --strip-unneeded" 859 default_compiler_configs += [ "//build/lite/config:clang_opt" ] 860 } else if (board_toolchain_type == "iccarm") { 861 import("//build/config/compiler/lite/iccarm/iccarm.gni") 862 ohos_current_cc_command = "${compile_prefix}iccarm$toolchain_cmd_suffix" 863 ohos_current_cxx_command = "${compile_prefix}iccarm$toolchain_cmd_suffix" 864 ohos_current_ar_command = "${compile_prefix}iarchive$toolchain_cmd_suffix" 865 ohos_current_as_command = "${compile_prefix}iasmarm$toolchain_cmd_suffix" 866 ohos_current_ld_command = "${compile_prefix}ilinkarm$toolchain_cmd_suffix" 867 ohos_current_strip_command = 868 "${compile_prefix}ielftool$toolchain_cmd_suffix --strip" 869 } else { 870 default_compiler_configs = [] 871 } 872 873 # Overwrite ld cmd by customed cmd. 874 if (defined(board_customed_ld_cmd) && board_customed_ld_cmd != "") { 875 ohos_current_ld_command = board_customed_ld_cmd 876 } 877 } else { 878 # OHOS default toolchain 879 default_compiler_configs = [] 880 ohos_build_compiler = "clang" 881 ohos_clang_toolchain_dir = rebase_path("${ohos_build_compiler_dir}/bin") 882 compile_prefix += "$ohos_clang_toolchain_dir/" 883 ohos_current_cc_command = "${compile_prefix}clang$toolchain_cmd_suffix" 884 ohos_current_cxx_command = "${compile_prefix}clang++$toolchain_cmd_suffix" 885 compile_prefix += "llvm-" 886 ohos_current_ar_command = "${compile_prefix}ar$toolchain_cmd_suffix" 887 ohos_current_ld_command = ohos_current_cxx_command 888 ohos_current_strip_command = 889 "${compile_prefix}strip$toolchain_cmd_suffix --strip-unneeded" 890 if (current_os == "ohos") { 891 set_default_toolchain("//build/lite/toolchain:linux_x86_64_ohos_clang") 892 default_compiler_configs += [ 893 "//build/lite/config:ohos_clang", 894 "//build/lite/config:clang_opt", 895 ] 896 } else { 897 set_default_toolchain("//build/toolchain/linux:clang_$target_cpu") 898 default_compiler_configs += [ 899 "//build/config:default_libs", 900 "//build/config:executable_config", 901 "//build/config/compiler:default_include_dirs", 902 "//build/config/compiler:compiler", 903 ] 904 } 905 } 906 if (board_toolchain_type != "iccarm") { 907 if (current_os == "ohos") { 908 default_compiler_configs += [ 909 "//build/lite/config:board_config", 910 "//build/lite/config:cpu_arch", 911 "//build/lite/config:common", 912 "//build/lite/config:default_link_path", 913 ] 914 } 915 916 if (ohos_build_type == "debug") { 917 default_compiler_configs += [ "//build/lite/config:debug" ] 918 } else if (ohos_build_type == "release") { 919 default_compiler_configs += [ "//build/lite/config:release" ] 920 } 921 922 if (ohos_kernel_type == "liteos_a" && current_os == "ohos") { 923 default_compiler_configs += 924 [ "//build/lite/config/kernel/liteos/cortex_a:default" ] 925 } 926 927 if (ohos_kernel_type == "liteos_a" || ohos_kernel_type == "linux") { 928 default_compiler_configs += [ 929 "//build/lite/config:security", 930 "//build/lite/config:exceptions", 931 ] 932 } else if (ohos_kernel_type == "liteos_m") { 933 default_compiler_configs += [ "//build/lite/config:stack_protector" ] 934 } 935 936 default_compiler_configs += [ 937 "//build/lite/config:language_c", 938 "//build/lite/config:language_cpp", 939 "//build/config/sanitizers:default_sanitizer_flags", 940 ] 941 942 if (current_os == "ohos") { 943 default_compiler_configs += [ "//build/lite/config:kernel_macros" ] 944 } 945 946 default_shared_library_configs = 947 default_compiler_configs + 948 [ "//build/lite/config:shared_library_config" ] 949 default_static_library_configs = default_compiler_configs 950 default_executable_configs = default_compiler_configs 951 if (ohos_kernel_type != "liteos_m") { 952 default_static_library_configs += 953 [ "//build/lite/config:static_pie_config" ] 954 default_executable_configs += [ "//build/lite/config:static_pie_config" ] 955 default_executable_configs += 956 [ "//build/lite/config:pie_executable_config" ] 957 } 958 default_executable_configs += [ "//build/lite/config:board_exe_ld_flags" ] 959 } 960} 961 962set_defaults("executable") { 963 configs = default_executable_configs 964} 965 966set_defaults("static_library") { 967 configs = default_static_library_configs 968} 969 970set_defaults("shared_library") { 971 configs = default_shared_library_configs 972} 973 974set_defaults("rust_library") { 975 configs = default_compiler_configs 976} 977 978set_defaults("rust_proc_macro") { 979 configs = default_compiler_configs 980} 981 982set_defaults("source_set") { 983 configs = default_compiler_configs 984} 985 986# Sets default dependencies for executable and shared_library targets. 987# 988# Variables 989# no_default_deps: If true, no standard dependencies will be added. 990target_type_list = [ 991 "executable", 992 "loadable_module", 993 "shared_library", 994 "static_library", 995 "rust_library", 996 "source_set", 997 "rust_proc_macro", 998] 999 1000foreach(_target_type, target_type_list) { 1001 template(_target_type) { 1002 target(_target_type, target_name) { 1003 forward_variables_from(invoker, "*", [ "no_default_deps" ]) 1004 if (!defined(deps)) { 1005 deps = [] 1006 } 1007 if (!defined(invoker.no_default_deps) || !invoker.no_default_deps) { 1008 if (is_lite_system && current_os == "ohos") { 1009 deps += [ "//third_party/musl:sysroot_lite" ] 1010 } else { 1011 deps += [ "//build/config:${_target_type}_deps" ] 1012 } 1013 } 1014 } 1015 } 1016} 1017 1018if (is_lite_system && current_os == "ohos") { 1019 _target_type_list = [ 1020 "action", 1021 "action_foreach", 1022 ] 1023 1024 foreach(_target_type, _target_type_list) { 1025 template(_target_type) { 1026 target(_target_type, target_name) { 1027 forward_variables_from(invoker, "*", [ "no_default_deps" ]) 1028 if (!defined(deps)) { 1029 deps = [] 1030 } 1031 if (!defined(invoker.no_default_deps) || !invoker.no_default_deps) { 1032 deps += [ "//third_party/musl:sysroot_lite" ] 1033 } 1034 } 1035 } 1036 } 1037} 1038