# Copyright (c) 2021-2025 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import("//arkcompiler/runtime_core/arkplatform/hybrid_config.gni") import("//arkcompiler/runtime_core/static_core/ark_root.gni") import("//arkcompiler/runtime_core/static_vm_config.gni") if (ark_standalone_build) { import("$build_root/ark.gni") } else { import("//build/ohos.gni") } ark_subsystem_name = "arkcompiler" ark_part_name = "runtime_core" hiviewdfx_ext_deps = [] enable_hilog = !ark_standalone_build && is_standard_system && current_os == "ohos" && (current_cpu == "arm64" || current_cpu == "arm") if (enable_hilog) { hiviewdfx_ext_deps += [ "hilog:libhilog" ] } if (is_standard_system || ark_standalone_build) { import("$ark_root/platforms/ohos/ark_config.gni") } else { import("$ark_root/platforms/mobile/ark_config.gni") } declare_args() { ark_enabled_plugins = default_ark_enabled_plugins extras = [] if (!defined(is_ohos)) { is_ohos = false } if (!defined(is_standard_system)) { is_standard_system = true } if (!defined(is_llvmbackend)) { is_llvmbackend = true } if ((is_ohos && is_standard_system) || ark_ets_hybrid) { ark_ets_interop_js = true } else { ark_ets_interop_js = false } if (ark_static_standalone_build) { abckit_enable = false } } declare_args() { if (!defined(is_llvm_interpreter)) { is_llvm_interpreter = is_llvmbackend } if (!defined(is_llvm_fastpath)) { is_llvm_fastpath = is_llvmbackend && target_cpu == "arm64" } if (!defined(is_llvm_aot)) { is_llvm_aot = is_llvmbackend } } if (current_cpu == "arm") { if (!defined(arm_float_abi) || arm_float_abi == "") { arm_float_abi = "softfp" } assert(arm_float_abi == "soft" || arm_float_abi == "softfp" || arm_float_abi == "hard", "arm_float_abi should be soft, softfp or hard") } ark_root_gen_dir = "$root_gen_dir/ark_sig" concat_gen_dir = get_label_info("$ark_root:concat_plugins_yamls", "target_gen_dir") ark_plugin_options_yaml = "$concat_gen_dir/plugin_options.yaml" isa_gen_dir = get_label_info("$ark_root/isa:isa_combine", "target_gen_dir") ark_isa_yaml = "$isa_gen_dir/isa.yaml" # chipset will set runtime_core_enable_codegen as false, not need codegen for it declare_args() { runtime_core_enable_codegen = true } enable_irtoc = true enable_codegen = true if (!runtime_core_enable_codegen) { # Disable irtoc and codegen for: # - !runtime_core_enable_codegen in chipset enable_irtoc = false enable_codegen = false } if (ark_standalone_build || ((!ark_static_standalone_build && (target_cpu == "x64" || target_cpu == "x86_64")) || (current_os == "win" || current_os == "mingw" || current_os == "winuwp"))) { enable_irtoc = false enable_codegen = false is_llvmbackend = false is_llvm_interpreter = false is_llvm_fastpath = false is_llvm_aot = false } if (target_cpu == "arm") { is_llvmbackend = false is_llvm_interpreter = false is_llvm_fastpath = false is_llvm_aot = false } if (!is_llvmbackend) { assert(!is_llvm_interpreter, "LLVM Irtoc Interpreter requires is_llvmbackend=true") assert(!is_llvm_fastpath, "LLVM Fastpath compilation feature requires is_llvmbackend=true") assert(!is_llvm_aot, "LLVM AOT compilation feature requires is_llvmbackend=true") } else { assert(!is_llvm_fastpath || target_cpu == "arm64", "LLVM Fastpath compilation available only for arm64 target") } ark_enable_global_register_variables = true enable_bytecode_optimizer = true vixl_with_panda = true sdk_libc_secshared_dep = "" sdk_libc_secshared_ext_dep = "" sdk_libc_secshared_config = "" zlib_public_config = "$ark_third_party_root/zlib:zlib_public_config" zlib_dep = "zlib:libz" icui18n_dep = "icu:shared_icui18n" icuuc_dep = "icu:shared_icuuc" vixl_dep = "vixl:libvixl" if (ark_static_standalone_build) { sdk_libc_secshared_dep = "$ark_third_party_root/securec:libc_secshared" sdk_libc_secshared_ext_dep = "$ark_third_party_root/securec:libc_secshared" sdk_libc_secshared_config = "$ark_third_party_root/securec:libsec_public_config" zlib_dep = "$ark_third_party_root/zlib:libz" icui18n_dep = "$ark_third_party_root/icu/icu4c:shared_icui18n" icuuc_dep = "$ark_third_party_root/icu/icu4c:shared_icuuc" vixl_dep = "$ark_third_party_root/vixl:libvixl" if (is_mingw || is_mac || is_linux) { sdk_libc_secshared_dep = "$ark_third_party_root/securec:libc_secstatic" sdk_libc_secshared_ext_dep = "$ark_third_party_root/securec:libc_secstatic" } } else { # For OpenHarmony build, always link with the static lib: sdk_libc_secshared_dep = "bounds_checking_function:libsec_static" sdk_libc_secshared_ext_dep = "bounds_checking_function:libsec_static" sdk_libc_secshared_config = "$ark_third_party_root/bounds_checking_function:libsec_public_config" } is_mob = !is_ohos && !is_linux && !is_mingw && !is_mac && (current_cpu != "arm" || is_wearable_product) if (is_ohos && is_standard_system) { hilog_root = "//base/hiviewdfx/hilog/interfaces/native/innerkits" } ## TODO add other arch # Generate file for a template and YAML data provided. # # Mandatory arguments: # data -- a list of data sources, YAML files # template_file -- template full name # output_file -- output file full name # api -- a list of Ruby scripts that provide data-querying API for templates # (Nth script from 'api' should parse Nth YAML file from 'data') # # Optional arguments: # extra_dependencies -- a list of files that should be considered as dependencies, must be lable # requires -- if defined, will require additional Ruby files for template generation, must be list template("ark_gen_file") { assert(defined(invoker.data), "data is required!") assert(defined(invoker.api), "api is required!") assert(defined(invoker.template_file), "template_file is required!") assert(defined(invoker.output_file), "output_file is required!") extra_dependencies = [] if (defined(invoker.extra_dependencies)) { extra_dependencies += invoker.extra_dependencies } positional_argv = [] if (defined(invoker.extra_argv)) { positional_argv += invoker.extra_argv } keyword_argv = [ "--template", rebase_path(invoker.template_file, root_build_dir), "--data", string_join(",", rebase_path(invoker.data, root_build_dir)), "--api", string_join(",", rebase_path(invoker.api, root_build_dir)), "--output", rebase_path(invoker.output_file), ] if (defined(invoker.requires)) { keyword_argv += [ "--require", string_join(",", rebase_path(invoker.requires, root_build_dir)), ] } action("$target_name") { script = "$ark_root/isa/gen.rb" # rerun action when data file or template file update if (defined(ohos_indep_compiler_enable) && !ohos_indep_compiler_enable) { inputs = [ invoker.template_file ] + invoker.data } outputs = [ invoker.output_file ] args = positional_argv + keyword_argv deps = extra_dependencies } } template("concat_yamls") { assert(defined(invoker.output_file), "output_file is required!") assert(defined(invoker.default_file), "default_file is required!") extra_dependencies = [] if (defined(invoker.extra_dependencies)) { extra_dependencies += invoker.extra_dependencies } outputs = [ invoker.output_file ] action("$target_name") { script = "$ark_root/templates/concat_yamls.sh" # rerun action when data file or template file update inputs = [ invoker.default_file ] args = [ rebase_path(invoker.output_file, root_build_dir), rebase_path(invoker.default_file, root_build_dir), ] foreach(yaml, invoker.add_yamls) { args += [ rebase_path(yaml, root_build_dir) ] } deps = extra_dependencies } } template("merge_yamls") { assert(defined(invoker.output_file), "output_file is required!") assert(defined(invoker.add_yamls), "add_yamls is required!") extra_dependencies = [] if (defined(invoker.extra_dependencies)) { extra_dependencies += invoker.extra_dependencies } outputs = [ invoker.output_file ] action("$target_name") { script = "$ark_root/templates/merge.rb" data = [] foreach(yaml, invoker.add_yamls) { data += [ rebase_path(yaml, root_build_dir) ] } args = [ "-d", string_join(",", data), "-o", rebase_path(invoker.output_file, root_build_dir), ] deps = extra_dependencies } } # Generate files based on templates and YAML data provided. # Adds targets for every template. Also adds a target for the whole function invocation # with name ${data_name}_gen_${PROJECT_NAME} for ease of declaring dependencies on generated files. # # Mandatory arguments: # * data -- a list of data sources, YAML files # * template_files -- a list of templates to generate files # * api -- a list of Ruby scripts that provide data-querying API for templates # (Nth script from 'api' should parse Nth YAML file from 'data') # # Optional arguments: # * sources -- a directory with templates, default is ${PROJECT_SOURCE_DIR}/templates # * destination -- a directory for output files, default is ${PANDA_BINARY_ROOT} # * extra_dependencies -- a list of files that should be considered as dependencies # * requires -- if defined, will require additional Ruby files for template generation, must be list # * extra_argv -- a list of positional arguments that could be accessed in '.erb' files via ARGV[] template("ark_gen") { assert(defined(invoker.data), "data files were not passed to ark_gen") assert(defined(invoker.api), "ruby api files were not passed to ark_gen") assert(defined(invoker.template_files), "template_files were not passed to ark_gen") if (defined(invoker.sources)) { dir = invoker.sources } else { dir = "templates" } if (defined(invoker.destination)) { destination = invoker.destination } else { destination = target_out_dir } foreach(t, invoker.template_files) { name = string_replace(t, ".erb", "") output = "${destination}/${name}" name = string_replace(name, ".", "_") name = string_replace(name, "/", "_") target = "${target_name}_${name}" ark_gen_file(target) { data = invoker.data template_file = "${dir}/${t}" output_file = output api = invoker.api if (defined(invoker.requires)) { requires = invoker.requires } if (defined(invoker.extra_dependencies)) { extra_dependencies = invoker.extra_dependencies } if (defined(invoker.extra_argv)) { extra_argv = invoker.extra_argv } } } } # Calls `ark_gen` for ISA YAML. # Adds targets for every template. Also adds a target for the whole function invocation # with name isa_gen_${PROJECT_NAME} for ease of declaring dependencies on generated files. # # Mandatory arguments: # * template_files -- a list of templates to generate files # # Optional arguments: # * sources -- a directory with templates, default is ${PROJECT_SOURCE_DIR}/templates # * destination -- a directory for output files, default is ${target_out_dir} # * requires -- if defined, will require additional Ruby files for template generation, must be list # * extra_dependencies -- a list of files that should be considered as dependencies lable, must be list, not used template("ark_isa_gen") { isa_api = [ "$ark_root/isa/isapi.rb" ] dependencies = [ "$ark_root/isa:isa_combine" ] if (defined(invoker.extra_dependencies)) { dependencies += invoker.extra_dependencies } ark_gen("$target_name") { data = [ ark_isa_yaml ] template_files = invoker.template_files sources = invoker.sources destination = invoker.destination api = isa_api if (defined(invoker.requires)) { requires = invoker.requires } extra_dependencies = dependencies } } # Run ark_asm # # Arguments: # * input_file -- Path to the source assembly code # * output_file -- Path to the generated binary code template("ark_asm_gen") { action(target_name) { ark_asm_root_out = get_label_info("$ark_root/assembler:arkts_asm(${host_toolchain})", "root_out_dir") script = ark_asm_root_out + "/$ark_subsystem_name/$ark_part_name/ark_asm" inputs = [ invoker.input_file ] outputs = [ invoker.output_file ] args = [ rebase_path(invoker.input_file, root_build_dir), rebase_path(invoker.output_file, root_build_dir), ] deps = [ "$ark_root/assembler:arkts_asm(${host_toolchain})" ] } } # Run es2panda # # Arguments: # The same you would pass to action except script and deps. template("es2panda_gen") { action(target_name) { es2panda_root_out = get_label_info("$ark_es2panda_root/aot:ets2panda(${host_toolchain})", "root_out_dir") inputs = invoker.inputs outputs = invoker.outputs if (ark_static_standalone_build) { deps = [ "$ark_es2panda_root/aot:ets2panda" ] es2panda_bin = "/bin/es2panda" script = es2panda_root_out + es2panda_bin args = invoker.args } else { if (ark_standalone_build) { deps = [ "$ark_es2panda_root/aot:ets2panda" ] } else { external_deps = [ "ets_frontend:ets2panda(${host_toolchain})" ] } es2panda_bin = rebase_path("${es2panda_root_out}/arkcompiler/ets_frontend/es2panda") script = "//arkcompiler/ets_runtime/script/run_ark_executable.py" if (defined(invoker.sources)) { sources = invoker.sources } args = [ "--script-file", es2panda_bin, "--script-args", string_join(" ", invoker.args), "--env-path", rebase_path("${es2panda_root_out}/arkcompiler/runtime_core/") + ":" + rebase_path("${es2panda_root_out}/arkcompiler/ets_frontend/") + ":" + rebase_path("${es2panda_root_out}/arkcompiler/ets_runtime/") + ":" + rebase_path("${es2panda_root_out}/thirdparty/zlib/") + ":" + rebase_path("${es2panda_root_out}/thirdparty/icu/"), "--expect-output", "0", ] } } }