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