文章目录
1. 前言
本文参考了wikis/下载和编译运行ArkTS演进版代码#4test。
本地环境是Windows11、wsl ubuntu22.04,非docker容器。
2. 搭建准备
准备文件。
bash
.
├── build.sh # arkcompiler编译脚本。
├── create_arkts.sh # arkcompiler环境搭建脚本,一键执行。建议在非root环境执行
└── runtime_core.patch # rutime_core为搭建环境需要修改pip源、增加github.com访问代理的补丁
说明:
- 环境依赖git、python3、clang(默认14版本)。未安装的请执行
apt install xxx来安装。 - 2个仓库都是拉取master分支代码。若需要其它分支,请修改
create_arkts.sh代码。 - 相关文件放在任意目录。
- 建议用非root用户操作。
- .sh文件请使用
chmod +x xxx.sh赋予执行权限。
3. 搭建&编译
搭建
执行 bash create_arkts.sh在当前文件夹创建arkts+当天日期的文件夹(比如arkts_20260325),自动下载2个仓库代码,并做相应的配置
搭建结果
bash
.
├── arkts_20260325
│ ├── ets_frontend
│ └── runtime_core
├── build.sh
├── create_arkts.sh
└── runtime_core.patch
编译
进入runtime工程目录的子目录static_core,执行arkcompiler构建(release)
bash
cd runtime/static_core
bash ../../../build.sh r # release构建,输出目录release_out。不带参数r,表示的是debug模式构建。输出目录out。
4. 附录
4.1 create_arkts.sh文件内容
bash
#!/bin/bash
# Create a new ArkTS project
# Usage: ./create_arkts.sh
current_date=$(date +%Y%m%d)
project_dir="arkts_${current_date}"
# download ets_frontend and runtime_core
mkdir -p "$project_dir"
cd "$project_dir"
# git clone https://gitcode.com/openharmony/arkcompiler_runtime_core.git runtime_core
# git clone https://gitcode.com/openharmony/arkcompiler_ets_frontend.git ets_frontend
# patch runtime_core
if [ ! -L ./runtime_core/static_core/tools/"es2panda" ]; then
ln -s ../../../ets_frontend/ets2panda ./runtime_core/static_core/tools/es2panda
fi
pwd
if [ ! -f "../runtime_core.patch" ]; then
echo "Error: runtime_core.patch file not found!"
exit 1
fi
cd ./runtime_core/
echo "Checking if patch has already been applied..."
if git apply --check --reverse ../../runtime_core.patch 2>/dev/null; then
echo "Patch has already been applied, skipping..."
else
echo "Applying patch..."
git apply --check ../../runtime_core.patch && git apply ../../runtime_core.patch || { echo "Error: Failed to apply runtime_core.patch!"; exit 1; }
echo "Patch applied successfully"
fi
# install node >= v18.19.1 npm >= v10
# check nodejs version if large than v18.19.1, then install it
echo "Checking Node.js version..."
NEED_INSTALL=false
if command -v node &> /dev/null; then
NODE_VERSION=$(node -v | sed 's/v//')
# Check if version is less than 20
if [ "$(printf '%s\n' "20.0.0" "$NODE_VERSION" | sort -V | head -n1)" != "20.0.0" ]; then
NEED_INSTALL=true
fi
else
NEED_INSTALL=true
fi
if [ "$NEED_INSTALL" = true ]; then
echo "Installing Node.js v18.19.1..."
# Clean up and install Node.js 18.x
sudo apt-get autoremove -y
sudo apt-get clean
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejs
# Verify installation
echo "Verifying Node.js and npm installation..."
node -v
npm -v
# Add configuration to ~/.npmrc
echo "Configuring npm..."
cat > ~/.npmrc << EOF
package-lock=true
registry=https://repo.huaweicloud.com/repository/npm/
@ohos:registry=https://repo.harmonyos.com/npm/
strict-ssl=false
lockfile=false
EOF
echo "npm configuration updated successfully"
# Check if installation was successful
NEW_NODE_VERSION=$(node -v | sed 's/v//')
if [ "$(printf '%s\n' "18.19.1" "$NEW_NODE_VERSION" | sort -V | head -n1)" = "18.19.1" ]; then
echo "Node.js installation successful: v$NEW_NODE_VERSION"
else
echo "Error: Node.js installation failed! Version: $NEW_NODE_VERSION"
exit 1
fi
fi
# 根据 ls /usr/bin/clang*执行结果, 查找clang++是否存在,不存在. 没有提醒安装.有创建手动链接
echo "Checking clang installation..."
# Check for clang++ in /usr/bin
if ls /usr/bin/clang* 2>/dev/null | grep -q "clang++"; then
echo "clang++ found, creating symlinks..."
# Create symlinks for clang and clang++
if [ -f "/usr/bin/clang-14" ]; then
sudo ln -sf /usr/bin/clang-14 /usr/bin/clang
fi
if [ -f "/usr/bin/clang++-14" ]; then
sudo ln -sf /usr/bin/clang++-14 /usr/bin/clang++
fi
echo "clang symlinks created successfully"
else
echo "clang++ not found, skipping symlink creation"
fi
# install dependencies
cd ./static_core/
sudo ./scripts/install-deps-ubuntu -i=dev -i=test
sudo apt install gdb
pip3 install tqdm
pip3 install python-dotenv
./scripts/install-third-party --force-clone
4.2 runtime_core.patch文件内容
bash
diff --git a/scripts/third-party-lists/public b/scripts/third-party-lists/public
index f4b3097c72..a580aa178e 100644
--- a/scripts/third-party-lists/public
+++ b/scripts/third-party-lists/public
@@ -28,22 +28,22 @@
# ARK common:
-googletest,https://github.com/google/googletest,tag,release-1.11.0,no_patches,no_submodules
+googletest,https://ghfast.top/https://github.com/google/googletest,tag,release-1.11.0,no_patches,no_submodules
utils_native,https://gitcode.com/openharmony/commonlibrary_c_utils,branch,master,no_patches,no_submodules
zlib,https://gitcode.com/openharmony/third_party_zlib,branch,master,no_patches,no_submodules
# ARK compiler:
-asmjit,https://github.com/asmjit/asmjit,commit,8474400e82c3ea65bd828761539e5d9b25f6bd83,with_patches,no_submodules
-elfio,https://github.com/serge1/ELFIO,tag,Release_3.9,with_patches,no_submodules
+asmjit,https://ghfast.top/https://github.com/asmjit/asmjit,commit,8474400e82c3ea65bd828761539e5d9b25f6bd83,with_patches,no_submodules
+elfio,https://ghfast.top/https://github.com/serge1/ELFIO,tag,Release_3.9,with_patches,no_submodules
vixl,https://git.linaro.org/arm/vixl.git,tag,6.2.0,with_patches,no_submodules
-zydis,https://github.com/zyantific/zydis,tag,v3.2.1,with_patches,no_submodules
+zydis,https://ghfast.top/https://github.com/zyantific/zydis,tag,v3.2.1,with_patches,no_submodules
# ARK bytecode verifier:
-rapidcheck,https://github.com/emil-e/rapidcheck,commit,8fafda42e732164db58003e542196e94a28481f9,no_patches,with_submodules:ext/catch
+rapidcheck,https://ghfast.top/https://github.com/emil-e/rapidcheck,commit,8fafda42e732164db58003e542196e94a28481f9,no_patches,with_submodules:ext/catch
# ARK tooling:
-asio,https://github.com/chriskohlhoff/asio,tag,asio-1-18-1,no_patches,no_submodules
-websocketpp,https://github.com/zaphoyd/websocketpp,tag,0.8.2,no_patches,no_submodules
+asio,https://ghfast.top/https://github.com/chriskohlhoff/asio,tag,asio-1-18-1,no_patches,no_submodules
+websocketpp,https://ghfast.top/https://github.com/zaphoyd/websocketpp,tag,0.8.2,no_patches,no_submodules
# ARK plugins:
icu,https://gitcode.com/openharmony/third_party_icu,branch,master,no_patches,no_submodules
diff --git a/static_core/scripts/install-deps-ubuntu b/static_core/scripts/install-deps-ubuntu
index 8ce62c486f..d1d86e11a9 100755
--- a/static_core/scripts/install-deps-ubuntu
+++ b/static_core/scripts/install-deps-ubuntu
@@ -112,7 +112,7 @@ function print_help
--install=test | -i=test Install python dependencies for tests running
--install=vmb | -i=vmb Installs VMB framework to run benchmarks from CLI
-
- --install=llvm-prebuilts | -i=llvm-prebuilts Install deps for use llvm prebuilts.
--install=ohos-sdk | -i=ohos-sdk Install ohos SDK.
@@ -164,7 +164,8 @@ function install_pip_dep
if [[ $VERSION_ID == "24.04" ]]; then
python3 -m pip install --break-system-packages --no-cache-dir --upgrade -r $fname
else
- python3 -m pip install --no-cache-dir --upgrade -r $fname
- # python3 -m pip install --no-cache-dir --upgrade -r $fname
- python3 -m pip install --no-cache-dir --upgrade -r $fname -i https://mirrors.huaweicloud.com/repository/pypi/simple/ --trusted-host mirrors.huaweicloud.com
fi
}
@@ -551,7 +552,7 @@ if [[ "$INSTALL_CROSS_LIBS" == "yes" ]]; then
fi
if [[ "x$INSTALL_DOC_DEV" == "xyes" ]]; then
- if [[ -f "$SCRIPT_DIR/dep-lists/$UBUNTU_NAME-doc-dev" ]] ; then
- if [[ -f "$SCRIPT_DIR/dep-lists/$UBUNTU_NAME-doc-dev" ]] ; then
install_dep "$SCRIPT_DIR/dep-lists/$UBUNTU_NAME-doc-dev"
else
install_dep "$SCRIPT_DIR/dep-lists/ubuntu-doc-dev"
diff --git a/static_core/scripts/install-third-party b/static_core/scripts/install-third-party
index 066266712f..69a2f36eb2 100755
--- a/static_core/scripts/install-third-party
+++ b/static_core/scripts/install-third-party
@@ -241,7 +241,7 @@ if [[ "$ARK_INSTALL_NODE" == "yes" ]] ; then
rm ${ARK_THIRD_PARTY_DIR}/nodejs/${ARCHIVE_NAME}
echo "-- Downloading nodejs stub lib for tsbindings windows"
NODE_API_STUB_LIB="libnode_api-windows.zip"
- wget --no-check-certificate -P ${ARK_THIRD_PARTY_DIR}/nodejs https://github.com/napi-bindings/node-api-stub/releases/download/8.0.0/${NODE_API_STUB_LIB}
- wget --no-check-certificate -P ${ARK_THIRD_PARTY_DIR}/nodejs https://ghfast.top/https://github.com/napi-bindings/node-api-stub/releases/download/8.0.0/${NODE_API_STUB_LIB}
unzip ${ARK_THIRD_PARTY_DIR}/nodejs/${NODE_API_STUB_LIB} -d ${ARK_THIRD_PARTY_DIR}/nodejs/node-${NODE_VERSION}-${DISTRO}/lib/
rm ${ARK_THIRD_PARTY_DIR}/nodejs/${NODE_API_STUB_LIB}
fi
diff --git a/static_core/scripts/third-party-lists/public b/static_core/scripts/third-party-lists/public
index ed2af05b9b..a1a460c1a6 100644
--- a/static_core/scripts/third-party-lists/public
+++ b/static_core/scripts/third-party-lists/public
@@ -28,23 +28,23 @@
# ARK common:
-googletest,https://github.com/google/googletest,tag,v1.13.0,with_patches,no_submodules
+googletest,https://ghfast.top/https://github.com/google/googletest,tag,v1.13.0,with_patches,no_submodules
utils_native,https://gitcode.com/openharmony/utils_native,branch,OpenHarmony-3.2-Beta1,no_patches,no_submodules
zlib,https://gitcode.com/openharmony/third_party_zlib,branch,OpenHarmony-5.0.1-Release,no_patches,no_submodules
# ARK compiler:
-asmjit,https://github.com/asmjit/asmjit,commit,8474400e82c3ea65bd828761539e5d9b25f6bd83,with_patches,no_submodules
+asmjit,https://ghfast.top/https://github.com/asmjit/asmjit,commit,8474400e82c3ea65bd828761539e5d9b25f6bd83,with_patches,no_submodules
elfio,https://gitcode.com/openharmony/third_party_elfio,branch,OpenHarmony_feature_20250328,no_patches,no_submodules
vixl,https://gitcode.com/openharmony/third_party_vixl.git,commit,62c46148189503cc1f220185ab753338211d03f2,with_patches,no_submodules
-zydis,https://github.com/zyantific/zydis,tag,v3.2.1,with_patches,no_submodules
+zydis,https://ghfast.top/https://github.com/zyantific/zydis,tag,v3.2.1,with_patches,no_submodules
flatbuffers,https://gitcode.com/openharmony/third_party_flatbuffers,tag,OpenHarmony-v6.0-Release,no_patches,no_submodules
# ARK bytecode verifier:
-rapidcheck,https://github.com/emil-e/rapidcheck,commit,8fafda42e732164db58003e542196e94a28481f9,with_patches,with_submodules:extras/gtest
+rapidcheck,https://ghfast.top/https://github.com/emil-e/rapidcheck,commit,8fafda42e732164db58003e542196e94a28481f9,with_patches,with_submodules:extras/gtest
# ARK tooling:
-asio,https://github.com/chriskohlhoff/asio,tag,asio-1-28-0,no_patches,no_submodules
-websocketpp,https://github.com/zaphoyd/websocketpp,tag,0.8.2,no_patches,no_submodules
+asio,https://ghfast.top/https://github.com/chriskohlhoff/asio,tag,asio-1-28-0,no_patches,no_submodules
+websocketpp,https://ghfast.top/https://github.com/zaphoyd/websocketpp,tag,0.8.2,no_patches,no_submodules
openssl,https://gitcode.com/openharmony/third_party_openssl,branch,OpenHarmony-5.0.1-Release,no_patches,no_submodules
arkcompiler/toolchain,https://gitcode.com/openharmony/arkcompiler_toolchain,commit,a69502ef3d4dbcf81b3a7154bf0004cb3d85ffb7,no_patches,no_submodules
说明:
本补丁的主要目的:
- pip源修改
- github.com直接访问困难,加了代理
4.3 build.sh文件内容
bash
#!/bin/bash
base_path=$(pwd)
test_path="${base_path}/runtime_core/static_core"
cd ${test_path}
is_debug="true"
if [ $# -ge 1 ]; then
if [ "$1" == "r" ]; then
is_debug="false"
fi
fi
if [ "$is_debug" == "true" ]; then
# Debug
cmake -B out -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=./cmake/toolchain/host_clang_default.cmake -GNinja .
cmake --build out
else
# Release
cmake -B release_out -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=./cmake/toolchain/host_clang_default.cmake -GNinja .
cmake --build release_out
fi