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