• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2021-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
14import("//arkcompiler/runtime_core/static_core/ark_config.gni")
15import("//arkcompiler/runtime_core/static_vm_config.gni")
16import("$ark_root/plugins/plugins.gni")
17
18if (ark_standalone_build) {
19  import("$build_root/ark.gni")
20} else {
21  import("//build/ohos.gni")
22}
23
24group("ark_packages") {
25  if (enable_static_vm) {
26    deps = plugin_ark_packages
27    if (host_os != "mac") {
28      deps += [
29        "$ark_root/compiler:libarktscompiler",
30        "$ark_root/compiler/aot:libarkaotmanager",
31        "$ark_root/libpandabase:libarktsbase",
32        "$ark_root/libpandafile:libarktsfile",
33        "$ark_root/libpandafile/external:libarkfileExt",
34        "$ark_root/libpandafile/external:libarksupport",
35        "$ark_root/libziparchive:libarktsziparchive",
36        "$ark_root/panda:arkts_bin",
37        "$ark_root/runtime:libarkruntime",
38        "$ark_root/runtime/tooling/inspector:libarkinspector",
39        "$ark_root/verification/verifier:verifier.config",
40        "$ark_root/verification/verifier:verifier_bin",
41      ]
42      if (enable_codegen) {
43        deps += [
44          "$ark_root/compiler/optimizer/code_generator:libarkencoder",
45          "$ark_root/compiler/tools/paoc:ark_aot",
46        ]
47      }
48    }
49  }
50}
51
52group("ark_host_linux_tools_packages") {
53  deps = plugin_ark_host_linux_tools_packages
54  if (host_os != "mac" && current_cpu != "arm") {
55    deps += [
56      "$ark_root/assembler:arkts_asm(${host_toolchain})",
57      "$ark_root/compiler:libarktscompiler(${host_toolchain})",
58      "$ark_root/compiler/aot:libarkaotmanager(${host_toolchain})",
59      "$ark_root/libpandabase:libarktsbase(${host_toolchain})",
60      "$ark_root/libpandafile:libarktsfile(${host_toolchain})",
61      "$ark_root/libpandafile/external:libarkfileExt(${host_toolchain})",
62      "$ark_root/libpandafile/external:libarksupport(${host_toolchain})",
63      "$ark_root/libziparchive:libarktsziparchive(${host_toolchain})",
64      "$ark_root/panda:arkts_bin(${host_toolchain})",
65      "$ark_root/runtime:libarkruntime(${host_toolchain})",
66    ]
67    if (enable_codegen) {
68      deps += [ "$ark_root/compiler/optimizer/code_generator:libarkencoder(${host_toolchain})" ]
69    }
70
71    # TODO: don't exclude these targets from OHOS build
72    if (ark_static_standalone_build) {
73      deps += [
74        "$ark_root/compiler/tools/aotdump:ark_aotdump(${host_toolchain})",
75        "$ark_root/compiler/tools/paoc:ark_aot(${host_toolchain})",
76        "$ark_root/disassembler:arkts_disasm(${host_toolchain})",
77        "$ark_root/static_linker:ark_link(${host_toolchain})",
78      ]
79    }
80  }
81}
82
83group("ark_host_windows_tools_packages") {
84  deps = plugin_ark_host_windows_tools_packages
85  if (host_os != "mac" && current_cpu != "arm" &&
86      !ark_static_standalone_build && !ark_standalone_build) {
87    deps += [
88      "$ark_root/assembler:arkts_asm(//build/toolchain/mingw:mingw_x86_64)",
89      "$ark_root/disassembler:arkts_disasm(//build/toolchain/mingw:mingw_x86_64)",
90      "$ark_root/static_linker:ark_link(//build/toolchain/mingw:mingw_x86_64)",
91    ]
92  }
93}
94
95group("ark_host_mac_tools_packages") {
96  deps = plugin_ark_host_mac_tools_packages
97  if (host_os == "mac") {
98    if (host_cpu == "arm64") {
99      deps += [
100        "$ark_root/assembler:arkts_asm($build_root/toolchain/mac:clang_arm64)",
101        "$ark_root/disassembler:arkts_disasm($build_root/toolchain/mac:clang_arm64)",
102        "$ark_root/libpandabase:libarktsbase($build_root/toolchain/mac:clang_arm64)",
103        "$ark_root/libpandafile:libarktsfile($build_root/toolchain/mac:clang_arm64)",
104        "$ark_root/libziparchive:libarktsziparchive($build_root/toolchain/mac:clang_arm64)",
105        "$ark_root/static_linker:ark_link($build_root/toolchain/mac:clang_arm64)",
106      ]
107    } else {
108      deps += [
109        "$ark_root/assembler:arkts_asm($build_root/toolchain/mac:clang_x64)",
110        "$ark_root/disassembler:arkts_disasm($build_root/toolchain/mac:clang_x64)",
111        "$ark_root/libpandabase:libarktsbase($build_root/toolchain/mac:clang_x64)",
112        "$ark_root/libpandafile:libarktsfile($build_root/toolchain/mac:clang_x64)",
113        "$ark_root/libziparchive:libarktsziparchive($build_root/toolchain/mac:clang_x64)",
114        "$ark_root/static_linker:ark_link($build_root/toolchain/mac:clang_x64)",
115      ]
116    }
117  }
118}
119
120group("ark_host_tests") {
121  testonly = true
122  deps = []
123  if (defined(extras)) {
124    foreach(ext, extras) {
125      deps += [ "${ext}:host_tests" ]
126    }
127  }
128}
129
130# Common config for ark source
131config("ark_config") {
132  if (!ark_static_standalone_build) {
133    visibility = [
134      "$abckit_root/*",
135      "$ark_es2panda_root:libes2panda",
136      "$ark_es2panda_root:libes2panda_frontend_static",
137      "$ark_es2panda_root:libes2panda_public",
138      "$ark_es2panda_root:libes2panda_public_frontend_static",
139      "$ark_es2panda_root/aot:ets2panda",
140      "$ark_third_party_root/asmjit:*",
141      "$ark_third_party_root/vixl:*",
142      "./*",
143    ]
144  }
145
146  include_dirs = [
147    "$ark_root",
148    get_label_info(":create_pipeline(${default_toolchain})", "target_gen_dir"),
149  ]
150  defines = [ "PANDA_TARGET_MOBILE_WITH_MANAGED_LIBS=1" ]
151  if (enable_codegen) {
152    defines += [ "PANDA_COMPILER_ENABLE" ]
153  }
154  if (is_emulator) {
155    defines += [ "PANDA_TARGET_EMULATOR" ]
156  }
157
158  if (is_llvm_interpreter || is_llvm_fastpath) {
159    defines += [ "PANDA_LLVM_IRTOC" ]
160    if (is_llvm_interpreter) {
161      defines += [ "PANDA_LLVM_INTERPRETER" ]
162    }
163    if (is_llvm_fastpath) {
164      defines += [ "PANDA_LLVM_FASTPATH" ]
165    }
166  }
167  if (is_llvm_aot) {
168    defines += [ "PANDA_LLVM_AOT" ]
169  }
170
171  if (is_ohos && is_standard_system) {
172    defines += [ "PANDA_TARGET_OHOS" ]
173    include_dirs += [ "$hilog_root/include" ]
174  }
175
176  if (is_linux) {
177    defines += [
178      "PANDA_TARGET_UNIX",
179      "PANDA_TARGET_LINUX",
180      "PANDA_WITH_BYTECODE_OPTIMIZER",
181      "PANDA_WITH_COMPILER",
182    ]
183    if (enable_irtoc) {
184      defines += [ "PANDA_WITH_IRTOC" ]
185    }
186    if (enable_codegen) {
187      defines += [ "PANDA_WITH_CODEGEN" ]
188    }
189    if (!is_asan) {
190      defines += [ "PANDA_USE_FUTEX" ]
191    }
192  } else if (is_mingw) {
193    defines += [
194      "PANDA_TARGET_WINDOWS",
195      "PANDA_WITH_BYTECODE_OPTIMIZER",
196      "PANDA_WITH_COMPILER",
197      "_CRTBLD",
198      "__LIBMSVCRT__",
199    ]
200    if (enable_irtoc) {
201      defines += [ "PANDA_WITH_IRTOC" ]
202    }
203    if (enable_codegen) {
204      defines += [ "PANDA_WITH_CODEGEN" ]
205    }
206  } else if (is_mac) {
207    defines += [
208      "PANDA_TARGET_UNIX",
209      "PANDA_TARGET_MACOS",
210      "PANDA_WITH_BYTECODE_OPTIMIZER",
211      "PANDA_WITH_COMPILER",
212
213      # "PANDA_USE_FUTEX",
214    ]
215    if (enable_irtoc) {
216      defines += [ "PANDA_WITH_IRTOC" ]
217    }
218    if (enable_codegen) {
219      defines += [ "PANDA_WITH_CODEGEN" ]
220    }
221  } else if (is_mob) {
222    defines += [
223      "PANDA_TARGET_UNIX",
224      "PANDA_USE_FUTEX",
225      "PANDA_TARGET_MOBILE",
226      "PANDA_TARGET_MOBILE_WITH_NATIVE_LIBS",
227    ]
228  } else if (is_ohos) {
229    defines += [
230      # TODO: use PANDA_TARGET_OHOS instead of PANDA_TARGET_UNIX
231      "PANDA_TARGET_UNIX",
232      "PANDA_WITH_COMPILER",
233    ]
234    if (!is_asan) {
235      defines += [ "PANDA_USE_FUTEX" ]
236    }
237    if (enable_irtoc) {
238      defines += [ "PANDA_WITH_IRTOC" ]
239    }
240    if (enable_codegen) {
241      defines += [ "PANDA_WITH_CODEGEN" ]
242    }
243  } else {
244    defines += [
245      "PANDA_TARGET_UNIX",
246      "PANDA_USE_FUTEX",
247    ]
248  }
249
250  if (!is_debug) {
251    defines += [ "NDEBUG" ]
252  }
253
254  cflags_cc = [
255    "-std=c++17",
256    "-pedantic",
257    "-Wall",
258    "-Wextra",
259    "-Werror",
260    "-fno-rtti",
261    "-fno-exceptions",
262    "-Wno-invalid-offsetof",
263
264    "-Wno-gnu-statement-expression",
265    "-Wno-unused-parameter",
266    "-Wno-unused-result",
267  ]
268
269  cflags_c = []
270
271  if (ark_static_standalone_build) {
272    cflags_cc += [ "-Wno-bitwise-instead-of-logical" ]
273  }
274
275  if (!is_mac && use_pbqp) {
276    cflags_cc += [
277      # PBQP regalloc
278      "-mllvm",
279      "-regalloc=pbqp",
280    ]
281  }
282
283  if (is_fastverify) {
284    cflags_cc += [
285      "-O3",
286      "-ggdb3",
287      "-fno-omit-frame-pointer",
288      "-D_GLIBCXX_ASSERTIONS",
289    ]
290    cflags_c += [
291      "-O3",
292      "-ggdb3",
293      "-fno-omit-frame-pointer",
294      "-D_GLIBCXX_ASSERTIONS",
295    ]
296  } else if (is_debug) {
297    cflags_cc += [
298      "-Og",
299      "-ggdb3",
300      "-gdwarf-4",
301    ]
302  }
303
304  if (is_asan) {
305    cflags_cc += [ "-g" ]
306    defines += [ "__SANITIZE_ADDRESS__" ]
307    print("ASAN is enabled")
308  }
309
310  if (enable_relayout_profile) {
311    defines += [ "PANDA_ENABLE_RELAYOUT_PROFILE" ]
312  }
313
314  configs = plugin_ark_configs
315
316  if (ark_static_standalone_build) {
317    configs += [ sdk_libc_secshared_config ]
318  }
319
320  if (current_cpu == "arm") {
321    cflags_cc += [
322      "-march=armv7-a",
323      "-mfloat-abi=${arm_float_abi}",
324      "-marm",
325      "-mfpu=vfp",
326    ]
327
328    if (arm_float_abi == "soft") {
329      defines += [ "PANDA_TARGET_ARM32_ABI_SOFT=1" ]
330    } else if (arm_float_abi == "softfp") {
331      defines += [ "PANDA_TARGET_ARM32_ABI_SOFTFP=1" ]
332    } else if (arm_float_abi == "hard") {
333      defines += [ "PANDA_TARGET_ARM32_ABI_HARD=1" ]
334    }
335
336    defines += [
337      "PANDA_TARGET_32",
338      "PANDA_TARGET_ARM32",
339    ]
340  } else if (current_cpu == "arm64") {
341    defines += [
342      "PANDA_TARGET_ARM64",
343      "PANDA_TARGET_64",
344      "PANDA_ENABLE_GLOBAL_REGISTER_VARIABLES",
345      "PANDA_USE_32_BIT_POINTER",
346    ]
347  } else if (current_cpu == "x86") {
348    defines += [ "PANDA_TARGET_X86" ]
349  } else if (current_cpu == "amd64" || current_cpu == "x64" ||
350             current_cpu == "x86_64") {
351    defines += [
352      "PANDA_TARGET_64",
353      "PANDA_TARGET_AMD64",
354      "PANDA_USE_32_BIT_POINTER",
355    ]
356  }
357}
358
359concat_yamls("concat_plugins_yamls") {
360  output_file = ark_plugin_options_yaml
361  default_file = "$ark_root/templates/plugin_options.yaml"
362  add_yamls = plugin_option_yamls
363}
364
365concat_yamls("concat_entrypoints_yamls") {
366  output_file = "$target_gen_dir/runtime/entrypoints.yaml"
367  default_file = "$ark_root/runtime/entrypoints/entrypoints.yaml"
368  add_yamls = plugin_entrypoints_yamls
369}
370
371concat_yamls("concat_inst_templates_yamls") {
372  output_file = "$target_gen_dir/compiler/generated/inst_templates.yaml"
373  default_file = "$ark_root/compiler/optimizer/ir_builder/inst_templates.yaml"
374  add_yamls = plugin_inst_templates_yamls
375}
376
377merge_yamls("merge_runtime_options_yamls") {
378  output_file = "$target_gen_dir/runtime_options.yaml"
379  add_yamls =
380      [ "$ark_root/runtime/options.yaml" ] + plugin_runtime_options_yamls
381}
382
383merge_yamls("merge_compiler_options_yamls") {
384  output_file = "$target_gen_dir/compiler/generated/compiler_options.yaml"
385  add_yamls =
386      [ "$ark_root/compiler/compiler.yaml" ] + plugin_compiler_options_yamls
387}
388