• 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_root.gni")
15import("//arkcompiler/runtime_core/static_vm_config.gni")
16
17if (ark_standalone_build) {
18  import("$build_root/ark.gni")
19} else {
20  import("//build/ohos.gni")
21}
22
23ark_subsystem_name = "arkcompiler"
24ark_part_name = "runtime_core"
25
26if (is_standard_system || ark_standalone_build) {
27  import("$ark_root/platforms/ohos/ark_config.gni")
28} else {
29  import("$ark_root/platforms/mobile/ark_config.gni")
30}
31
32declare_args() {
33  ark_enabled_plugins = default_ark_enabled_plugins
34  extras = []
35  if (!defined(is_ohos)) {
36    is_ohos = false
37  }
38  if (!defined(is_standard_system)) {
39    is_standard_system = true
40  }
41
42  if (!defined(is_llvmbackend)) {
43    is_llvmbackend = false
44  }
45
46  if (is_ohos && is_standard_system) {
47    ark_ets_interop_js = true
48  } else {
49    ark_ets_interop_js = false
50  }
51
52  if (ark_static_standalone_build) {
53    abckit_enable = false
54  }
55}
56
57declare_args() {
58  if (!defined(is_llvm_interpreter)) {
59    is_llvm_interpreter = is_llvmbackend
60  }
61  if (!defined(is_llvm_fastpath)) {
62    is_llvm_fastpath = is_llvmbackend && target_cpu == "arm64"
63  }
64  if (!defined(is_llvm_aot)) {
65    is_llvm_aot = is_llvmbackend
66  }
67}
68
69if (current_cpu == "arm") {
70  if (!defined(arm_float_abi) || arm_float_abi == "") {
71    arm_float_abi = "softfp"
72  }
73
74  assert(arm_float_abi == "soft" || arm_float_abi == "softfp" ||
75             arm_float_abi == "hard",
76         "arm_float_abi should be soft, softfp or hard")
77}
78
79ark_root_gen_dir = "$root_gen_dir/ark_sig"
80
81concat_gen_dir =
82    get_label_info("$ark_root:concat_plugins_yamls", "target_gen_dir")
83ark_plugin_options_yaml = "$concat_gen_dir/plugin_options.yaml"
84
85isa_gen_dir = get_label_info("$ark_root/isa:isa_combine", "target_gen_dir")
86ark_isa_yaml = "$isa_gen_dir/isa.yaml"
87
88enable_irtoc = true
89enable_codegen = true
90if (ark_standalone_build || (!ark_static_standalone_build &&
91                             (target_cpu == "x64" || target_cpu == "x86_64"))) {
92  enable_irtoc = false
93  enable_codegen = false
94  is_llvmbackend = false
95  is_llvm_interpreter = false
96  is_llvm_fastpath = false
97  is_llvm_aot = false
98}
99if (target_cpu == "arm") {
100  is_llvmbackend = false
101  is_llvm_interpreter = false
102  is_llvm_fastpath = false
103  is_llvm_aot = false
104}
105
106if (!is_llvmbackend) {
107  assert(!is_llvm_interpreter,
108         "LLVM Irtoc Interpreter requires is_llvmbackend=true")
109  assert(!is_llvm_fastpath,
110         "LLVM Fastpath compilation feature requires is_llvmbackend=true")
111  assert(!is_llvm_aot,
112         "LLVM AOT compilation feature requires is_llvmbackend=true")
113} else {
114  assert(!is_llvm_fastpath || target_cpu == "arm64",
115         "LLVM Fastpath compilation available only for arm64 target")
116}
117
118ark_enable_global_register_variables = true
119enable_bytecode_optimizer = true
120enable_relayout_profile = false
121vixl_with_panda = true
122
123sdk_libc_secshared_dep = ""
124sdk_libc_secshared_ext_dep = ""
125sdk_libc_secshared_config = ""
126
127zlib_public_config = "$ark_third_party_root/zlib:zlib_public_config"
128zlib_dep = "zlib:libz"
129
130icui18n_dep = "icu:shared_icui18n"
131icuuc_dep = "icu:shared_icuuc"
132vixl_dep = "vixl:libvixl"
133
134if (ark_static_standalone_build) {
135  sdk_libc_secshared_dep = "$ark_third_party_root/securec:libc_secshared"
136  sdk_libc_secshared_ext_dep = "$ark_third_party_root/securec:libc_secshared"
137  sdk_libc_secshared_config =
138      "$ark_third_party_root/securec:libsec_public_config"
139  zlib_dep = "$ark_third_party_root/zlib:libz"
140  icui18n_dep = "$ark_third_party_root/icu/icu4c:shared_icui18n"
141  icuuc_dep = "$ark_third_party_root/icu/icu4c:shared_icuuc"
142  vixl_dep = "$ark_third_party_root/vixl:libvixl"
143
144  if (is_mingw || is_mac || is_linux) {
145    sdk_libc_secshared_dep = "$ark_third_party_root/securec:libc_secstatic"
146    sdk_libc_secshared_ext_dep = "$ark_third_party_root/securec:libc_secstatic"
147  }
148} else {
149  # For OpenHarmony build, always link with the static lib:
150  sdk_libc_secshared_dep = "bounds_checking_function:libsec_static"
151  sdk_libc_secshared_ext_dep = "bounds_checking_function:libsec_static"
152  sdk_libc_secshared_config =
153      "$ark_third_party_root/bounds_checking_function:libsec_public_config"
154}
155
156is_mob = !is_ohos && !is_linux && !is_mingw && !is_mac &&
157         (current_cpu != "arm" || is_wearable_product)
158
159if (is_ohos && is_standard_system) {
160  hilog_root = "//base/hiviewdfx/hilog/interfaces/native/innerkits"
161}
162
163## TODO add other arch
164
165# Generate file for a template and YAML data provided.
166#
167# Mandatory arguments:
168# data -- a list of data sources, YAML files
169# template_file -- template full name
170# output_file -- output file full name
171# api -- a list of Ruby scripts that provide data-querying API for templates
172#   (Nth script from 'api' should parse Nth YAML file from 'data')
173#
174# Optional arguments:
175# extra_dependencies -- a list of files that should be considered as dependencies, must be lable
176# requires -- if defined, will require additional Ruby files for template generation, must be list
177
178template("ark_gen_file") {
179  assert(defined(invoker.data), "data is required!")
180  assert(defined(invoker.api), "api is required!")
181  assert(defined(invoker.template_file), "template_file is required!")
182  assert(defined(invoker.output_file), "output_file is required!")
183
184  extra_dependencies = []
185  if (defined(invoker.extra_dependencies)) {
186    extra_dependencies += invoker.extra_dependencies
187  }
188
189  positional_argv = []
190  if (defined(invoker.extra_argv)) {
191    positional_argv += invoker.extra_argv
192  }
193  keyword_argv = [
194    "--template",
195    rebase_path(invoker.template_file, root_build_dir),
196    "--data",
197    string_join(",", rebase_path(invoker.data, root_build_dir)),
198    "--api",
199    string_join(",", rebase_path(invoker.api, root_build_dir)),
200    "--output",
201    rebase_path(invoker.output_file),
202  ]
203  if (defined(invoker.requires)) {
204    keyword_argv += [
205      "--require",
206      string_join(",", rebase_path(invoker.requires, root_build_dir)),
207    ]
208  }
209
210  action("$target_name") {
211    script = "$ark_root/isa/gen.rb"
212
213    # rerun action when data file or template file update
214    inputs = [ invoker.template_file ] + invoker.data
215    outputs = [ invoker.output_file ]
216    args = positional_argv + keyword_argv
217    deps = extra_dependencies
218  }
219}
220
221template("concat_yamls") {
222  assert(defined(invoker.output_file), "output_file is required!")
223  assert(defined(invoker.default_file), "default_file is required!")
224
225  extra_dependencies = []
226  if (defined(invoker.extra_dependencies)) {
227    extra_dependencies += invoker.extra_dependencies
228  }
229
230  outputs = [ invoker.output_file ]
231
232  action("$target_name") {
233    script = "$ark_root/templates/concat_yamls.sh"
234
235    # rerun action when data file or template file update
236    inputs = [ invoker.default_file ]
237
238    args = [
239      rebase_path(invoker.output_file, root_build_dir),
240      rebase_path(invoker.default_file, root_build_dir),
241    ]
242
243    foreach(yaml, invoker.add_yamls) {
244      args += [ rebase_path(yaml, root_build_dir) ]
245    }
246
247    deps = extra_dependencies
248  }
249}
250
251template("merge_yamls") {
252  assert(defined(invoker.output_file), "output_file is required!")
253  assert(defined(invoker.add_yamls), "add_yamls is required!")
254
255  extra_dependencies = []
256  if (defined(invoker.extra_dependencies)) {
257    extra_dependencies += invoker.extra_dependencies
258  }
259
260  outputs = [ invoker.output_file ]
261
262  action("$target_name") {
263    script = "$ark_root/templates/merge.rb"
264
265    data = []
266    foreach(yaml, invoker.add_yamls) {
267      data += [ rebase_path(yaml, root_build_dir) ]
268    }
269    args = [
270      "-d",
271      string_join(",", data),
272      "-o",
273      rebase_path(invoker.output_file, root_build_dir),
274    ]
275
276    deps = extra_dependencies
277  }
278}
279
280# Generate files based on templates and YAML data provided.
281# Adds targets for every template. Also adds a target for the whole function invocation
282# with name ${data_name}_gen_${PROJECT_NAME} for ease of declaring dependencies on generated files.
283#
284# Mandatory arguments:
285# * data -- a list of data sources, YAML files
286# * template_files -- a list of templates to generate files
287# * api -- a list of Ruby scripts that provide data-querying API for templates
288#   (Nth script from 'api' should parse Nth YAML file from 'data')
289#
290# Optional arguments:
291# * sources -- a directory with templates, default is ${PROJECT_SOURCE_DIR}/templates
292# * destination -- a directory for output files, default is ${PANDA_BINARY_ROOT}
293# * extra_dependencies -- a list of files that should be considered as dependencies
294# * requires -- if defined, will require additional Ruby files for template generation, must be list
295# * extra_argv -- a list of positional arguments that could be accessed in '.erb' files via ARGV[]
296template("ark_gen") {
297  assert(defined(invoker.data), "data files were not passed to ark_gen")
298  assert(defined(invoker.api), "ruby api files were not passed to ark_gen")
299  assert(defined(invoker.template_files),
300         "template_files were not passed to ark_gen")
301
302  if (defined(invoker.sources)) {
303    dir = invoker.sources
304  } else {
305    dir = "templates"
306  }
307
308  if (defined(invoker.destination)) {
309    destination = invoker.destination
310  } else {
311    destination = target_out_dir
312  }
313
314  foreach(t, invoker.template_files) {
315    name = string_replace(t, ".erb", "")
316    output = "${destination}/${name}"
317    name = string_replace(name, ".", "_")
318    name = string_replace(name, "/", "_")
319    target = "${target_name}_${name}"
320
321    ark_gen_file(target) {
322      data = invoker.data
323      template_file = "${dir}/${t}"
324      output_file = output
325      api = invoker.api
326      if (defined(invoker.requires)) {
327        requires = invoker.requires
328      }
329      if (defined(invoker.extra_dependencies)) {
330        extra_dependencies = invoker.extra_dependencies
331      }
332      if (defined(invoker.extra_argv)) {
333        extra_argv = invoker.extra_argv
334      }
335    }
336  }
337}
338
339# Calls `ark_gen` for ISA YAML.
340# Adds targets for every template. Also adds a target for the whole function invocation
341# with name isa_gen_${PROJECT_NAME} for ease of declaring dependencies on generated files.
342#
343# Mandatory arguments:
344# * template_files -- a list of templates to generate files
345#
346# Optional arguments:
347# * sources -- a directory with templates, default is ${PROJECT_SOURCE_DIR}/templates
348# * destination -- a directory for output files, default is ${target_out_dir}
349# * requires -- if defined, will require additional Ruby files for template generation, must be list
350# * extra_dependencies -- a list of files that should be considered as dependencies lable, must be list, not used
351template("ark_isa_gen") {
352  isa_api = [ "$ark_root/isa/isapi.rb" ]
353  dependencies = [ "$ark_root/isa:isa_combine" ]
354  if (defined(invoker.extra_dependencies)) {
355    dependencies += invoker.extra_dependencies
356  }
357
358  ark_gen("$target_name") {
359    data = [ ark_isa_yaml ]
360    template_files = invoker.template_files
361    sources = invoker.sources
362    destination = invoker.destination
363    api = isa_api
364    if (defined(invoker.requires)) {
365      requires = invoker.requires
366    }
367    extra_dependencies = dependencies
368  }
369}
370
371# Run ark_asm
372#
373# Arguments:
374# * input_file -- Path to the source assembly code
375# * output_file -- Path to the generated binary code
376template("ark_asm_gen") {
377  action(target_name) {
378    ark_asm_root_out =
379        get_label_info("$ark_root/assembler:arkts_asm(${host_toolchain})",
380                       "root_out_dir")
381    script = ark_asm_root_out + "/$ark_subsystem_name/$ark_part_name/ark_asm"
382
383    inputs = [ invoker.input_file ]
384    outputs = [ invoker.output_file ]
385    args = [
386      rebase_path(invoker.input_file, root_build_dir),
387      rebase_path(invoker.output_file, root_build_dir),
388    ]
389
390    deps = [ "$ark_root/assembler:arkts_asm(${host_toolchain})" ]
391  }
392}
393
394# Run es2panda
395#
396# Arguments:
397# The same you would pass to action except script and deps.
398template("es2panda_gen") {
399  action(target_name) {
400    es2panda_root_out =
401        get_label_info("$ark_es2panda_root/aot:ets2panda(${host_toolchain})",
402                       "root_out_dir")
403
404    inputs = invoker.inputs
405    outputs = invoker.outputs
406
407    if (ark_static_standalone_build) {
408      deps = [ "$ark_es2panda_root/aot:ets2panda" ]
409      es2panda_bin = "/bin/es2panda"
410      script = es2panda_root_out + es2panda_bin
411      args = invoker.args
412    } else {
413      if (ark_standalone_build) {
414        deps = [ "$ark_es2panda_root/aot:ets2panda" ]
415      } else {
416        external_deps = [ "ets_frontend:ets2panda(${host_toolchain})" ]
417      }
418      es2panda_bin =
419          rebase_path("${es2panda_root_out}/arkcompiler/ets_frontend/es2panda")
420      script = "//arkcompiler/ets_runtime/script/run_ark_executable.py"
421      if (defined(invoker.sources)) {
422        sources = invoker.sources
423      }
424      args = [
425        "--script-file",
426        es2panda_bin,
427        "--script-args",
428        string_join(" ", invoker.args),
429        "--env-path",
430        rebase_path("${es2panda_root_out}/arkcompiler/runtime_core/") + ":" +
431            rebase_path("${es2panda_root_out}/arkcompiler/ets_frontend/") +
432            ":" + rebase_path("${es2panda_root_out}/arkcompiler/ets_runtime/") +
433            ":" + rebase_path("${es2panda_root_out}/thirdparty/zlib/") + ":" +
434            rebase_path("${es2panda_root_out}/thirdparty/icu/"),
435        "--expect-output",
436        "0",
437      ]
438    }
439  }
440}
441