# 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/static_core/ark_config.gni") if (ark_standalone_build) { import("$build_root/ark.gni") } else { import("//build/ohos.gni") } if (!(ark_standalone_build || (defined(ark_static_standalone_build) && ark_static_standalone_build))) { import("//build/config/components/ets_frontend/ets2abc_config.gni") } # NB! Standard library is built only if the front-end is available. with_stdlib = false foreach(plugin, ark_enabled_plugins) { if (plugin == "ecmascript" || plugin == "ets") { with_stdlib = true } } # Note(ivan-tyulyandin): internal issue #21800 with_sdk = false group("ark_packages") { deps = [ "runtime/libani_helpers:ani_helpers", "runtime/napi/etsnative:etsnative", ] if (ark_static_standalone_build) { deps += [ "$ark_es2panda_root/aot:ets2panda" ] } if (with_stdlib) { deps += [ ":etsstdlib" ] } if (with_sdk) { deps += [ ":etssdk" ] } if (ark_ets_interop_js) { deps += [ "runtime/interop_js:ets_interop_js_napi" ] } if (!(ark_standalone_build || (defined(ohos_indep_compiler_enable) && ohos_indep_compiler_enable) || (defined(ark_static_standalone_build) && ark_static_standalone_build))) { deps += [ ":commonsdk_packages", ":etsstdlib_bootabc", ] } } if (!(ark_standalone_build || (defined(ohos_indep_compiler_enable) && ohos_indep_compiler_enable) || (defined(ark_static_standalone_build) && ark_static_standalone_build))) { generate_static_abc("ets2abc_etsstdlib_bootabc") { arktsconfig = "$ark_root/plugins/ets/stdlib/arktsconfig.json" dst_file = "$target_out_dir/etsstdlib_bootabc.abc" out_puts = [ "$target_out_dir/etsstdlib_bootabc.abc" ] is_boot_abc = "True" device_dst_file = "/system/framework/etsstdlib_bootabc.abc" is_stdlib = "True" } ohos_prebuilt_etc("etsstdlib_bootabc_etc") { source = "$target_out_dir/etsstdlib_bootabc.abc" module_install_dir = "framework" subsystem_name = "arkcompiler" part_name = "runtime_core" deps = [ ":ets2abc_etsstdlib_bootabc" ] } group("etsstdlib_bootabc") { deps = [ ":etsstdlib_bootabc_etc" ] } ohos_prebuilt_etc("ets2abc_commonsdk_api_etc") { source = "$target_out_dir/ets2abc_commonsdk_api.abc" module_install_dir = "framework" subsystem_name = "arkcompiler" part_name = "runtime_core" deps = [ ":ets2abc_commonsdk_api" ] } generate_static_abc("ets2abc_commonsdk_api") { base_url = "./sdk/api" files = [ "./sdk/api/@ohos.buffer.ets", "./sdk/api/@ohos.uri.ets", "./sdk/api/@ohos.url.ets", "./sdk/api/@ohos.util.ArrayList.ets", "./sdk/api/@ohos.util.Deque.ets", "./sdk/api/@ohos.util.HashMap.ets", "./sdk/api/@ohos.util.HashSet.ets", "./sdk/api/@ohos.util.json.ets", "./sdk/api/@ohos.util.LightWeightMap.ets", "./sdk/api/@ohos.util.LightWeightSet.ets", "./sdk/api/@ohos.util.LinkedList.ets", "./sdk/api/@ohos.util.List.ets", "./sdk/api/@ohos.util.PlainArray.ets", "./sdk/api/@ohos.util.Queue.ets", "./sdk/api/@ohos.util.Stack.ets", "./sdk/api/@ohos.util.stream.ets", "./sdk/api/@ohos.util.ets", "./sdk/api/@ohos.util.TreeMap.ets", "./sdk/api/@ohos.util.TreeSet.ets", "./sdk/api/@ohos.xml.ets", ] is_boot_abc = "True" device_dst_file = "/system/framework/ets2abc_commonsdk_api.abc" } ohos_prebuilt_etc("ets2abc_commonsdk_arkts_etc") { source = "$target_out_dir/ets2abc_commonsdk_arkts.abc" module_install_dir = "framework" subsystem_name = "arkcompiler" part_name = "runtime_core" deps = [ ":ets2abc_commonsdk_arkts" ] } generate_static_abc("ets2abc_commonsdk_arkts") { base_url = "./sdk/arkts" files = [ "./sdk/arkts/@arkts.math.Decimal.ets", "./sdk/arkts/@arkts.collections.ets", ] is_boot_abc = "True" device_dst_file = "/system/framework/ets2abc_commonsdk_arkts.abc" } ohos_shared_library("ets_sdk_native") { include_dirs = [ "$ark_root/plugins/ets", "$ark_root/plugins/ets/runtime", "$ark_root/plugins/ets/runtime/ani", "$ark_root/plugins/ets/runtime/napi", "$ark_root/plugins/ets/sdk", "$ark_root/plugins/ets/sdk/native", ] sources = [ "$ark_root/plugins/ets/sdk/native/api/Util.cpp", "$ark_root/plugins/ets/sdk/native/api/ani_stringdecoder.cpp", "$ark_root/plugins/ets/sdk/native/api/ani_textdecoder.cpp", "$ark_root/plugins/ets/sdk/native/api/ani_textencoder.cpp", "$ark_root/plugins/ets/sdk/native/api/ani_textencoder_helper.cpp", "$ark_root/plugins/ets/sdk/native/main.cpp", "$ark_root/plugins/ets/stdlib/native/core/stdlib_ani_helpers.cpp", ] external_deps = [ "bounds_checking_function:libsec_shared", "c_utils:utils", "hilog:libhilog", "openssl:libcrypto_shared", icuuc_dep, ] deps = [ "$ark_root/libpandabase:libarktsbase_static", "$ark_root/plugins/ets/runtime/ani:ani", ] subsystem_name = "arkcompiler" part_name = "runtime_core" output_extension = "so" } group("commonsdk_packages") { deps = [ ":ets2abc_commonsdk_api_etc", ":ets2abc_commonsdk_arkts_etc", ":ets_sdk_native", ] } } group("ark_host_linux_tools_packages") { } group("ark_host_windows_tools_packages") { # Required, but empty: nothing to add currently } group("ark_host_mac_tools_packages") { # Required, but empty: nothing to add currently } config("ark_config") { defines = [ "PANDA_WITH_ETS" ] if (ark_ets_interop_js) { defines += [ "PANDA_ETS_INTEROP_JS" ] } } # TODO(nsizov): Fix and clean after PR480 is merged group("assembler_deps") { deps = [ ":ark_asm_ets_meta_gen_h" ] } config("assembler") { include_dirs = [ "$ark_root/plugins/ets/assembler/extension", "$target_gen_dir", ] } ark_gen_file("ark_asm_ets_meta_gen_h") { template_file = "$ark_root/assembler/templates/meta_gen.cpp.erb" data = [ "$ark_root/plugins/ets/assembler/extension/metadata.yaml" ] api = [ "$ark_root/assembler/asm_metadata.rb" ] output_file = "$target_gen_dir/ets_meta_gen.h" } config("runtime") { include_dirs = [ "$ark_root/plugins/ets/runtime" ] configs = [ "$ark_es2panda_root:libes2panda_public_config", "$ark_root/assembler:arkassembler_public_config", "$ark_root/libpandafile:arkfile_public_config", ] } config("runtime_interpreter_impl") { # Required, but empty: nothing to add currently } config("bytecodeopt") { include_dirs = [ "$ark_root/plugins/ets/bytecode_optimizer/", "$target_gen_dir", ] } ark_isa_gen("isa_gen_ets_bytecodeopt") { template_files = [ "ets_codegen_intrinsics_gen.inc.erb" ] sources = "$ark_root/plugins/ets/bytecode_optimizer/templates/" destination = "$target_gen_dir/" requires = [ "$ark_root/assembler/asm_isapi.rb" ] } if (with_stdlib) { es2panda_gen("etsstdlib") { inputs = [ "stdlib" ] if (ark_static_standalone_build) { outputs = [ "$root_build_dir/plugins/ets/etsstdlib.abc" ] } else { outputs = [ "$target_gen_dir/etsstdlib.abc" ] } abs_ark_root = rebase_path(ark_root) json_array = [ "{", " \"compilerOptions\": {", " \"baseUrl\": \"$abs_ark_root\",", " \"paths\": {", " \"std\": [\"$abs_ark_root" + "/plugins/ets/stdlib/std\"],", " \"escompat\": [\"$abs_ark_root" + "/plugins/ets/stdlib/escompat\"],", " \"api\": [\"$abs_ark_root" + "/plugins/ets/sdk/api\"],", " \"arkts\": [\"$abs_ark_root" + "/plugins/ets/sdk/arkts\"],", " \"import_tests\": [\"$abs_ark_root" + "$ark_es2panda_root/test/parser/ets/import_tests\"]", " }", " }", "}", ] json_relative_path_array = { compilerOptions = { baseUrl = "." paths = { std = [ "../lib/stdlib/std" ] escompat = [ "../lib/stdlib/escompat" ] } } } default_arktsconfig = get_label_info("$ark_es2panda_root/aot:ets2panda(${host_toolchain})", "root_out_dir") if (ark_static_standalone_build) { default_arktsconfig += "/bin" } else { default_arktsconfig += "/arkcompiler/ets_frontend" } write_file("$root_build_dir/tools/es2panda/generated/arktsconfig.json", json_array, "list lines") write_file("$default_arktsconfig/arktsconfig.json", json_array, "list lines") write_file( "$root_build_dir/ohos-sdk/linux/ets/ets1.2/build-tools/ets2panda/bin/arktsconfig.json", json_relative_path_array, "json") write_file( "$root_build_dir/ohos-sdk/windows/ets/ets1.2/build-tools/ets2panda/bin/arktsconfig.json", json_relative_path_array, "json") if (defined(ohos_indep_compiler_enable) && ohos_indep_compiler_enable) { write_file( "$root_build_dir/clang_x64/obj/binarys/arkcompiler/ets_frontend/innerapis/ets2panda/clang_x64/libs/arktsconfig.json", json_array, "list lines") } args = [ "--extension=ets", "--opt-level=2", "--gen-stdlib=true", "--output=" + rebase_path(outputs[0], root_build_dir), ] } if (is_linux) { copy("etsstdlib_copy_linux") { deps = [ ":etsstdlib" ] if (ark_static_standalone_build) { sources = [ "$root_build_dir/plugins/ets/etsstdlib.abc" ] } else { sources = [ "$target_gen_dir/etsstdlib.abc" ] } outputs = [ "$root_build_dir/ohos-sdk/linux/ets/ets1.2/build-tools/ets2panda/lib/etsstdlib.abc" ] } } if (is_win || is_mingw) { copy("etsstdlib_copy_windows") { deps = [ ":etsstdlib" ] if (ark_static_standalone_build) { sources = [ "$root_build_dir/plugins/ets/etsstdlib.abc" ] } else { sources = [ "$target_gen_dir/etsstdlib.abc" ] } outputs = [ "$root_build_dir/ohos-sdk/windows/ets/ets1.2/build-tools/ets2panda/lib/etsstdlib.abc" ] } } action("ets-compile-stdlib-default") { # Running ark_aot compilation for etsstdlib with default options script = "$ark_root/plugins/ets/compiler/tools/paoc_compile_stdlib.sh" outputs = [ "$root_build_dir/plugins/ets/etsstdlib.an" ] deps = [ ":etsstdlib", "$ark_root/compiler/tools/paoc:ark_aot", ] args = [ "--binary-dir=" + rebase_path(root_build_dir), "-compiler-options=--compiler-check-final=true", "-paoc-output=" + rebase_path(outputs[0], root_build_dir), ] } group("ets_func_tests") { deps = [ "tests:ets_func_tests_int_jit_aot" ] } if (ark_standalone_build) { testonly = true group("hybrid_tests") { deps = [ "$ark_root/tools/ark_js_napi_cli:HybridXGCTests", "tests/interop_js/eacoro:eacoro_tests", "tests/interop_js/taskpool:taskpool_tests", "tests/interop_js/xgc:xgc_tests", ] } } } if (with_sdk) { # Note(ivan-tyulyandin): internal issue #21800 assert(false, "Sdk build with gn is not supported!") }