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