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