From de1e3ccd38d449cbecdeb5d17ebe8bd83ca884e6 Mon Sep 17 00:00:00 2001 From: lijunru Date: Wed, 18 Jun 2025 15:11:35 +0800 Subject: [PATCH] Adapt ohos independent build Issue: https://gitee.com/openharmony/arkcompiler_runtime_core/issues/ICFKLT Signed-off-by: lijunru --- bundle.json | 13 +++---- es2panda/BUILD.gn | 82 ++++++++++++++++++++++++++++++--------- es2panda/util/helpers.cpp | 9 ++--- ets2panda/BUILD.gn | 13 ++++++- ets2panda/aot/BUILD.gn | 4 ++ merge_abc/BUILD.gn | 40 +++++++++++++++---- 6 files changed, 120 insertions(+), 41 deletions(-) diff --git a/bundle.json b/bundle.json index aaab390cf3..bf8ba46efb 100644 --- a/bundle.json +++ b/bundle.json @@ -1,5 +1,5 @@ { - "name": "@arkcompiller/ets_frontend", + "name": "@ohos/ets_frontend", "description": "支持应用TS/JS语言代码的编译,行为符合ArkUI框架需要的Strict模式的ES2015标准", "version": "3.1", "license": "Apache License 2.0", @@ -22,12 +22,11 @@ "runtime_core", "zlib", "bounds_checking_function", - "protobuf" + "protobuf", + "icu", + "abseil-cpp" ], - "third_party": [ - "json", - "icu" - ] + "third_party": [] }, "build": { "sub_component": [ @@ -46,4 +45,4 @@ ] } } -} +} \ No newline at end of file diff --git a/es2panda/BUILD.gn b/es2panda/BUILD.gn index d7f663a2bb..56f0a55564 100644 --- a/es2panda/BUILD.gn +++ b/es2panda/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# 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 @@ -293,14 +293,18 @@ config("es2abc_config_src") { config("es2abc_config_common") { configs = [ "$ark_root:ark_config", - "$sdk_libc_secshared_config", "$ark_root/libpandafile:arkfile_public_config", "$ark_root/libpandabase:arkbase_public_config", "$ark_root/assembler:arkassembler_public_config", "$ark_root/abc2program:abc2program_public_config", - "$ark_third_party_root/json:nlohmann_json_config", ":es2abc_config_src", ] + if (defined(is_arkui_x) && is_arkui_x) { + configs += [ + "$sdk_libc_secshared_config", + "$ark_third_party_root/json:nlohmann_json_config", + ] + } if (enable_bytecode_optimizer) { defines = [ "ENABLE_BYTECODE_OPT" ] @@ -343,7 +347,11 @@ action_foreach("gen_keywords_headers") { # generate headers for es2panda compiler isa_gen = "${ark_root}/isa/gen.rb" -isa_gen_data = "$root_gen_dir/isa/isa.yaml" +if (defined(ohos_indep_compiler_enable) && ohos_indep_compiler_enable) { + isa_gen_data = "$root_build_dir/gen/isa/isa.yaml" +} else { + isa_gen_data = "$root_gen_dir/isa/isa.yaml" +} isa_gen_require = "${ark_root}/isa/isapi.rb" action_foreach("gen_isa_headers") { deps = [ "//arkcompiler/runtime_core/isa:isa_combine" ] @@ -361,11 +369,13 @@ action_foreach("gen_isa_headers") { outputs = [ "${generated_header_dir}/{{source_name_part}}" ] script = "scripts/gen_isa.sh" - inputs = [ - "${isa_gen}", - "${isa_gen_data}", - "${isa_gen_require}", - ] + if (defined(ohos_indep_compiler_enable) && !ohos_indep_compiler_enable) { + inputs = [ + "${isa_gen}", + "${isa_gen_data}", + "${isa_gen_require}", + ] + } args = [ "-g", rebase_path("${isa_gen}"), @@ -394,21 +404,25 @@ ohos_static_library("es2panda_lib") { "../merge_abc:panda_assembly_proto_public_config", ] - include_dirs = [ - "${target_out_dir}", - "//third_party/icu/icu4c/source/common", - "//third_party/icu/icu4c/source/i18n", - "//third_party/icu/icu4c/source", - ] + include_dirs = [ "${target_out_dir}" ] deps = [ ":gen_isa_headers", ":gen_keywords_headers", - "$ark_third_party_root/icu/icu4c:static_icuuc", "../merge_abc:panda_assembly_proto_static", ] + external_deps = [ sdk_libc_secshared_dep ] + if (ark_standalone_build || (defined(is_arkui_x) && is_arkui_x)) { + deps += [ "$ark_third_party_root/icu/icu4c:static_icuuc" ] + include_dirs += [ + "//third_party/icu/icu4c/source/common", + "//third_party/icu/icu4c/source/i18n", + "//third_party/icu/icu4c/source", + ] + } else { + external_deps += [ "icu:static_icuuc" ] + } - external_deps = [] if (!is_arkui_x) { external_deps += [ "json:nlohmann_json_static", @@ -451,7 +465,14 @@ ohos_static_library("es2panda_lib") { "-Wno-c++20-designator", "-Wno-implicit-fallthrough", ] - + if (defined(ohos_indep_compiler_enable) && ohos_indep_compiler_enable) { + external_deps += [ "runtime_core:libarkassembler_static" ] + if (enable_hilog) { + external_deps += [ "hilog:libhilog" ] + } + cflags += [ "-I" + rebase_path( + "$root_build_dir/gen/arkcompiler/runtime_core/compiler/generated") ] + } part_name = "ets_frontend" subsystem_name = "arkcompiler" } @@ -481,7 +502,30 @@ ohos_executable("es2panda") { "//arkcompiler/ets_frontend/merge_abc:panda_assembly_proto_static", ] - external_deps = [ "zlib:libz" ] + external_deps = [ + "json:nlohmann_json_static", + "zlib:libz", + sdk_libc_secshared_dep, + ] + + if (defined(ohos_indep_compiler_enable) && ohos_indep_compiler_enable) { + external_deps += [ + "abseil-cpp:absl_base_static", + "icu:shared_icuuc", + "runtime_core:libarkassembler_static", + ] + if (enable_hilog) { + external_deps += [ "hilog:libhilog" ] + } + cflags = [ + "-Wno-constant-conversion", + "-I" + rebase_path( + "$root_build_dir/gen/arkcompiler/runtime_core/bytecode_optimizer"), + "-I" + rebase_path( + "$root_build_dir/gen/arkcompiler/runtime_core/compiler/generated"), + ] + } + if (ark_standalone_build) { external_deps += [ "protobuf:protobuf_lite_static", diff --git a/es2panda/util/helpers.cpp b/es2panda/util/helpers.cpp index 30f0a4bc1c..02a0df64f1 100644 --- a/es2panda/util/helpers.cpp +++ b/es2panda/util/helpers.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * 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 @@ -677,10 +677,9 @@ static std::string GetTempOutputName(const std::string &inputFile) void Helpers::AnalysisProgram(panda::pandasm::Program *prog, const std::string &inputFile) { +#ifdef PANDA_WITH_BYTECODE_OPTIMIZER std::map stat; std::map *statp = &stat; - -#ifdef PANDA_WITH_BYTECODE_OPTIMIZER auto tempOutput = GetTempOutputName(inputFile); bool exists = false; auto mapsp = &panda::bytecodeopt::BytecodeAnalysisResults::GetOrCreateBytecodeMaps(tempOutput, exists); @@ -701,11 +700,11 @@ void Helpers::AnalysisProgram(panda::pandasm::Program *prog, const std::string & void Helpers::OptimizeProgram(panda::pandasm::Program *prog, const std::string &inputFile) { - std::map stat; - std::map *statp = &stat; auto tempOutput = GetTempOutputName(inputFile); #ifdef PANDA_WITH_BYTECODE_OPTIMIZER + std::map stat; + std::map *statp = &stat; const uint32_t COMPONENT_MASK = panda::Logger::Component::ASSEMBLER | panda::Logger::Component::BYTECODE_OPTIMIZER | panda::Logger::Component::COMPILER; diff --git a/ets2panda/BUILD.gn b/ets2panda/BUILD.gn index 7542df6a82..a7d027eff5 100644 --- a/ets2panda/BUILD.gn +++ b/ets2panda/BUILD.gn @@ -1142,8 +1142,6 @@ ohos_source_set("libes2panda_frontend_static") { ":gen_es2panda_lexer_token_inl", ":isa_gen_es2panda_formats_h", ":isa_gen_es2panda_isa_h", - "$ark_third_party_root/icu/icu4c:static_icui18n", - "$ark_third_party_root/icu/icu4c:static_icuuc", ] external_deps = [ "runtime_core:libarktsassembler_package", @@ -1152,6 +1150,17 @@ ohos_source_set("libes2panda_frontend_static") { "runtime_core:libarktsfile_package", sdk_libc_secshared_dep, ] + if (ark_standalone_build || ark_static_standalone_build) { + deps += [ + "$ark_third_party_root/icu/icu4c:static_icui18n", + "$ark_third_party_root/icu/icu4c:static_icuuc", + ] + } else { + external_deps += [ + "icu:static_icui18n", + "icu:static_icuuc", + ] + } part_name = "ets_frontend" subsystem_name = "arkcompiler" } diff --git a/ets2panda/aot/BUILD.gn b/ets2panda/aot/BUILD.gn index 2a76c53b3d..0a8d75cffd 100644 --- a/ets2panda/aot/BUILD.gn +++ b/ets2panda/aot/BUILD.gn @@ -60,6 +60,10 @@ ohos_executable("ets2panda") { sdk_libc_secshared_dep, ] + if (defined(ohos_indep_compiler_enable) && ohos_indep_compiler_enable) { + external_deps += [ "icu:shared_icuuc" ] + } + libs = platform_libs ldflags = platform_ldflags if (is_linux) { diff --git a/merge_abc/BUILD.gn b/merge_abc/BUILD.gn index 54bdb3148c..a20f2b5607 100644 --- a/merge_abc/BUILD.gn +++ b/merge_abc/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2022-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 @@ -52,7 +52,6 @@ config("panda_assembly_proto_public_config") { } assembly_proto_configs = [ - sdk_libc_secshared_config, "$ark_root:ark_config", ":panda_assembly_proto_public_config", "$ark_root/assembler:arkassembler_public_config", @@ -60,6 +59,10 @@ assembly_proto_configs = [ "$ark_root/libpandafile:arkfile_public_config", ] +if (defined(is_arkui_x) && is_arkui_x) { + assembly_proto_configs += [ sdk_libc_secshared_config ] +} + proto_file_defines = [ # add your proto file here "annotation", @@ -91,7 +94,8 @@ foreach(proto_file, proto_file_defines) { protoc_binary_out_path = "${THIRDPARTY_PROTOBUF_SUBSYS_NAME}/${THIRDPARTY_PROTOBUF_PART_NAME}" -if (!ark_standalone_build) { +if (!ark_standalone_build && defined(ohos_indep_compiler_enable) && + !ohos_indep_compiler_enable) { if (default_toolchain == current_toolchain) { #if target build host_out_path = "/" + get_label_info(host_toolchain, "name") @@ -102,6 +106,10 @@ if (!ark_standalone_build) { host_protoc_path = root_out_dir + host_out_path + "/" + protoc_binary_out_path + "/protoc" +} else if (defined(ohos_indep_compiler_enable) && ohos_indep_compiler_enable) { + not_needed([ "protoc_binary_out_path" ]) + host_protoc_path = rebase_path( + "//binarys/third_party/protobuf/innerapis/protoc/clang_x64/libs/protoc") } else { host_protoc_path = get_label_info( @@ -110,7 +118,11 @@ if (!ark_standalone_build) { } action("arkcompiler_generate_proto") { - deps = [ "$ark_third_party_root/protobuf:protoc($host_toolchain)" ] + if (ark_standalone_build) { + deps = [ "$ark_third_party_root/protobuf:protoc($host_toolchain)" ] + } else { + external_deps = [ "protobuf:protoc($host_toolchain)" ] + } args = [] sources = [] outputs = proto_generated_header + proto_generated_source @@ -149,6 +161,7 @@ ohos_source_set("assembly_proto_static") { "runtime_core:libarkassembler_frontend_static", "runtime_core:libarkbase_frontend_static", "runtime_core:libarkfile_frontend_static", + sdk_libc_secshared_dep, ] } else { deps += [ @@ -160,6 +173,16 @@ ohos_source_set("assembly_proto_static") { ] } + if (defined(ohos_indep_compiler_enable) && ohos_indep_compiler_enable) { + external_deps += [ + "abseil-cpp:absl_base_static", + "runtime_core:libarkassembler_static", + ] + if (enable_hilog) { + external_deps += [ "hilog:libhilog" ] + } + } + sources = proto_generated_header + proto_generated_source + protobuf_snapshot_generator_sources public_configs = assembly_proto_configs @@ -196,7 +219,6 @@ ohos_executable("merge_abc") { include_dirs = [ "./src" ] configs = [ - sdk_libc_secshared_config, "$ark_root:ark_config", ":panda_assembly_proto_public_config", "$ark_root/assembler:arkassembler_public_config", @@ -207,12 +229,14 @@ ohos_executable("merge_abc") { deps = [ ":panda_assembly_proto_static", - "$ark_third_party_root/icu/icu4c:static_icuuc", "../es2panda:es2panda_lib", ] - + external_deps = [ + "icu:static_icuuc", + sdk_libc_secshared_dep, + ] if (!is_arkui_x) { - external_deps = [ "runtime_core:libarkziparchive_frontend_static" ] + external_deps += [ "runtime_core:libarkziparchive_frontend_static" ] } else { deps += [ "$ark_root/libziparchive:libarkziparchive_frontend_static" ] } -- Gitee