1# Copyright (c) 2022 Huawei Device Co., Ltd.
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at
5#
6# http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13declare_args() {
14  ark_standalone_build = true
15  use_musl = true
16  build_root = "//arkcompiler/toolchain/build"
17  run_with_qemu = false
18  so_dir_for_qemu = "common/common/libc"
19  enable_lto_O0 = false
20  disable_force_gc = false
21  timeout = 1200
22}
23
24check_mac_system_and_cpu_script =
25    rebase_path("$build_root/scripts/check_mac_system_and_cpu.py")
26check_darwin_system_result =
27    exec_script(check_mac_system_and_cpu_script, [ "system" ], "string")
28
29if (check_darwin_system_result != "") {
30  check_mac_host_cpu_result =
31      exec_script(check_mac_system_and_cpu_script, [ "cpu" ], "string")
32  if (check_mac_host_cpu_result != "") {
33    host_cpu = "arm64"
34  }
35}
36
37if (host_os == "linux") {
38  host_platform_dir = "linux-x86_64"
39} else if (host_os == "mac") {
40  if (host_cpu == "arm64") {
41    host_platform_dir = "darwin-arm64"
42  } else {
43    host_platform_dir = "darwin-x86_64"
44  }
45} else {
46  assert(false, "Unsupported host_os: $host_os")
47}
48
49declare_args() {
50  # Debug build. Enabling official builds automatically sets is_debug to false.
51  is_debug = false
52  is_standard_system = false
53}
54
55declare_args() {
56  # Enable mini debug info, it will add .gnu_debugdata
57  # section in each stripped sofile
58
59  # Currently, we don't publish ohos-adapted python on m1 platform,
60  # So that we disable mini debug info on m1 platform until
61  # ohos-adapted python publishing on m1 platform
62  if (host_os == "mac") {
63    full_mini_debug = false
64  } else {
65    full_mini_debug = true
66  }
67}
68
69declare_args() {
70  host_toolchain = ""
71  custom_toolchain = ""
72  target_toolchain = ""
73
74  is_clang = current_os != "linux" ||
75             (current_cpu != "s390x" && current_cpu != "s390" &&
76              current_cpu != "ppc64" && current_cpu != "ppc" &&
77              current_cpu != "mips" && current_cpu != "mips64")
78
79  target_platform = "phone"
80
81  is_official_build = false
82
83  is_component_build = false
84
85  # build for cross platform
86  is_arkui_x = false
87}
88
89is_wearable_product = "${target_platform}" == "wearable"
90
91is_emulator = false
92
93if (target_os == "ohos" && target_cpu == "x86_64") {
94  is_emulator = true
95}
96
97# Determine host_toolchain. (like a constant in a build on a certain host)
98if (host_toolchain == "") {
99  if (host_os == "linux") {
100    if (target_os != "linux") {
101      host_toolchain = "$build_root/toolchain/linux:clang_$host_cpu"
102    } else if (is_clang) {
103      host_toolchain = "$build_root/toolchain/linux:clang_$host_cpu"
104    } else {
105      host_toolchain = "$build_root/toolchain/linux:$host_cpu"
106    }
107  } else if (host_os == "mac") {
108    host_toolchain = "$build_root/toolchain/mac:clang_$host_cpu"
109  } else {
110    assert(false, "Unsupported host_os: $host_os")
111  }
112}
113
114# Determine default_toolchain.
115# (like a constant in a build for a certain target on a certain host)
116_default_toolchain = host_toolchain
117if (target_os == "ohos") {
118  _default_toolchain = "$build_root/toolchain/ark:ark_clang_${target_cpu}"
119} else if (target_os == "linux" && target_cpu == "x64") {
120  _default_toolchain = "$build_root/toolchain/linux:clang_x64"
121} else if (target_os == "linux" && target_cpu == "x86") {
122  _default_toolchain = "$build_root/toolchain/linux:clang_x86"
123} else if (target_os == "mingw" && target_cpu == "x86_64") {
124  _default_toolchain = "$build_root/toolchain/mingw:mingw_x86_64"
125} else if (target_os == "android" && target_cpu == "arm64") {
126  _default_toolchain = "$build_root/toolchain/aosp:aosp_clang_arm64"
127} else if (target_os == "mac" && target_cpu == "arm64") {
128  _default_toolchain = "$build_root/toolchain/mac:clang_arm64"
129}
130if (custom_toolchain != "") {
131  set_default_toolchain(custom_toolchain)
132} else if (_default_toolchain != "") {
133  set_default_toolchain(_default_toolchain)
134}
135
136# Determine current_cpu and current_os.
137# (like a variable which could be changed during tracing deps)
138if (current_cpu == "") {
139  current_cpu = target_cpu
140}
141if (current_os == "") {
142  current_os = target_os
143}
144
145# Variables like "is_..." are already used to represent for
146# "current_os == "..."" in most of the repositories. Thus, we need to make them
147# change with the change of current_os.
148if (current_os == "mac") {
149  is_aix = false
150  is_ohos = false
151  is_chromeos = false
152  is_linux = false
153  is_mac = true
154  is_nacl = false
155  is_posix = true
156  is_win = false
157  is_mingw = false
158  is_android = false
159  is_ios = false
160} else if (current_os == "ohos") {
161  is_ohos = true
162  is_linux = false
163  is_mac = false
164  is_posix = true
165  is_win = false
166  is_mingw = false
167  is_android = false
168  is_ios = false
169} else if (current_os == "linux") {
170  is_ohos = false
171  is_linux = true
172  is_mac = false
173  is_posix = true
174  is_win = false
175  is_mingw = false
176  is_android = false
177  is_ios = false
178} else if (current_os == "mingw") {
179  is_ohos = false
180  is_linux = false
181  is_mac = false
182  is_posix = true
183  is_win = false
184  is_mingw = true
185  is_android = false
186  is_ios = false
187} else if (current_os == "android") {
188  is_ohos = false
189  is_linux = false
190  is_mac = false
191  is_posix = true
192  is_win = false
193  is_mingw = false
194  is_android = true
195  is_ios = false
196}
197
198default_compiler_configs = [
199  "$build_root/config/compiler:default_warnings",
200  "$build_root/config/compiler:compiler",
201  "$build_root/config/compiler:default_include_dirs",
202  "$build_root/config/compiler:default_optimization",
203  "$build_root/config/compiler:runtime_config",
204  "$build_root/config:default_libs",
205  "$build_root/config/compiler:ark_code",
206  "$build_root/config/compiler:no_rtti",
207]
208
209default_static_library_configs = default_compiler_configs
210default_source_set_configs = default_compiler_configs
211default_shared_library_configs =
212    default_compiler_configs + [ "$build_root/config:shared_library_config" ]
213default_executable_configs =
214    default_compiler_configs + [ "$build_root/config:executable_config" ]
215
216set_defaults("executable") {
217  configs = default_executable_configs
218}
219
220set_defaults("static_library") {
221  configs = default_static_library_configs
222}
223
224set_defaults("shared_library") {
225  configs = default_shared_library_configs
226}
227
228set_defaults("source_set") {
229  configs = default_source_set_configs
230}
231
232target_list = [
233  "static_library",
234  "shared_library",
235  "source_set",
236  "executable",
237]
238
239foreach(target, target_list) {
240  template(target) {
241    target(target, target_name) {
242      forward_variables_from(invoker, "*", [ "no_default_deps" ])
243      if (!defined(deps)) {
244        deps = []
245      }
246      if (!defined(invoker.no_default_deps) || !invoker.no_default_deps) {
247        deps += [ "$build_root/config:${target}_deps" ]
248      }
249    }
250  }
251}
252