• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2024 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.
13
14if (!defined(ark_standalone_build)) {
15  ark_standalone_build = false
16}
17
18declare_args() {
19  # If true, use icu to implement Intl APIs.
20  # If false, use @ohos.intl APIs to implement Intl APIs.
21  enable_ark_intl = true
22  run_regress_test = false
23
24  # If true, enable fuzz option. Default false.
25  enable_fuzz_option = false
26
27  # Enable pgo for building.
28  ets_runtime_feature_enable_pgo = false
29
30  # Set pgo profdata path.
31  ets_runtime_feature_pgo_path = ""
32
33  # Defaults for fort
34  ets_runtime_support_jit_code_sign = false
35  enable_jit_code_sign = false
36  disable_fort_switch = false
37
38  is_qemu_runtime = false
39
40  TARGET = "x86_64"
41  HOST_ARCH = 64
42
43  # If true app_aot_jit_enable_list will be placed in /etc/ark
44  # Default false.
45  ets_runtime_feature_enable_list = false
46  enable_gc_dfx_options = false
47}
48
49if (target_cpu == "arm64") {
50  TARGET = "aarch64"
51}
52MAPLEALL_ROOT = "//arkcompiler/ets_runtime/ecmascript/compiler/codegen/maple"
53MAPLEALL_THIRD_PARTY_ROOT = "//third_party"
54LLVM_LIB_ROOT = "//arkcompiler/ets_runtime/ecmascript/compiler/codegen/llvm/lib"
55
56if (!ark_standalone_build) {
57  build_root = "//build"
58  ark_third_party_root = "//third_party"
59  import("$build_root/config/components/toolchain/build_type.gni")
60  import("$build_root/ohos.gni")
61} else {
62  ark_third_party_root = "//arkcompiler/toolchain/build/third_party_gn"
63  import("$build_root/ark.gni")
64  import("$build_root/config/build_type.gni")
65}
66if (!defined(build_variant)) {
67  build_variant = "root"
68}
69ark_root = "//arkcompiler/runtime_core"
70js_root = "//arkcompiler/ets_runtime"
71global_root = "//base/global/i18n"
72hilog_root = "//base/hiviewdfx/hilog/interfaces/native/innerkits"
73qos_root = "//foundation/resourceschedule/qos_manager"
74compile_llvm_online = false
75run_with_asan = false
76if (enable_fuzz_option) {
77  run_with_asan = true
78}
79enable_leak_check = false
80enable_cow_array = true
81enable_coverage = false
82enable_asm_assert = false
83ark_compile_mode = "debug"
84if (defined(is_arkui_x) && is_arkui_x && defined(runtime_mode) &&
85    runtime_mode == "release") {
86  ark_compile_mode = "release"
87}
88
89asan_lib_path = "/usr/lib/llvm-10/lib/clang/10.0.0/lib/linux"
90
91# under /system/lib64 dir
92arkcompiler_relative_lib_path = "module/arkcompiler"
93if (is_standard_system || ark_standalone_build) {
94  icu_part_name = "icu"
95  icu_subsystem_name = "thirdparty"
96} else {
97  icu_part_name = "i18n"
98  icu_subsystem_name = "global"
99}
100
101if (defined(is_arkui_x) && is_arkui_x && target_os == "ios") {
102  sdk_libc_secshared_dep =
103      "$ark_third_party_root/bounds_checking_function:libsec_static"
104} else {
105  sdk_libc_secshared_dep =
106      "$ark_third_party_root/bounds_checking_function:libsec_shared"
107}
108sdk_libc_secshared_config =
109    "$ark_third_party_root/bounds_checking_function:libsec_public_config"
110
111# ohos device, windows previewer, mac previewer
112enable_hilog = !ark_standalone_build && !(defined(is_arkui_x) && is_arkui_x) &&
113               (is_ohos || is_mingw || is_mac) && !is_qemu_runtime
114enable_hisysevent =
115    !ark_standalone_build && !(defined(is_arkui_x) && is_arkui_x) && is_ohos &&
116    is_standard_system && !is_qemu_runtime
117enable_dump_in_faultlog =
118    !ark_standalone_build && !(defined(is_arkui_x) && is_arkui_x) && is_ohos &&
119    is_standard_system && !is_qemu_runtime
120enable_bytrace =
121    !ark_standalone_build && !(defined(is_arkui_x) && is_arkui_x) && is_ohos &&
122    is_standard_system && !is_qemu_runtime
123enable_hitrace =
124    !ark_standalone_build && !(defined(is_arkui_x) && is_arkui_x) && is_ohos &&
125    is_standard_system && !is_qemu_runtime
126enable_unwinder =
127    !ark_standalone_build && !(defined(is_arkui_x) && is_arkui_x) && is_ohos &&
128    is_standard_system && !is_qemu_runtime
129
130hiviewdfx_deps = []
131hiviewdfx_ext_deps = []
132if (enable_dump_in_faultlog) {
133  hiviewdfx_ext_deps += [
134    "faultloggerd:libfaultloggerd",
135    "init:libbegetutil",
136  ]
137}
138if (enable_unwinder) {
139  hiviewdfx_ext_deps += [ "faultloggerd:libunwinder" ]
140}
141if (enable_bytrace) {
142  hiviewdfx_ext_deps += [ "hitrace:hitrace_meter" ]
143}
144if (enable_hitrace) {
145  hiviewdfx_ext_deps += [ "hitrace:libhitracechain" ]
146}
147if (enable_hilog) {
148  hiviewdfx_ext_deps += [ "hilog:libhilog" ]
149}
150if (enable_hisysevent) {
151  hiviewdfx_ext_deps += [ "hisysevent:libhisysevent" ]
152}
153
154enable_sanitize = is_ohos && is_standard_system && !ark_standalone_build &&
155                  current_toolchain != host_toolchain
156
157enable_target_compilation =
158    !ark_standalone_build && !is_mac && !(defined(is_arkui_x) && is_arkui_x) &&
159    (current_cpu == "arm64" && host_cpu != "arm64")
160
161have_local_code_sign = false
162if (defined(global_parts_info) &&
163    defined(global_parts_info.security_code_signature) &&
164    global_parts_info.security_code_signature) {
165  have_local_code_sign = true
166}
167enable_local_code_sign = false
168if (have_local_code_sign && enable_target_compilation) {
169  enable_local_code_sign = true
170}
171if (!ark_standalone_build && !(defined(is_arkui_x) && is_arkui_x) && is_ohos &&
172    is_standard_system && target_cpu == "arm64" && !is_emulator &&
173    defined(global_parts_info) &&
174    defined(global_parts_info.security_code_signature)) {
175  enable_jit_code_sign = ets_runtime_support_jit_code_sign
176}
177ets_runtime_output_path = "ets_runtime/ets_runtime"
178
179template("libark_jsruntime_common_set") {
180  forward_variables_from(invoker, "*")
181
182  ohos_source_set(target_name) {
183    if (target_name == "libark_jsruntime_arm_set" && is_ohos &&
184        is_standard_system && !is_arkui_x && target_cpu == "arm64") {
185      include_dirs = [
186        "$js_root",
187        "$js_root/ecmascript/napi/include",
188      ]
189    }
190
191    stack_protector_ret = false
192
193    if (is_ohos && is_standard_system) {
194      stub_an_file_path =
195          "/system/lib64/${arkcompiler_relative_lib_path}/stub.an"
196    } else {
197      stub_an_file_path =
198          rebase_path("$root_gen_dir/arkcompiler/ets_runtime/stub.an")
199    }
200    defines = [ "STUB_AN_FILE=\"${stub_an_file_path}\"" ]
201
202    if (current_cpu == "arm64") {
203      defines += [ "ENABLE_POSTFORK_FORCEEXPAND" ]
204    }
205
206    sources = invoker.ecma_source
207    sources += invoker.ecma_profiler_source
208    sources += invoker.ecma_debugger_source
209    sources += invoker.hitrace_scope_source
210    sources += invoker.ecma_platform_source
211
212    if (is_ohos) {
213      sources += invoker.ecma_stackinfo_source
214    }
215
216    public_configs = [ "$js_root:ark_jsruntime_public_config" ]
217    public_configs += [ ":include_llvm" ]
218
219    configs = [
220      "$js_root:ark_jsruntime_common_config",
221      "$js_root:asm_interp_enable_config",
222    ]
223
224    cflags_cc = []
225    if (is_standard_system || target_os == "android" || target_os == "ios") {
226      cflags_cc += [ "-fvisibility=hidden" ]
227    }
228
229    external_deps = []
230
231    if (enable_dump_in_faultlog) {
232      external_deps += [ "libuv:uv" ]
233    }
234
235    if (target_name == "libark_jsruntime_arm_set" && is_ohos &&
236        is_standard_system && !is_arkui_x) {
237      defines += [ "ENABLE_FFRT_INTERFACES" ]
238      external_deps += [
239        "ffrt:libffrt",
240        "hilog:libhilog",
241      ]
242    }
243    deps = []
244    if (!is_arkui_x) {
245      external_deps += [ "runtime_core:arkfile_header_deps" ]
246    } else {
247      deps += [ "$ark_root/libpandafile:arkfile_header_deps" ]
248    }
249
250    if (is_ohos && is_standard_system && !is_arkui_x &&
251        defined(global_parts_info) &&
252        defined(global_parts_info.resourceschedule_qos_manager)) {
253      defines += [ "ENABLE_QOS" ]
254      external_deps += [ "qos_manager:qos" ]
255    }
256
257    if (!ark_standalone_build && !(defined(is_arkui_x) && is_arkui_x) &&
258        is_ohos && is_standard_system) {
259      external_deps += [ "init:libbegetutil" ]
260      defines += [
261        "GET_PARAMETER_FOR_JIT",
262        "JIT_ESCAPE_ENABLE",
263        "AOT_ESCAPE_ENABLE",
264        "OHOS_GET_PARAMETER",
265      ]
266    }
267
268    if (ark_standalone_build) {
269      defines += [ "STANDALONE_MODE" ]
270    }
271
272    include_dirs = []
273    if (enable_jit_code_sign) {
274      defines += [ "JIT_ENABLE_CODE_SIGN" ]
275      external_deps += [ "code_signature:libjit_code_sign" ]
276      if (disable_fort_switch) {
277        defines += [ "JIT_FORT_DISABLE" ]
278      }
279    }
280
281    if (enable_target_compilation) {
282      external_deps += [ "c_utils:utils" ]
283    }
284
285    # hiviewdfx libraries
286    external_deps += hiviewdfx_ext_deps
287    deps += hiviewdfx_deps
288
289    if (ark_standalone_build || is_arkui_x) {
290      deps += [ "$ark_third_party_root/zlib:libz" ]
291    } else {
292      external_deps += [ "zlib:shared_libz" ]
293    }
294
295    # gc dfx options
296    if (enable_gc_dfx_options) {
297      defines += [ "ECMASCRIPT_ENABLE_GC_DFX_OPTIONS" ]
298    }
299
300    part_name = "ets_runtime"
301    subsystem_name = "arkcompiler"
302  }
303}
304
305template("libark_jsruntime_intl_common_set") {
306  forward_variables_from(invoker, "*")
307
308  ohos_source_set(target_name) {
309    stack_protector_ret = false
310    sources = invoker.intl_sources
311
312    public_configs = [ "$js_root:ark_jsruntime_public_config" ]
313
314    configs = [ "$js_root:ark_jsruntime_common_config" ]
315
316    cflags_cc = []
317    if (is_standard_system || target_os == "android" || target_os == "ios") {
318      cflags_cc += [ "-fvisibility=hidden" ]
319    }
320
321    external_deps = []
322    deps = []
323    if (!is_arkui_x) {
324      external_deps += [ "runtime_core:arkfile_header_deps" ]
325    } else {
326      deps += [ "$ark_root/libpandafile:arkfile_header_deps" ]
327    }
328
329    # hiviewdfx libraries
330    external_deps += hiviewdfx_ext_deps
331    deps += hiviewdfx_deps
332
333    part_name = "ets_runtime"
334    subsystem_name = "arkcompiler"
335  }
336}
337