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