• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2021 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
14import("//arkcompiler/ets_runtime/js_runtime_config.gni")
15
16if (ark_standalone_build) {
17  import("$build_root/ark.gni")
18} else {
19  import("//build/ohos.gni")
20}
21
22action("build_llvm_libs") {
23  script = "compile_llvm_lib.sh"
24  sources = [ "$js_root/ecmascript/compiler/compile_llvm_lib.sh" ]
25  outputs = [ "${root_out_dir}/llvm" ]
26}
27
28config("include_llvm") {
29  if (compile_llvm_online) {
30    include_dirs = [
31      "//third_party/third_party_llvm-project/build/include",
32      "//third_party/third_party_llvm-project/llvm/include/",
33    ]
34  } else {
35    if (is_mingw) {
36      include_dirs = [
37        "//prebuilts/ark_tools/ark_js_prebuilts/llvm_prebuilts_windows/llvm/include",
38        "//prebuilts/ark_tools/ark_js_prebuilts/llvm_prebuilts_windows/build/include",
39      ]
40    } else if (is_mac) {
41      if (host_cpu == "arm64") {
42        include_dirs = [
43          "//prebuilts/ark_tools/ark_js_prebuilts/llvm_prebuilts_darwin_arm64/llvm/include",
44          "//prebuilts/ark_tools/ark_js_prebuilts/llvm_prebuilts_darwin_arm64/build/include",
45        ]
46      } else {
47        include_dirs = [
48          "//prebuilts/ark_tools/ark_js_prebuilts/llvm_prebuilts_darwin_x64/llvm/include",
49          "//prebuilts/ark_tools/ark_js_prebuilts/llvm_prebuilts_darwin_x64/build/include",
50        ]
51      }
52    } else {
53      if (current_cpu == "arm64") {
54        include_dirs = [
55          "//prebuilts/ark_tools/ark_js_prebuilts/llvm_prebuilts_aarch64/llvm/include",
56          "//prebuilts/ark_tools/ark_js_prebuilts/llvm_prebuilts_aarch64/build/include",
57        ]
58      } else {
59        include_dirs = [
60          "//prebuilts/ark_tools/ark_js_prebuilts/llvm_prebuilts/llvm/include",
61          "//prebuilts/ark_tools/ark_js_prebuilts/llvm_prebuilts/build/include",
62        ]
63      }
64    }
65    cflags_cc = [ "-DARK_GC_SUPPORT" ]
66  }
67}
68
69source_set("libark_jsoptimizer_set") {
70  sources = [
71    "access_object_stub_builder.cpp",
72    "argument_accessor.cpp",
73    "assembler/aarch64/assembler_aarch64.cpp",
74    "assembler/aarch64/extend_assembler.cpp",
75    "assembler/x64/assembler_x64.cpp",
76    "assembler/x64/extended_assembler_x64.cpp",
77    "assembler_module.cpp",
78    "async_function_lowering.cpp",
79    "bc_call_signature.cpp",
80    "builtins/builtins_call_signature.cpp",
81    "builtins/builtins_string_stub_builder.cpp",
82    "builtins/builtins_stubs.cpp",
83    "builtins/containers_stub_builder.cpp",
84    "builtins_lowering.cpp",
85    "bytecode_circuit_builder.cpp",
86    "bytecode_info_collector.cpp",
87    "bytecodes.cpp",
88    "call_signature.cpp",
89    "circuit.cpp",
90    "circuit_builder.cpp",
91    "circuit_optimizer.cpp",
92    "common_stubs.cpp",
93    "compilation_driver.cpp",
94    "compiler_log.cpp",
95    "early_elimination.cpp",
96    "file_generators.cpp",
97    "frame_states.cpp",
98    "gate.cpp",
99    "gate_accessor.cpp",
100    "gate_meta_data.cpp",
101    "ic_stub_builder.cpp",
102    "interpreter_stub.cpp",
103    "llvm_codegen.cpp",
104    "llvm_ir_builder.cpp",
105    "new_object_stub_builder.cpp",
106    "operations_stub_builder.cpp",
107    "pass_manager.cpp",
108    "rt_call_signature.cpp",
109    "scheduler.cpp",
110    "slowpath_lowering.cpp",
111    "stub.cpp",
112    "stub_builder.cpp",
113    "test_stubs.cpp",
114    "test_stubs_signature.cpp",
115    "trampoline/aarch64/asm_interpreter_call.cpp",
116    "trampoline/aarch64/common_call.cpp",
117    "trampoline/aarch64/optimized_call.cpp",
118    "trampoline/x64/asm_interpreter_call.cpp",
119    "trampoline/x64/common_call.cpp",
120    "trampoline/x64/optimized_call.cpp",
121    "ts_inline_lowering.cpp",
122    "ts_type_lowering.cpp",
123    "type.cpp",
124    "type_inference/type_infer.cpp",
125    "type_lowering.cpp",
126    "type_recorder.cpp",
127    "verifier.cpp",
128  ]
129
130  public_configs = [
131    ":include_llvm",
132    "$js_root:ark_jsruntime_compiler_config",
133    "$js_root:ark_jsruntime_public_config",
134  ]
135
136  if (compile_llvm_online) {
137    lib_dirs = [ "//third_party/third_party_llvm-project/build/lib" ]
138  } else {
139    if (is_mingw) {
140      lib_dirs = [
141        "//prebuilts/ark_tools/ark_js_prebuilts/llvm_prebuilts_windows/build/lib",
142        "//prebuilts/mingw-w64/ohos/linux-x86_64/clang-mingw/x86_64-w64-mingw32",
143      ]
144    } else if (is_mac) {
145      if (host_cpu == "arm64") {
146        lib_dirs = [ "//prebuilts/ark_tools/ark_js_prebuilts/llvm_prebuilts_darwin_arm64/build/lib" ]
147      } else {
148        lib_dirs = [ "//prebuilts/ark_tools/ark_js_prebuilts/llvm_prebuilts_darwin_x64/build/lib" ]
149      }
150    } else {
151      if (current_cpu == "arm64") {
152        lib_dirs = [ "//prebuilts/ark_tools/ark_js_prebuilts/llvm_prebuilts_aarch64/build/lib" ]
153      } else {
154        lib_dirs = [
155          "//prebuilts/ark_tools/ark_js_prebuilts/llvm_prebuilts/build/lib",
156        ]
157      }
158    }
159  }
160
161  libs = [
162    "LLVMTarget",
163    "LLVMObject",
164    "LLVMMC",
165    "LLVMSupport",
166    "LLVMCore",
167    "LLVMExecutionEngine",
168    "LLVMInterpreter",
169    "LLVMMCJIT",
170    "LLVMExegesis",
171    "LLVMRuntimeDyld",
172    "LLVMInstCombine",
173    "LLVMAnalysis",
174    "LLVMScalarOpts",
175    "LLVMBinaryFormat",
176    "LLVMDebugInfoDWARF",
177    "LLVMRemarks",
178    "LLVMTextAPI",
179    "LLVMScalarOpts",
180    "LLVMTransformUtils",
181    "LLVMBitReader",
182    "LLVMAsmPrinter",
183    "LLVMProfileData",
184    "LLVMBitstreamReader",
185    "LLVMSelectionDAG",
186    "LLVMGlobalISel",
187    "LLVMLTO",
188    "LLVMCFGuard",
189    "LLVMVectorize",
190    "LLVMDemangle",
191    "LLVMipo",
192    "LLVMInstrumentation",
193    "LLVMDebugInfoCodeView",
194    "LLVMAggressiveInstCombine",
195    "LLVMAsmParser",
196    "LLVMMCParser",
197    "LLVMMIRParser",
198    "LLVMMCDisassembler",
199    "LLVMCodeGen",
200    "LLVMTransformUtils",
201    "LLVMIRReader",
202    "LLVMAArch64Utils",
203    "LLVMAArch64CodeGen",
204    "LLVMAArch64Info",
205    "LLVMAArch64Desc",
206    "LLVMAArch64Disassembler",
207    "LLVMAArch64AsmParser",
208    "LLVMFrontendOpenMP",
209    "LLVMBitWriter",
210  ]
211
212  # Only support compiling aarch64 target at device-side(arm64 platform).
213  # So these os-related libs of arm and x86 are not needed on arm64 platform.
214  if (is_mac || current_cpu != "arm64") {
215    libs += [
216      "LLVMARMUtils",
217      "LLVMARMCodeGen",
218      "LLVMARMDisassembler",
219      "LLVMARMDesc",
220      "LLVMARMInfo",
221      "LLVMARMAsmParser",
222      "LLVMX86AsmParser",
223      "LLVMX86CodeGen",
224      "LLVMX86Desc",
225      "LLVMX86Disassembler",
226      "LLVMX86Info",
227    ]
228  }
229
230  if (is_mingw) {
231    libs += [
232      "kernel32",
233      "shell32",
234      "uuid",
235      "advapi32",
236      "msvcrt",
237      "msvcrt-os",
238      "windowsapp",
239    ]
240  }
241
242  deps = [ "$ark_root/libpandafile:arkfile_header_deps" ]
243
244  if (compile_llvm_online) {
245    deps += [ ":build_llvm_libs" ]
246  }
247}
248
249source_set("ark_stub_compiler_set") {
250  sources = [ "stub_compiler.cpp" ]
251  include_dirs = [ "$target_gen_dir" ]
252
253  public_configs = [
254    ":include_llvm",
255    "$js_root:ark_jsruntime_compiler_config",
256    "$js_root:ark_jsruntime_public_config",
257  ]
258
259  deps = [
260    ":libark_jsoptimizer_set",
261    ":libark_mock_stub_set",
262    "$js_root:libark_js_intl_set",
263    "$js_root:libark_jsruntime_set",
264  ]
265}
266
267source_set("ark_aot_compiler_set") {
268  sources = [ "aot_compiler.cpp" ]
269
270  public_configs = [
271    ":include_llvm",
272    "$js_root:ark_jsruntime_compiler_config",
273    "$js_root:ark_jsruntime_public_config",
274  ]
275
276  deps = [
277    "$js_root:libark_jsruntime_set",
278  ]
279}
280
281source_set("libark_stub_set") {
282  deps = [ ":build_stub_to_cpp" ]
283
284  sources = [ "$root_gen_dir/arkcompiler/ets_runtime/stub_an.cpp" ]
285
286  public_configs = [
287    "$js_root:ark_jsruntime_common_config",
288    "$js_root:ark_jsruntime_public_config",
289  ]
290}
291
292source_set("libark_mock_stub_set") {
293  sources = [ "mock/mock_stub_an.cpp" ]
294
295  public_configs = [
296    "$js_root:ark_jsruntime_common_config",
297    "$js_root:ark_jsruntime_public_config",
298  ]
299}
300
301ohos_shared_library("libark_jsoptimizer") {
302  deps = [
303    ":libark_jsoptimizer_set",
304    ":libark_mock_stub_set",
305    "$ark_root/libpandabase:libarkbase_static",
306    "$ark_root/libpandafile:libarkfile_static",
307    "$js_root:libark_js_intl_set",
308    "$js_root:libark_jsruntime_set",
309  ]
310
311  if (is_mingw && !ark_standalone_build) {
312    deps += [
313      "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog_windows",
314    ]
315  }
316
317  if (target_os == "ios") {
318    deps += [
319      "$ark_third_party_root/icu/icu4c:static_icui18n",
320      "$ark_third_party_root/icu/icu4c:static_icuuc",
321    ]
322  } else {
323    deps += [
324      "$ark_third_party_root/icu/icu4c:shared_icui18n",
325      "$ark_third_party_root/icu/icu4c:shared_icuuc",
326    ]
327  }
328
329  if (run_with_asan) {
330    defines = [ "RUN_WITH_ASAN" ]
331  }
332
333  install_enable = false
334
335  if (!is_mingw && !is_mac) {
336    output_extension = "so"
337  }
338  part_name = "ets_runtime"
339  subsystem_name = "arkcompiler"
340}
341
342ohos_shared_library("libark_jsoptimizer_test") {
343  deps = [
344    ":libark_jsoptimizer_set",
345    "$ark_root/libpandafile:libarkfile_static",
346    "$js_root:libark_jsruntime_test_set",
347  ]
348
349  ldflags = []
350  if (enable_coverage) {
351    ldflags += [ "--coverage" ]
352    cflags_cc = [ "--coverage" ]
353  }
354
355  if (!ark_standalone_build) {
356    ldflags += [ "-Wl,--lto-O0" ]
357  }
358  install_enable = false
359
360  output_extension = "so"
361  subsystem_name = "test"
362}
363
364ohos_executable("ark_stub_compiler") {
365  deps = [
366    ":ark_stub_compiler_set",
367    "$ark_root/libpandafile:libarkfile_static",
368  ]
369
370  if (!ark_standalone_build) {
371    ldflags = [ "-Wl,--lto-O0" ]
372  }
373  install_enable = false
374
375  if (run_with_asan) {
376    defines = [ "RUN_WITH_ASAN" ]
377  }
378
379  if (target_os == "ios") {
380    deps += [
381      "$ark_third_party_root/icu/icu4c:static_icui18n",
382      "$ark_third_party_root/icu/icu4c:static_icuuc",
383    ]
384  } else {
385    deps += [
386      "$ark_third_party_root/icu/icu4c:shared_icui18n",
387      "$ark_third_party_root/icu/icu4c:shared_icuuc",
388    ]
389  }
390
391  part_name = "ets_runtime"
392  subsystem_name = "arkcompiler"
393}
394
395ohos_executable("ark_aot_compiler") {
396  deps = [ ":ark_aot_compiler_set" ]
397
398  if (ark_standalone_build) {
399    ldflags = [ "-shared" ]
400  }
401
402  deps += [
403    ":libark_mock_stub_set",
404    "$ark_root/libpandabase:libarkbase_static",
405    "$ark_root/libpandafile:libarkfile_static",
406    "$js_root:libark_js_intl_set",
407    "$js_root:libark_jsruntime_set",
408    "$js_root/ecmascript/compiler:libark_jsoptimizer_set",
409  ]
410
411  if (is_mingw && !ark_standalone_build) {
412    deps += [
413      "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog_windows",
414    ]
415  }
416
417  if (is_mac && !ark_standalone_build) {
418    deps += [
419      "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog_mac",
420    ]
421  }
422
423  if (target_os == "ios") {
424    deps += [
425      "$ark_third_party_root/icu/icu4c:static_icui18n",
426      "$ark_third_party_root/icu/icu4c:static_icuuc",
427    ]
428  } else {
429    deps += [
430      "$ark_third_party_root/icu/icu4c:shared_icui18n",
431      "$ark_third_party_root/icu/icu4c:shared_icuuc",
432    ]
433  }
434
435  if (is_ohos && is_standard_system) {
436    if (enable_dump_in_faultlog || enable_bytrace || enable_hitrace ||
437        enable_hilog) {
438      external_deps = []
439    }
440    if (enable_dump_in_faultlog) {
441      external_deps += [ "faultloggerd:libfaultloggerd" ]
442    }
443    if (enable_bytrace) {
444      external_deps += [ "hitrace_native:hitrace_meter" ]
445    }
446    if (enable_hitrace) {
447      external_deps += [ "hitrace_native:libhitracechain" ]
448    }
449    if (enable_hilog) {
450      external_deps += [ "hiviewdfx_hilog_native:libhilog" ]
451    }
452  }
453
454  install_enable = false
455
456  part_name = "ets_runtime"
457  subsystem_name = "arkcompiler"
458}
459
460action("gen_stub_file") {
461  script = "$js_root/script/run_ark_executable.py"
462
463  deps = [ "$js_root/ecmascript/compiler:ark_stub_compiler(${host_toolchain})" ]
464
465  stub_file_gen_dir = "$root_gen_dir/arkcompiler/ets_runtime"
466  root_out_dir_with_host_toolchain =
467      get_label_info(":ark_stub_compiler(${host_toolchain})", "root_out_dir")
468
469  if (current_toolchain == host_toolchain || ark_standalone_build) {
470    stub_option = " --stub-file=" + rebase_path(stub_file_gen_dir) + "/stub.an"
471  } else {
472    stub_option = " --stub-file=" + rebase_path(stub_file_gen_dir) +
473                  "/stub.an" + " --target-triple=aarch64-unknown-linux-gnu"
474  }
475
476  args = [
477    "--script-file",
478    rebase_path(root_out_dir_with_host_toolchain) +
479        "/arkcompiler/ets_runtime/ark_stub_compiler",
480    "--script-options",
481    stub_option,
482    "--expect-output",
483    "0",
484    "--timeout-limit",
485    "300",
486    "--env-path",
487    rebase_path(root_out_dir_with_host_toolchain) +
488        "/arkcompiler/ets_runtime:" +
489        rebase_path(root_out_dir_with_host_toolchain) +
490        "/${icu_subsystem_name}/${icu_part_name}:" +
491        rebase_path(root_out_dir_with_host_toolchain) + "/thirdparty/zlib:" +
492        rebase_path("//prebuilts/clang/ohos/linux-x86_64/llvm/lib/"),
493  ]
494
495  outputs = [ "$stub_file_gen_dir/stub.an" ]
496}
497
498action("build_stub_to_cpp") {
499  sources = [ "$root_gen_dir/arkcompiler/ets_runtime/stub.an" ]
500
501  script = "$js_root/script/build_resource_to_cpp.py"
502
503  deps = [ ":gen_stub_file" ]
504
505  args = [
506    "--input",
507    rebase_path("$root_gen_dir/arkcompiler/ets_runtime/stub.an"),
508    "--output",
509    rebase_path("$root_gen_dir/arkcompiler/ets_runtime/stub_an.cpp"),
510  ]
511
512  outputs = [ "$root_gen_dir/arkcompiler/ets_runtime/stub_an.cpp" ]
513}
514