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