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