From 7dd22a770f294f3779c921615508ea835b51e02e Mon Sep 17 00:00:00 2001 From: Medvedev Aleksandr Date: Fri, 22 Aug 2025 12:08:10 +0300 Subject: [PATCH 1/6] LibArkTs configuration --- .gitlab-ci.yml | 1 + .gn | 14 ++ BUILD.gn | 23 ++ gn/command/npm_util.py | 1 - gn/config/BUILD.gn | 33 +++ gn/config/BUILDCONFIG.gn | 59 +++++ gn/import/npm.gni | 77 +++++++ gn/script/npm.py | 93 ++++++++ gn/toolchain/BUILD.gn | 85 +++++++ incremental/BUILD.gn | 34 +-- interop/BUILD.gn | 55 +++-- ui2abc/BUILD.gn | 89 ++++--- ui2abc/gn/sdk_config.json | 10 + ui2abc/libarkts/.gitlab-ci.yml | 15 ++ ui2abc/libarkts/BUILD.gn | 358 +++++++++++++++-------------- ui2abc/libarkts/gn/command/copy.py | 14 +- 16 files changed, 683 insertions(+), 278 deletions(-) create mode 100644 .gn create mode 100644 BUILD.gn create mode 100644 gn/config/BUILD.gn create mode 100644 gn/config/BUILDCONFIG.gn create mode 100644 gn/import/npm.gni create mode 100755 gn/script/npm.py create mode 100644 gn/toolchain/BUILD.gn diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a55842637..27f4cbc86 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -16,6 +16,7 @@ image: "${KOALA_CI_IMAGE}" stages: - install-deps - build + - build-gn - build-ets - build-har - test diff --git a/.gn b/.gn new file mode 100644 index 000000000..19001187c --- /dev/null +++ b/.gn @@ -0,0 +1,14 @@ +# Copyright (c) 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. + +buildconfig = "//gn/config/BUILDCONFIG.gn" \ No newline at end of file diff --git a/BUILD.gn b/BUILD.gn new file mode 100644 index 000000000..3524c553d --- /dev/null +++ b/BUILD.gn @@ -0,0 +1,23 @@ +# Copyright (c) 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("${koala_mr.imports_prefix}/npm.gni") + +group("koala_mr_new_all") { + deps = [ + "${koala_mr.libarkts_path}:es2panda", + "${koala_mr.libarkts_path}:libarkts", + "${koala_mr.libarkts_path}:libarkts_sdk_copy", + "${koala_mr.incremental_path}:incremental_abc" + ] +} \ No newline at end of file diff --git a/gn/command/npm_util.py b/gn/command/npm_util.py index e32b92f35..2dec5865c 100755 --- a/gn/command/npm_util.py +++ b/gn/command/npm_util.py @@ -59,7 +59,6 @@ def run(args, dir = None): if os.environ.get("KOALA_LOG_STDOUT"): subprocess.run(["npm"] + args, env=os.environ, text=True, check=True, stderr=subprocess.STDOUT) return - result = subprocess.run(["npm"] + args, capture_output=True, env=os.environ, text=True) with open(koala_log, "a+") as f: f.write(f"npm args: {args}; project: {project_path}:\n" + result.stdout) diff --git a/gn/config/BUILD.gn b/gn/config/BUILD.gn new file mode 100644 index 000000000..b798729a8 --- /dev/null +++ b/gn/config/BUILD.gn @@ -0,0 +1,33 @@ +# Copyright (c) 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. + +config("compiler_defaults") { + if (current_os == "linux") { + cflags = [ + "-fPIC", + "-pthread", + ] + cflags_cc = [ + "-std=c++17", + ] + } +} + +config("executable_ldconfig") { + if (!is_mac) { + ldflags = [ + "-Wl,-rpath=\$ORIGIN/", + "-Wl,-rpath-link=", + ] + } +} \ No newline at end of file diff --git a/gn/config/BUILDCONFIG.gn b/gn/config/BUILDCONFIG.gn new file mode 100644 index 000000000..ea6cca402 --- /dev/null +++ b/gn/config/BUILDCONFIG.gn @@ -0,0 +1,59 @@ +# Copyright (c) 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. + +if (target_os == "") { + target_os = host_os +} +if (target_cpu == "") { + target_cpu = host_cpu +} +if (current_cpu == "") { + current_cpu = target_cpu +} +if (current_os == "") { + current_os = target_os +} + +_shared_binary_target_configs = [ "//gn/config:compiler_defaults" ] +set_defaults("executable") { + configs = _shared_binary_target_configs + configs += [ "//gn/config:executable_ldconfig" ] +} +set_defaults("static_library") { + configs = _shared_binary_target_configs +} +set_defaults("shared_library") { + configs = _shared_binary_target_configs +} +set_defaults("source_set") { + configs = _shared_binary_target_configs +} +set_default_toolchain("//gn/toolchain:gcc") + +koala_mr = { + root_path = "//." + scripts_path = "$root_path/gn/script" + imports_prefix = "$root_path/gn/import" + ui2abc_path = "$root_path/ui2abc" + libarkts_path = "$ui2abc_path/libarkts" + incremental_path = "$root_path/incremental" + panda_sdk_path = "$incremental_path/tools/panda/node_modules/@panda/sdk" + es2panda_path = "$panda_sdk_path/ohos_arm64/include/tools/es2panda" + interop_path = "$root_path/interop" + is_rri = true +} + +host_toolchain = "//gn/toolchain:gcc" + +is_linux = host_os == "linux" && current_os == "linux" && target_os == "linux" +is_mac = host_os == "mac" && current_os == "mac" && target_os == "mac" \ No newline at end of file diff --git a/gn/import/npm.gni b/gn/import/npm.gni new file mode 100644 index 000000000..85333a8fa --- /dev/null +++ b/gn/import/npm.gni @@ -0,0 +1,77 @@ +# Copyright (c) 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. + +template("npm_cmd") { + if (!defined(invoker.panda_sdk_path)) { + invoker.panda_sdk_path = rebase_path(koala_mr.panda_sdk_path) + } + action("$target_name") { + script = "${koala_mr.scripts_path}/npm.py" + if (!defined(invoker.outputs)) { + outputs = [ + "$target_out_dir/$target_name" + ] + } else { + outputs = invoker.outputs + } + if (defined(invoker.sources)) { + sources = invoker.sources + } + if (defined(invoker.deps)) { + deps = invoker.deps + } + if (defined(invoker.inputs)) { + inputs = invoker.inputs + } + if (defined(invoker.external_deps)) { + external_deps = invoker.external_deps + } + + args = [ + "--project-path", invoker.project_path + ] + if (defined(invoker.panda_sdk_path)) { + args += [ "--panda-sdk-path", invoker.panda_sdk_path ] + } + if (defined(invoker.node_path)) { + args += [ "--node-path", invoker.node_path ] + } + if (defined(invoker.target_out_path)) { + args += [ "--target-out-path", invoker.target_out_path ] + } + if (defined(invoker.built_file_path)) { + args += [ "--built-file-path", invoker.built_file_path ] + } + if (defined(invoker.install) && invoker.install) { + args += [ "--install" ] + } + if (defined(invoker.install_path)) { + args += [ "--install-path", invoker.install_path ] + } + if (defined(invoker.run_tasks)) { + args += [ "--run-tasks" ] + invoker.run_tasks + } + } +} + +template("npm_install") { + forward_variables_from(invoker, "*") + npm_cmd(target_name) { + if (!defined(sources)) { + sources = [ + "$project_path/package.json" + ] + } + install = true + } +} \ No newline at end of file diff --git a/gn/script/npm.py b/gn/script/npm.py new file mode 100755 index 000000000..b24c0b178 --- /dev/null +++ b/gn/script/npm.py @@ -0,0 +1,93 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (c) 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 argparse +import shutil +import subprocess +import os +import sys + +NPM_REPO = "https://repo.huaweicloud.com/repository/npm/" + +parser = argparse.ArgumentParser(description="npm command parser") +parser.add_argument("--project-path", help="project directory in koala repo") +parser.add_argument("--node-path", help="nodejs path") +parser.add_argument("--arklink-path", help="ark-link path") +parser.add_argument("--es2panda-path", help="es2panda path") +parser.add_argument("--stdlib-path", help="stdlib path") +parser.add_argument("--target-out-path", help="out directory of built target") +parser.add_argument("--built-file-path", help="result of building") +parser.add_argument("--install", action="store_true", help="request npm install") +parser.add_argument("--install-path", help="path to install in") +parser.add_argument("--run-tasks", nargs='+', help="npm run tasks") +parser.add_argument("--panda-sdk-path", help="panda sdk path") + +args = parser.parse_args() + +project_path = args.project_path +koala_log = os.path.join(project_path, "koala_build.log") + +node_path = args.node_path or (os.path.dirname(shutil.which("node")) if shutil.which("node") else None) +if node_path: + os.environ["PATH"] = f"{node_path}:{os.environ.get('PATH', '')}" +else: + print("Error: Node.js is not found in the system PATH, and --node-path is not provided") + sys.exit(1) + +if args.es2panda_path: + os.environ["ES2PANDA_PATH"] = args.es2panda_path +if args.arklink_path: + os.environ["ARKLINK_PATH"] = args.arklink_path +if args.stdlib_path: + os.environ["ETS_STDLIB_PATH"] = args.stdlib_path +if args.panda_sdk_path: + os.environ["PANDA_SDK_PATH"] = args.panda_sdk_path +# os.environ["PANDA_SDK_PATH"] = os.path.join(os.path.dirname(os.path.realpath(__file__)), "../../ui2abc/build/sdk") + +def run(args, dir = None): + os.chdir(dir or project_path) + + if os.environ.get("KOALA_LOG_STDOUT"): + subprocess.run(["npm"] + args, env=os.environ, text=True, check=True, stderr=subprocess.STDOUT) + return + result = subprocess.run(["npm"] + args, capture_output=True, env=os.environ, text=True) + with open(koala_log, "a+") as f: + f.write(f"npm args: {args}; project: {project_path}:\n" + result.stdout) + if result.returncode != 0: + f.write(f"npm args: {args}; project: {project_path}:\n" + result.stderr) + print(open(koala_log, "r").read()) + raise Exception("npm failed") + f.close() + +def install(dir = None): + run(["install", "--registry", NPM_REPO, "--verbose"], dir or project_path) + +def copy_target(): + if not os.path.exists(args.built_file_path): + print(f"Error: Built file not found at {args.built_file_path}") + sys.exit(1) + shutil.copy(args.built_file_path, args.target_out_path) + +def main(): + if args.install: + install(args.install_path) + if args.run_tasks: + for task in args.run_tasks: + run(["run", task]) + if args.target_out_path and args.built_file_path: + copy_target() + +if __name__ == '__main__': + main() diff --git a/gn/toolchain/BUILD.gn b/gn/toolchain/BUILD.gn new file mode 100644 index 000000000..fdb5ac105 --- /dev/null +++ b/gn/toolchain/BUILD.gn @@ -0,0 +1,85 @@ +# Copyright (c) 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. + +toolchain("gcc") { + tool("cc") { + depfile = "{{output}}.d" + command = "gcc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}" + depsformat = "gcc" + description = "CC {{output}}" + outputs = + [ "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o" ] + } + tool("cxx") { + depfile = "{{output}}.d" + command = "g++ -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}" + depsformat = "gcc" + description = "CXX {{output}}" + outputs = + [ "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o" ] + } + tool("alink") { + command = "ar rcs {{output}} {{inputs}}" + description = "AR {{target_output_name}}{{output_extension}}" + outputs = + [ "{{target_out_dir}}/{{target_output_name}}{{output_extension}}" ] + default_output_extension = ".a" + output_prefix = "lib" + } + tool("solink") { + soname = "{{target_output_name}}{{output_extension}}" # e.g. "libfoo.so". + sofile = "{{output_dir}}/$soname" + rspfile = soname + ".rsp" + if (is_mac) { + os_specific_option = "-install_name @executable_path/$sofile" + rspfile_content = "{{inputs}} {{solibs}} {{libs}}" + } else { + os_specific_option = "-Wl,-soname=$soname" + rspfile_content = "-Wl,--whole-archive {{inputs}} {{solibs}} -Wl,--no-whole-archive {{libs}}" + } + command = "g++ -shared {{ldflags}} -o $sofile $os_specific_option @$rspfile" + description = "SOLINK $soname" + # Use this for {{output_extension}} expansions unless a target manually + # overrides it (in which case {{output_extension}} will be what the target + # specifies). + default_output_extension = ".so" + # Use this for {{output_dir}} expansions unless a target manually overrides + # it (in which case {{output_dir}} will be what the target specifies). + default_output_dir = "{{root_out_dir}}" + outputs = [ sofile ] + link_output = sofile + depend_output = sofile + output_prefix = "lib" + } + tool("link") { + outfile = "{{target_output_name}}{{output_extension}}" + rspfile = "$outfile.rsp" + if (is_mac) { + command = "g++ {{ldflags}} -o $outfile @$rspfile {{solibs}} {{libs}}" + } else { + command = "g++ {{ldflags}} -o $outfile -Wl,--start-group @$rspfile {{solibs}} -Wl,--end-group {{libs}}" + } + description = "LINK $outfile" + default_output_dir = "{{root_out_dir}}" + rspfile_content = "{{inputs}}" + outputs = [ outfile ] + } + tool("stamp") { + command = "touch {{output}}" + description = "STAMP {{output}}" + } + tool("copy") { + command = "cp -af {{source}} {{output}}" + description = "COPY {{source}} {{output}}" + } +} \ No newline at end of file diff --git a/incremental/BUILD.gn b/incremental/BUILD.gn index 02b5b1aac..1668b3ba3 100644 --- a/incremental/BUILD.gn +++ b/incremental/BUILD.gn @@ -11,16 +11,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import("//build/config/components/ets_frontend/ets2abc_config.gni") -import("//build/ohos.gni") -import("//foundation/arkui/ace_engine/ace_config.gni") -import("//foundation/arkui/ace_engine/frameworks/bridge/arkts_frontend/koala_mirror/gn/npm_util.gni") +if (!koala_mr.is_rri) { + import("//build/config/components/ets_frontend/ets2abc_config.gni") + import("//build/ohos.gni") + import("//foundation/arkui/ace_engine/ace_config.gni") +} import("./incremental_components.gni") - -koala_root = ".." - -node_version = "v16.20.2" -host_arch = "${host_os}-${host_cpu}" +import("${koala_mr.imports_prefix}/npm.gni") if (current_toolchain == host_toolchain) { npm_install("incremental_install") { @@ -40,20 +37,23 @@ npm_cmd("incremental_build") { inputs = incremental_files deps = [ - "$koala_root/ui2abc:ui2abc" + "${koala_mr.ui2abc_path}:ui2abc" ] - external_deps = [ - ets2abc_build_deps, - static_linker_build_deps, - "ets_frontend:libes2panda_public(${host_toolchain})" - ] + if (!koala_mr.is_rri) { + external_deps = [ + ets2abc_build_deps, + static_linker_build_deps, + "ets_frontend:libes2panda_public(${host_toolchain})" + ] + } + built_file_path = rebase_path("./runtime/build/incremental.abc") target_out_path = rebase_path("$target_out_dir/incremental.abc") } group("incremental_abc") { deps = [ - ":incremental_build" + ":incremental_build" ] -} \ No newline at end of file +} diff --git a/interop/BUILD.gn b/interop/BUILD.gn index f6c9d97d8..a6ddf953f 100644 --- a/interop/BUILD.gn +++ b/interop/BUILD.gn @@ -10,17 +10,12 @@ # 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("//build/config/components/ets_frontend/ets2abc_config.gni") -import("//build/ohos.gni") -import("//foundation/arkui/ace_engine/ace_config.gni") -import("//foundation/arkui/ace_engine/frameworks/bridge/arkts_frontend/koala_mirror/gn/npm_util.gni") - -koala_root = ".." -interop_root = "" - -node_version = "v16.20.2" -host_arch = "${host_os}-${host_cpu}" +if (!koala_mr.is_rri) { + import("//build/config/components/ets_frontend/ets2abc_config.gni") + import("//build/ohos.gni") + import("//foundation/arkui/ace_engine/ace_config.gni") +} +import("${koala_mr.imports_prefix}/npm.gni") if (current_toolchain == host_toolchain) { npm_install("interop_install") { @@ -31,25 +26,27 @@ if (current_toolchain == host_toolchain) { } } -npm_cmd("interop.abc") { - outputs = [ - "$target_out_dir/interop.abc" - ] - project_path = rebase_path(".") - run_tasks = [ "build" ] +if (!koala_mr.is_rri) { + npm_cmd("interop.abc") { + outputs = [ + "$target_out_dir/interop.abc" + ] + project_path = rebase_path(".") + run_tasks = [ "build" ] - deps = [ - "$koala_root/ui2abc:ui2abc" - ] + deps = [ + "${koala_mr.ui2abc_path}:ui2abc" + ] - external_deps = [ - ets2abc_build_deps, - static_linker_build_deps - ] -} + external_deps = [ + ets2abc_build_deps, + static_linker_build_deps + ] + } -group("interop") { - deps = [ - "$interop_root:interop.abc" - ] + group("interop") { + deps = [ + "${koala_mr.interop_path}:interop.abc" + ] + } } \ No newline at end of file diff --git a/ui2abc/BUILD.gn b/ui2abc/BUILD.gn index 90f7f90f5..face10c6f 100644 --- a/ui2abc/BUILD.gn +++ b/ui2abc/BUILD.gn @@ -11,17 +11,50 @@ # See the License for the specific language governing permissions and # limitations under the License. -import("//build/ohos.gni") -import("//build/config/components/ets_frontend/ets2abc_config.gni") -import("//foundation/arkui/ace_engine/frameworks/bridge/arkts_frontend/koala_mirror/gn/npm_util.gni") +if (!koala_mr.is_rri) { + import("//build/ohos.gni") + import("//build/config/components/ets_frontend/ets2abc_config.gni") +} +import("${koala_mr.imports_prefix}/npm.gni") +if (current_toolchain == host_toolchain) { + npm_install("ui2abc_install") { + deps = [ + "${koala_mr.ui2abc_path}/libarkts:libarkts_install" + ] + project_path = rebase_path(".") + } +} -koala_root = ".." +if (!koala_mr.is_rri) { + action("ui2abc_panda_sdk") { + script = "gn/command/gen_sdk.py" -node_version = "v16.20.2" -host_arch = "${host_os}-${host_cpu}" + outputs = [ + "$target_out_dir/panda-sdk" + ] -libarkts_root = "./libarkts" -build_root = "//build" + external_deps = [ ets2abc_build_deps ] + external_deps += [ static_linker_build_deps ] + external_deps += [ "ets_frontend:libes2panda_public(${host_toolchain})" ] + + args = [ + "--config", rebase_path("gn/sdk_config.json"), + "--src", rebase_path("//"), + "--dist", rebase_path("./build/sdk"), + "--out-root", rebase_path(root_out_dir), + "--current-os", current_os, + "--current-cpu", current_cpu + ] + } +} + +group("ui2abc_install_all") { + deps = [ + ":ui2abc_install(${host_toolchain})", + "${koala_mr.incremental_path}:incremental_install(${host_toolchain})", + "${koala_mr.interop_path}:interop_install(${host_toolchain})" + ] +} npm_cmd("fast_arktsc_build") { outputs = [ @@ -34,15 +67,6 @@ npm_cmd("fast_arktsc_build") { run_tasks = [ "compile" ] } -if (current_toolchain == host_toolchain) { - npm_install("ui2abc_install") { - outputs = [ - "$target_out_dir/ui2abc_install" - ] - project_path = rebase_path(".") - } -} - npm_cmd("ui2abc_build") { outputs = [ "$target_out_dir/MemoTransformer.js" @@ -50,42 +74,13 @@ npm_cmd("ui2abc_build") { deps = [ ":fast_arktsc_build", - "$libarkts_root:es2panda" + "${koala_mr.libarkts_path}:es2panda" ] project_path = rebase_path(".") run_tasks = [ "build:plugins" ] } -action("ui2abc_panda_sdk") { - script = "gn/command/gen_sdk.py" - - outputs = [ - "$target_out_dir/panda-sdk" - ] - - external_deps = [ets2abc_build_deps] - external_deps += [static_linker_build_deps] - external_deps += [ "ets_frontend:libes2panda_public(${host_toolchain})" ] - - args = [ - "--config", rebase_path("gn/sdk_config.json"), - "--src", rebase_path("//"), - "--dist", rebase_path("./build/sdk"), - "--out-root", rebase_path(root_out_dir), - "--current-os", current_os, - "--current-cpu", current_cpu - ] -} - -group("ui2abc_install_all") { - deps = [ - ":ui2abc_install(${host_toolchain})", - "$koala_root/incremental:incremental_install(${host_toolchain})", - "$koala_root/interop:interop_install(${host_toolchain})" - ] -} - group("ui2abc") { deps = [ ":ui2abc_build" diff --git a/ui2abc/gn/sdk_config.json b/ui2abc/gn/sdk_config.json index 8630b8b93..4ea6f1bca 100644 --- a/ui2abc/gn/sdk_config.json +++ b/ui2abc/gn/sdk_config.json @@ -7,6 +7,12 @@ "$.exe": "", "$.lib": ".so" }, + "ohos": + { + "$host_tools": "linux_host_tools", + "$.exe": "", + "$.lib": ".so" + }, "mingw": { "$host_tools": "windows_host_tools", @@ -47,6 +53,10 @@ "source": "$out_root/$compiler_type/gen/arkcompiler/ets_frontend/ets2panda/generated/es2panda_lib", "destination": "$host_tools/include/tools/es2panda/generated/es2panda_lib" }, + { + "source": "arkcompiler/ets_frontend/ets2panda/public/es2panda_lib.h", + "destination": "ohos_arm64/include/tools/es2panda/public/es2panda_lib.h" + }, { "source": "$out_root/$compiler_type/gen/arkcompiler/ets_frontend/ets2panda/generated/es2panda_lib", "destination": "ohos_arm64/include/tools/es2panda/generated/es2panda_lib" diff --git a/ui2abc/libarkts/.gitlab-ci.yml b/ui2abc/libarkts/.gitlab-ci.yml index f001ba76a..feb1c9038 100644 --- a/ui2abc/libarkts/.gitlab-ci.yml +++ b/ui2abc/libarkts/.gitlab-ci.yml @@ -40,6 +40,21 @@ regenerate plugin-api: - install node modules (interop) - install panda sdk +build gn-libarkts: + interruptible: true + stage: build-gn + extends: .linux-vm-shell-task + before_script: + - !reference [ .setup, script ] + script: + - gn gen out/Dir + - ninja -C out/Dir + needs: + - install node modules (ui2abc) + - install node modules (arkoala-arkts) + - install node modules (incremental) + - install node modules (interop) + build plugin-api: interruptible: true stage: build diff --git a/ui2abc/libarkts/BUILD.gn b/ui2abc/libarkts/BUILD.gn index 8caa9faf9..593f0c315 100644 --- a/ui2abc/libarkts/BUILD.gn +++ b/ui2abc/libarkts/BUILD.gn @@ -11,48 +11,90 @@ # See the License for the specific language governing permissions and # limitations under the License. -import("//build/ohos.gni") -import("//foundation/arkui/ace_engine/frameworks/bridge/arkts_frontend/koala_mirror/gn/npm_util.gni") +if (!koala_mr.is_rri) { + import("//build/ohos.gni") +} +import("${koala_mr.imports_prefix}/npm.gni") + +ws_node_modules_dir = koala_mr.ui2abc_path + "/node_modules" + +if (koala_mr.is_rri) { + npm_cmd("panda_sdk_reinstall") { + project_path = rebase_path(".") + run_tasks = [ + "panda:sdk:reinstall" + ] + deps = [ + ":libarkts_install" + ] + } +} else { + + # Use from OHOS-SDK build (//build/ohos/sdk/ohos_sdk_description_std.json) + + ohos_copy("libarkts-sdk") { + deps = [ ":libarkts_sdk_copy" ] + sources = [ rebase_path("$target_gen_dir") ] + outputs = [ target_out_dir + "/$target_name" ] + module_source_dir = target_out_dir + "/$target_name" + module_install_name = "" + subsystem_name = "arkui" + part_name = "ace_engine" + } -koala_root = "../.." -libarkts_root = "." -ui2abc_root = ".." -interop_root = "$koala_root/interop" +} -node_modules_dir = "../node_modules" -node_version = "v16.20.2" -host_arch = "${host_os}-${host_cpu}" +if (current_toolchain == host_toolchain) { + npm_cmd("regenerate") { + assert(current_toolchain == host_toolchain, "must be executed with host_toolchain") + if (koala_mr.is_rri) { + deps = [ + ":libarkts_install", + ":panda_sdk_reinstall" + ] + } else { + deps = [ + "${koala_mr.ui2abc_path}:ui2abc_install_all(${host_toolchain})", + "${koala_mr.ui2abc_path}:ui2abc_panda_sdk" + ] + } + project_path = rebase_path(".") + run_tasks = [ + "regenerate" + ] + } + + npm_install("libarkts_install") { + project_path = rebase_path(".") + } +} shared_library("es2panda_lib") { - external_deps = [ "ets_frontend:ets2panda" ] + if (!koala_mr.is_rri) { + external_deps = [ "ets_frontend:ets2panda" ] + } sources = [ - "$libarkts_root/native/src/common.cc", - "$libarkts_root/native/src/bridges.cc", - "$libarkts_root/native/src/generated/bridges.cc", + "${koala_mr.libarkts_path}/native/src/common.cc", + "${koala_mr.libarkts_path}/native/src/bridges.cc", + "${koala_mr.libarkts_path}/native/src/generated/bridges.cc", - "$interop_root/src/cpp/napi/convertors-napi.cc", - "$interop_root/src/cpp/callback-resource.cc", - "$interop_root/src/cpp/interop-logging.cc", - "$interop_root/src/cpp/common-interop.cc" + "${koala_mr.interop_path}/src/cpp/napi/convertors-napi.cc", + "${koala_mr.interop_path}/src/cpp/callback-resource.cc", + "${koala_mr.interop_path}/src/cpp/interop-logging.cc", + "${koala_mr.interop_path}/src/cpp/common-interop.cc" ] include_dirs = [ - "$ui2abc_root/build/sdk/linux_host_tools/include/tools/es2panda/public", - "$ui2abc_root/build/sdk/linux_host_tools/include/tools/es2panda", - - "$libarkts_root/native/src", - - "$koala_root/interop/src/cpp", - "$koala_root/interop/src/cpp/napi", - "$koala_root/interop/src/cpp/types", - - "$node_modules_dir/node-api-headers/include", - "$node_modules_dir/node-addon-api", - - # "//arkcompiler/ets_frontend/ets2panda/public/", - # rebase_path("$root_gen_dir/arkcompiler/ets_frontend/ets2panda/"), + "${koala_mr.es2panda_path}/public", + "${koala_mr.es2panda_path}", + "${koala_mr.libarkts_path}/native/src", + "${koala_mr.root_path}/interop/src/cpp", + "${koala_mr.root_path}/interop/src/cpp/napi", + "${koala_mr.root_path}/interop/src/cpp/types", + "$ws_node_modules_dir/node-api-headers/include", + "$ws_node_modules_dir/node-addon-api" ] defines = [ @@ -63,28 +105,30 @@ shared_library("es2panda_lib") { ] deps = [ - "$ui2abc_root:ui2abc_install(${host_toolchain})", - ":regenerate(${host_toolchain})" + ":regenerate($host_toolchain)" ] - configs -= [ "//build/config/compiler:compiler" ] + if (!koala_mr.is_rri) { + deps += [ "${koala_mr.ui2abc_path}:ui2abc_install($host_toolchain)" ] + configs -= [ "//build/config/compiler:compiler" ] + } if (is_mac) { cflags_cc = [ - "-std=c++17", - "-Wall", - "-Werror", - "-Wno-unused-variable", - "-fPIC", + "-std=c++17", + "-Wall", + "-Werror", + "-Wno-unused-variable", + "-fPIC", ] ldflags = [ - "-fPIC", - "-Wl,-undefined,dynamic_lookup", - "-fuse-ld=lld", - "-Wl,--icf=all", - "-Wl,--color-diagnostics", - "-m64" + "-fPIC", + "-Wl,-undefined,dynamic_lookup", + "-fuse-ld=lld", + "-Wl,--icf=all", + "-Wl,--color-diagnostics", + "-m64" ] defines += [ "KOALA_MACOS" ] output_extension = "node" @@ -92,169 +136,128 @@ shared_library("es2panda_lib") { if (is_linux) { cflags_cc = [ - "-std=c++17", - "-Wall", - "-Werror", - "-Wno-unused-command-line-argument", - "-Wno-unused-variable", - "-fPIC", + "-std=c++17", + "-Wall", + "-Werror", + "-Wno-unused-command-line-argument", + "-Wno-unused-variable", + "-fPIC", ] ldflags = [ - "-Wl,--allow-shlib-undefined", - "-Wl,--fatal-warnings", - "-Wl,--build-id=md5", - "-fPIC", - "-Wl,-z,noexecstack", - "-Wl,-z,now", - "-Wl,-z,relro", + "-Wl,--allow-shlib-undefined", + "-Wl,--fatal-warnings", + "-Wl,--build-id=md5", + "-fPIC", + "-Wl,-z,noexecstack", + "-Wl,-z,now", + "-Wl,-z,relro", - # "-Wl,-z,defs", # must no use this option - "-Wl,--as-needed", - "-fuse-ld=lld", - "-Wl,--icf=all", - "-Wl,--color-diagnostics", - "-m64", + # "-Wl,-z,defs", # must no use this option + "-Wl,--as-needed", + "-fuse-ld=lld", + "-Wl,--icf=all", + "-Wl,--color-diagnostics", + "-m64", ] defines += [ "KOALA_LINUX" ] output_extension = "node" } else if (current_os == "mingw") { cflags_cc = [ - "-std=c++17", - "-Wall", - "-Werror", - "-Wno-unused-variable", - "-Wno-unused-command-line-argument", - "-fPIC", - "-Wno-error=deprecated-copy", - "-enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang", - "-ftrivial-auto-var-init=zero", - "-fcolor-diagnostics", - "-fmerge-all-constants", - "-Xclang", - "-mllvm", - "-Xclang", - "-instcombine-lower-dbg-declare=0", - "-no-canonical-prefixes", - "-fuse-ld=lld", - "-fno-stack-protector", - "-fno-strict-aliasing", - "-Wno-builtin-macro-redefined", - "-fms-extensions", - "-static", - "-rtlib=compiler-rt", - "-stdlib=libc++", - "-lunwind", - "-lpthread", - "-Qunused-arguments", - "-target", - "x86_64-pc-windows-gnu", - "-D__CUSTOM_SECURITY_LIBRARY", + "-std=c++17", + "-Wall", + "-Werror", + "-Wno-unused-variable", + "-Wno-unused-command-line-argument", + "-fPIC", + "-Wno-error=deprecated-copy", + "-enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang", + "-ftrivial-auto-var-init=zero", + "-fcolor-diagnostics", + "-fmerge-all-constants", + "-Xclang", + "-mllvm", + "-Xclang", + "-instcombine-lower-dbg-declare=0", + "-no-canonical-prefixes", + "-fuse-ld=lld", + "-fno-stack-protector", + "-fno-strict-aliasing", + "-Wno-builtin-macro-redefined", + "-fms-extensions", + "-static", + "-rtlib=compiler-rt", + "-stdlib=libc++", + "-lunwind", + "-lpthread", + "-Qunused-arguments", + "-target", + "x86_64-pc-windows-gnu", + "-D__CUSTOM_SECURITY_LIBRARY", ] ldflags = [ - "-Wl,--fatal-warnings", - "-fPIC", - "-Wl,--as-needed", - "-fuse-ld=lld", - "-Wl,--icf=all", - "-m64", - "-static", - "-rtlib=compiler-rt", - "-stdlib=libc++", - "-std=c++17", - "-lunwind", - "-lpthread", - "-Qunused-arguments", - "-target", - "x86_64-pc-windows-gnu", + "-Wl,--fatal-warnings", + "-fPIC", + "-Wl,--as-needed", + "-fuse-ld=lld", + "-Wl,--icf=all", + "-m64", + "-static", + "-rtlib=compiler-rt", + "-stdlib=libc++", + "-std=c++17", + "-lunwind", + "-lpthread", + "-Qunused-arguments", + "-target", + "x86_64-pc-windows-gnu", ] output_extension = "dll" defines += [ "KOALA_WINDOWS" ] - sources += [ "../../interop/src/cpp/napi/win-dynamic-node.cc" ] + sources += [ "${koala_mr.interop_path}/src/cpp/napi/win-dynamic-node.cc" ] } } action("es2panda_lib_copy") { script = "gn/command/copy.py" - outputs = [ - "$target_out_dir/es2panda.node" - ] - if (build_ohos_sdk) { + if (defined(build_ohos_sdk) && build_ohos_sdk) { deps = [ ":es2panda_lib" ] + from_path = root_out_dir } else { deps = [ ":es2panda_lib(${host_toolchain})" ] + if (host_toolchain != current_toolchain) { + toolchain_parts = string_split(host_toolchain, ":") + from_path = "$root_out_dir/${toolchain_parts[1]}" + } else { + from_path = root_out_dir + } } + + inputs = [ + "$from_path/libes2panda_lib.node" + ] + outputs = [ + "$target_out_dir/es2panda.node" + ] args = [ - "--from-path", rebase_path(root_out_dir), + "--from-path", rebase_path(from_path), "--to-path", rebase_path("."), "--current-os", current_os, "--current-cpu", current_cpu ] } -if (current_toolchain == host_toolchain) { - npm_cmd("regenerate") { - assert(current_toolchain == host_toolchain, "must be executed with host_toolchain") - outputs = [ - "$target_out_dir/regenerate" - ] - deps = [ - "$ui2abc_root:ui2abc_install_all(${host_toolchain})", - "$ui2abc_root:ui2abc_panda_sdk" - ] - project_path = rebase_path(".") - run_tasks = [ "regenerate" ] - } -} - -if (current_toolchain == host_toolchain) { - npm_install("libarkts_install") { - outputs = [ - "$target_out_dir/libarkts_install" - ] - deps = [ - "$ui2abc_root:ui2abc_install(${host_toolchain})" - ] - project_path = rebase_path(".") - } -} - -action("libarkts_sdk_copy") { - script = "../gn/command/copy_libs.py" - args = [ - "--source_path", rebase_path(get_path_info(".", "abspath")), - "--output_path", rebase_path("$target_gen_dir"), - "--root_out_dir", rebase_path(root_out_dir), - ] - outputs = [ "$target_gen_dir" ] - deps = [ - "$ui2abc_root:ui2abc" - ] -} - -# Use from OHOS-SDK build (//build/ohos/sdk/ohos_sdk_description_std.json) - -ohos_copy("libarkts-sdk") { - deps = [ - ":libarkts_sdk_copy" - ] - sources = [ rebase_path("$target_gen_dir") ] - outputs = [ target_out_dir + "/$target_name" ] - module_source_dir = target_out_dir + "/$target_name" - module_install_name = "" - subsystem_name = "arkui" - part_name = "ace_engine" -} - # for //developtools/ace_ets2bundle npm_cmd("libarkts_compile") { deps = [ + "${koala_mr.interop_path}:interop_install(${host_toolchain})", + "${koala_mr.incremental_path}:incremental_install(${host_toolchain})", ":regenerate(${host_toolchain})" ] outputs = [ @@ -273,7 +276,20 @@ group("es2panda") { group("libarkts") { deps = [ - ":es2panda_lib", - ":libarkts_compile(${host_toolchain})" + ":es2panda_lib", + ":libarkts_compile(${host_toolchain})" + ] +} + +action("libarkts_sdk_copy") { + script = "../gn/command/copy_libs.py" + args = [ + "--source_path", rebase_path(get_path_info(".", "abspath")), + "--output_path", rebase_path("$target_gen_dir"), + "--root_out_dir", rebase_path(root_out_dir), + ] + outputs = [ "$target_gen_dir" ] + deps = [ + "${koala_mr.ui2abc_path}:ui2abc" ] } \ No newline at end of file diff --git a/ui2abc/libarkts/gn/command/copy.py b/ui2abc/libarkts/gn/command/copy.py index 9b360ab83..c42c37f14 100755 --- a/ui2abc/libarkts/gn/command/copy.py +++ b/ui2abc/libarkts/gn/command/copy.py @@ -19,11 +19,6 @@ import shutil import subprocess import sys -def get_compiler_name(os, cpu): - if (os == 'mingw' and cpu == 'x86_64'): - return 'mingw_x86_64' - return 'clang_x64' - def library_ext(os, cpu): if (os == 'mingw' and cpu == 'x86_64'): return 'dll' @@ -53,19 +48,12 @@ def run_cmd(cmd, execution_path=None): def copy_output(options): - - compiler = get_compiler_name(options.current_os, options.current_cpu) library_extention = library_ext(options.current_os, options.current_cpu) from_path = options.from_path to_path = options.to_path - head_dir, tail_dir = os.path.split(from_path) - if (tail_dir == compiler): - from_path = head_dir - - - copy_files(os.path.join(from_path, f'{compiler}/libes2panda_lib.{library_extention}'), + copy_files(os.path.join(from_path, f'libes2panda_lib.{library_extention}'), os.path.join(to_path, 'build/native/build/es2panda.node'), True) -- Gitee From 1e78fcde2374e6c7d03055f97b2d4b992b53f11f Mon Sep 17 00:00:00 2001 From: Medvedev Aleksandr Date: Tue, 26 Aug 2025 11:02:40 +0300 Subject: [PATCH 2/6] Incremental and interop were added --- BUILD.gn | 2 ++ ui2abc/memo-plugin/BUILD.gn | 36 +++++++++++++++++------------------- ui2abc/ui-plugins/BUILD.gn | 35 +++++++++++++++++------------------ 3 files changed, 36 insertions(+), 37 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 3524c553d..e2756492b 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -18,6 +18,8 @@ group("koala_mr_new_all") { "${koala_mr.libarkts_path}:es2panda", "${koala_mr.libarkts_path}:libarkts", "${koala_mr.libarkts_path}:libarkts_sdk_copy", + "${koala_mr.ui2abc_path}/memo-plugin:gen_memo_plugin", + "${koala_mr.ui2abc_path}/ui-plugins:gen_ui_plugin", "${koala_mr.incremental_path}:incremental_abc" ] } \ No newline at end of file diff --git a/ui2abc/memo-plugin/BUILD.gn b/ui2abc/memo-plugin/BUILD.gn index 629577e13..b59f04018 100644 --- a/ui2abc/memo-plugin/BUILD.gn +++ b/ui2abc/memo-plugin/BUILD.gn @@ -11,14 +11,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -import("//build/ohos.gni") -import("//foundation/arkui/ace_engine/frameworks/bridge/arkts_frontend/koala_mirror/gn/npm_util.gni") - -node_version = "v16.20.2" -host_arch = "${host_os}-${host_cpu}" - -ui2abc_root = ".." -libarkts_root = "${ui2abc_root}/libarkts" +if (!koala_mr.is_rri) { + import("//build/ohos.gni") +} +import("${koala_mr.imports_prefix}/npm.gni") npm_cmd("memo_plugin_compile") { outputs = [ @@ -28,7 +24,7 @@ npm_cmd("memo_plugin_compile") { run_tasks = [ "compile" ] deps = [ - "${libarkts_root}:libarkts" + "${koala_mr.libarkts_path}:libarkts" ] } @@ -45,14 +41,16 @@ action("gen_memo_plugin") { ] } -# Use from OHOS-SDK build (//build/ohos/sdk/ohos_sdk_description_std.json) - -ohos_copy("memo-plugin-sdk") { - deps = [ ":gen_memo_plugin" ] - sources = [ rebase_path("$target_gen_dir") ] - outputs = [ target_out_dir + "/$target_name" ] - module_source_dir = target_out_dir + "/$target_name" - module_install_name = "" - subsystem_name = "arkui" - part_name = "ace_engine" +if (!koala_mr.is_rri) { + # Use from OHOS-SDK build (//build/ohos/sdk/ohos_sdk_description_std.json) + + ohos_copy("memo-plugin-sdk") { + deps = [ ":gen_memo_plugin" ] + sources = [ rebase_path("$target_gen_dir") ] + outputs = [ target_out_dir + "/$target_name" ] + module_source_dir = target_out_dir + "/$target_name" + module_install_name = "" + subsystem_name = "arkui" + part_name = "ace_engine" + } } \ No newline at end of file diff --git a/ui2abc/ui-plugins/BUILD.gn b/ui2abc/ui-plugins/BUILD.gn index 719595008..e31c23d68 100644 --- a/ui2abc/ui-plugins/BUILD.gn +++ b/ui2abc/ui-plugins/BUILD.gn @@ -11,14 +11,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -import("//build/ohos.gni") -import("//foundation/arkui/ace_engine/frameworks/bridge/arkts_frontend/koala_mirror/gn/npm_util.gni") - -node_version = "v16.20.2" -host_arch = "${host_os}-${host_cpu}" - -ui2abc_root = ".." -libarkts_root = "${ui2abc_root}/libarkts" +if (!koala_mr.is_rri) { + import("//build/ohos.gni") +} +import("${koala_mr.imports_prefix}/npm.gni") npm_cmd("ui_plugin_compile") { outputs = [ @@ -28,7 +24,7 @@ npm_cmd("ui_plugin_compile") { run_tasks = [ "compile" ] deps = [ - "${libarkts_root}:libarkts" + "${koala_mr.libarkts_path}:libarkts" ] } @@ -45,14 +41,17 @@ action("gen_ui_plugin") { ] } -# Use from OHOS-SDK build (//build/ohos/sdk/ohos_sdk_description_std.json) -ohos_copy("ui-plugin-sdk") { - deps = [":gen_ui_plugin" ] - sources = [ rebase_path("$target_gen_dir") ] - outputs = [ target_out_dir + "/$target_name" ] - module_source_dir = target_out_dir + "/$target_name" - module_install_name = "" - subsystem_name = "arkui" - part_name = "ace_engine" +if (!koala_mr.is_rri) { + # Use from OHOS-SDK build (//build/ohos/sdk/ohos_sdk_description_std.json) + + ohos_copy("ui-plugin-sdk") { + deps = [":gen_ui_plugin" ] + sources = [ rebase_path("$target_gen_dir") ] + outputs = [ target_out_dir + "/$target_name" ] + module_source_dir = target_out_dir + "/$target_name" + module_install_name = "" + subsystem_name = "arkui" + part_name = "ace_engine" + } } \ No newline at end of file -- Gitee From c72a8993f4bf2bb1edea5a2224263bad99922727 Mon Sep 17 00:00:00 2001 From: Medvedev Aleksandr Date: Tue, 26 Aug 2025 11:22:54 +0300 Subject: [PATCH 3/6] Lib copy workaround for ohos building --- ui2abc/libarkts/BUILD.gn | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ui2abc/libarkts/BUILD.gn b/ui2abc/libarkts/BUILD.gn index 593f0c315..de5340c77 100644 --- a/ui2abc/libarkts/BUILD.gn +++ b/ui2abc/libarkts/BUILD.gn @@ -238,9 +238,9 @@ action("es2panda_lib_copy") { } } - inputs = [ - "$from_path/libes2panda_lib.node" - ] + # inputs = [ + # "$from_path/libes2panda_lib.node" + # ] outputs = [ "$target_out_dir/es2panda.node" ] -- Gitee From a8a135974712c7c1d76734944b5b5ff219e58c76 Mon Sep 17 00:00:00 2001 From: Medvedev Aleksandr Date: Tue, 26 Aug 2025 17:35:59 +0300 Subject: [PATCH 4/6] OHOS integration --- gn/import/npm.gni | 9 +++++++-- gn/script/npm.py | 6 +++--- incremental/BUILD.gn | 4 ++++ interop/BUILD.gn | 5 +++++ ui2abc/BUILD.gn | 5 ++++- ui2abc/libarkts/BUILD.gn | 4 ++++ ui2abc/memo-plugin/BUILD.gn | 5 ++++- ui2abc/ui-plugins/BUILD.gn | 4 ++++ 8 files changed, 35 insertions(+), 7 deletions(-) diff --git a/gn/import/npm.gni b/gn/import/npm.gni index 85333a8fa..0a60c64e9 100644 --- a/gn/import/npm.gni +++ b/gn/import/npm.gni @@ -11,6 +11,11 @@ # See the License for the specific language governing permissions and # limitations under the License. +if (!defined(koala_mr)) { + # OHOS build tree workaround + import("../../../koala_integration.gni") +} + template("npm_cmd") { if (!defined(invoker.panda_sdk_path)) { invoker.panda_sdk_path = rebase_path(koala_mr.panda_sdk_path) @@ -43,8 +48,8 @@ template("npm_cmd") { if (defined(invoker.panda_sdk_path)) { args += [ "--panda-sdk-path", invoker.panda_sdk_path ] } - if (defined(invoker.node_path)) { - args += [ "--node-path", invoker.node_path ] + if (defined(invoker.koala_node_path)) { + args += [ "--node-path", invoker.koala_node_path ] } if (defined(invoker.target_out_path)) { args += [ "--target-out-path", invoker.target_out_path ] diff --git a/gn/script/npm.py b/gn/script/npm.py index b24c0b178..7bcc018a3 100755 --- a/gn/script/npm.py +++ b/gn/script/npm.py @@ -39,9 +39,9 @@ args = parser.parse_args() project_path = args.project_path koala_log = os.path.join(project_path, "koala_build.log") -node_path = args.node_path or (os.path.dirname(shutil.which("node")) if shutil.which("node") else None) -if node_path: - os.environ["PATH"] = f"{node_path}:{os.environ.get('PATH', '')}" +koala_node_path = args.node_path or (os.path.dirname(shutil.which("node")) if shutil.which("node") else None) +if koala_node_path: + os.environ["PATH"] = f"{koala_node_path}:{os.environ.get('PATH', '')}" else: print("Error: Node.js is not found in the system PATH, and --node-path is not provided") sys.exit(1) diff --git a/incremental/BUILD.gn b/incremental/BUILD.gn index 1668b3ba3..00ef1511b 100644 --- a/incremental/BUILD.gn +++ b/incremental/BUILD.gn @@ -11,6 +11,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +if (!defined(koala_mr)) { + # OHOS build tree workaround + import("../../koala_integration.gni") +} if (!koala_mr.is_rri) { import("//build/config/components/ets_frontend/ets2abc_config.gni") import("//build/ohos.gni") diff --git a/interop/BUILD.gn b/interop/BUILD.gn index a6ddf953f..a292282e6 100644 --- a/interop/BUILD.gn +++ b/interop/BUILD.gn @@ -10,6 +10,11 @@ # 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. + +if (!defined(koala_mr)) { + # OHOS build tree workaround + import("../../koala_integration.gni") +} if (!koala_mr.is_rri) { import("//build/config/components/ets_frontend/ets2abc_config.gni") import("//build/ohos.gni") diff --git a/ui2abc/BUILD.gn b/ui2abc/BUILD.gn index face10c6f..391040411 100644 --- a/ui2abc/BUILD.gn +++ b/ui2abc/BUILD.gn @@ -10,7 +10,10 @@ # 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. - +if (!defined(koala_mr)) { + # OHOS build tree workaround + import("../../koala_integration.gni") +} if (!koala_mr.is_rri) { import("//build/ohos.gni") import("//build/config/components/ets_frontend/ets2abc_config.gni") diff --git a/ui2abc/libarkts/BUILD.gn b/ui2abc/libarkts/BUILD.gn index de5340c77..089570169 100644 --- a/ui2abc/libarkts/BUILD.gn +++ b/ui2abc/libarkts/BUILD.gn @@ -11,6 +11,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +if (!defined(koala_mr)) { + # OHOS build tree workaround + import("../../../koala_integration.gni") +} if (!koala_mr.is_rri) { import("//build/ohos.gni") } diff --git a/ui2abc/memo-plugin/BUILD.gn b/ui2abc/memo-plugin/BUILD.gn index b59f04018..39ea51fff 100644 --- a/ui2abc/memo-plugin/BUILD.gn +++ b/ui2abc/memo-plugin/BUILD.gn @@ -10,7 +10,10 @@ # 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. - +if (!defined(koala_mr)) { + # OHOS build tree workaround + import("../../../koala_integration.gni") +} if (!koala_mr.is_rri) { import("//build/ohos.gni") } diff --git a/ui2abc/ui-plugins/BUILD.gn b/ui2abc/ui-plugins/BUILD.gn index e31c23d68..221a55349 100644 --- a/ui2abc/ui-plugins/BUILD.gn +++ b/ui2abc/ui-plugins/BUILD.gn @@ -11,6 +11,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +if (!defined(koala_mr)) { + # OHOS build tree workaround + import("../../../koala_integration.gni") +} if (!koala_mr.is_rri) { import("//build/ohos.gni") } -- Gitee From 3be188207f6a85911836b86f2ca327d0b4ada585 Mon Sep 17 00:00:00 2001 From: Medvedev Aleksandr Date: Thu, 28 Aug 2025 11:20:19 +0300 Subject: [PATCH 5/6] Interop was added --- BUILD.gn | 5 +++-- interop/BUILD.gn | 30 +++++++++++++++--------------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index e2756492b..97a44fa53 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -13,13 +13,14 @@ import("${koala_mr.imports_prefix}/npm.gni") -group("koala_mr_new_all") { +group("koala_mr_all") { deps = [ "${koala_mr.libarkts_path}:es2panda", "${koala_mr.libarkts_path}:libarkts", "${koala_mr.libarkts_path}:libarkts_sdk_copy", "${koala_mr.ui2abc_path}/memo-plugin:gen_memo_plugin", "${koala_mr.ui2abc_path}/ui-plugins:gen_ui_plugin", - "${koala_mr.incremental_path}:incremental_abc" + "${koala_mr.incremental_path}:incremental_abc", + "${koala_mr.interop_path}:interop", ] } \ No newline at end of file diff --git a/interop/BUILD.gn b/interop/BUILD.gn index a292282e6..c9d60bc58 100644 --- a/interop/BUILD.gn +++ b/interop/BUILD.gn @@ -31,27 +31,27 @@ if (current_toolchain == host_toolchain) { } } -if (!koala_mr.is_rri) { - npm_cmd("interop.abc") { - outputs = [ - "$target_out_dir/interop.abc" - ] - project_path = rebase_path(".") - run_tasks = [ "build" ] +npm_cmd("interop.abc") { + outputs = [ + "$target_out_dir/interop.abc" + ] + project_path = rebase_path(".") + run_tasks = [ "build" ] - deps = [ - "${koala_mr.ui2abc_path}:ui2abc" - ] + deps = [ + "${koala_mr.ui2abc_path}:ui2abc" + ] + if (!koala_mr.is_rri) { external_deps = [ ets2abc_build_deps, static_linker_build_deps ] } +} - group("interop") { - deps = [ - "${koala_mr.interop_path}:interop.abc" - ] - } +group("interop") { + deps = [ + "${koala_mr.interop_path}:interop.abc" + ] } \ No newline at end of file -- Gitee From 72fe78a05fc42474a394b6afc7219b3915d4a5da Mon Sep 17 00:00:00 2001 From: Medvedev Aleksandr Date: Wed, 3 Sep 2025 15:30:19 +0300 Subject: [PATCH 6/6] Switched to clang toolchain --- gn/config/BUILDCONFIG.gn | 4 ++-- gn/toolchain/BUILD.gn | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/gn/config/BUILDCONFIG.gn b/gn/config/BUILDCONFIG.gn index ea6cca402..4497405f2 100644 --- a/gn/config/BUILDCONFIG.gn +++ b/gn/config/BUILDCONFIG.gn @@ -38,7 +38,7 @@ set_defaults("shared_library") { set_defaults("source_set") { configs = _shared_binary_target_configs } -set_default_toolchain("//gn/toolchain:gcc") +set_default_toolchain("//gn/toolchain:clang") koala_mr = { root_path = "//." @@ -53,7 +53,7 @@ koala_mr = { is_rri = true } -host_toolchain = "//gn/toolchain:gcc" +host_toolchain = "//gn/toolchain:clang" is_linux = host_os == "linux" && current_os == "linux" && target_os == "linux" is_mac = host_os == "mac" && current_os == "mac" && target_os == "mac" \ No newline at end of file diff --git a/gn/toolchain/BUILD.gn b/gn/toolchain/BUILD.gn index fdb5ac105..e5e4c8a5f 100644 --- a/gn/toolchain/BUILD.gn +++ b/gn/toolchain/BUILD.gn @@ -11,10 +11,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -toolchain("gcc") { +toolchain("clang") { tool("cc") { depfile = "{{output}}.d" - command = "gcc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}" + command = "clang -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}" depsformat = "gcc" description = "CC {{output}}" outputs = @@ -22,7 +22,7 @@ toolchain("gcc") { } tool("cxx") { depfile = "{{output}}.d" - command = "g++ -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}" + command = "clang++ -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}" depsformat = "gcc" description = "CXX {{output}}" outputs = @@ -47,7 +47,7 @@ toolchain("gcc") { os_specific_option = "-Wl,-soname=$soname" rspfile_content = "-Wl,--whole-archive {{inputs}} {{solibs}} -Wl,--no-whole-archive {{libs}}" } - command = "g++ -shared {{ldflags}} -o $sofile $os_specific_option @$rspfile" + command = "clang++ -shared {{ldflags}} -o $sofile $os_specific_option @$rspfile" description = "SOLINK $soname" # Use this for {{output_extension}} expansions unless a target manually # overrides it (in which case {{output_extension}} will be what the target @@ -65,9 +65,9 @@ toolchain("gcc") { outfile = "{{target_output_name}}{{output_extension}}" rspfile = "$outfile.rsp" if (is_mac) { - command = "g++ {{ldflags}} -o $outfile @$rspfile {{solibs}} {{libs}}" + command = "clang++ {{ldflags}} -o $outfile @$rspfile {{solibs}} {{libs}}" } else { - command = "g++ {{ldflags}} -o $outfile -Wl,--start-group @$rspfile {{solibs}} -Wl,--end-group {{libs}}" + command = "clang++ {{ldflags}} -o $outfile -Wl,--start-group @$rspfile {{solibs}} -Wl,--end-group {{libs}}" } description = "LINK $outfile" default_output_dir = "{{root_out_dir}}" -- Gitee