-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·107 lines (91 loc) · 3.69 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·107 lines (91 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/bin/sh
set -e
if [ -z "$1" ]; then
echo "usage: ./build.sh <branch name or tag name>"
echo "example: ./build.sh main"
echo "example: ./build.sh v26.7.0"
exit 1
fi
version=$1
workdir=$(pwd)
query_component() {
component=$1
curl -fsSL 'https://dcp.openharmony.cn/api/daily_build/build/list/component' \
-H 'Accept: application/json, text/plain, */*' \
-H 'Content-Type: application/json' \
--data-raw '{"projectName":"openharmony","branch":"master","pageNum":1,"pageSize":10,"deviceLevel":"","component":"'${component}'","type":1,"startTime":"2025080100000000","endTime":"20990101235959","sortType":"","sortField":"","hardwareBoard":"","buildStatus":"success","buildFailReason":"","withDomain":1}'
}
# clean old files if exist
rm -rf *.tar.gz \
*.tar.xz \
ohos-sdk \
daily_build.log \
manifest_tag.xml \
llvm-19 \
node \
node-${version}-openharmony-arm64
# setup openharmony sdk
sdk_download_url=$(query_component "ohos-sdk-public" | jq -r ".data.list.dataList[0].obsPath")
curl $sdk_download_url -o ohos-sdk-public.tar.gz
tar -zxf ohos-sdk-public.tar.gz
rm -rf daily_build.log manifest_tag.xml ohos-sdk/windows ohos-sdk/ohos
cd ohos-sdk/linux
unzip -q toolchains-*.zip
rm -rf *.zip
cd ../..
# setup LLVM-19
llvm19_download_url=$(query_component "LLVM-19" | jq -r ".data.list.dataList[0].obsPath")
curl $llvm19_download_url -o LLVM-19.tar.gz
mkdir llvm-19
tar -zxf LLVM-19.tar.gz -C llvm-19
cd llvm-19
tar -zxf llvm-linux-x86_64.tar.gz
tar -zxf ohos-sysroot.tar.gz
cd ..
git clone --branch $version --depth 1 https://github.com/nodejs/node.git
cd node
export CC="$workdir/llvm-19/llvm/bin/aarch64-unknown-linux-ohos-clang -fno-emulated-tls"
export CXX="$workdir/llvm-19/llvm/bin/aarch64-unknown-linux-ohos-clang++ -fno-emulated-tls"
export CC_host="gcc"
export CXX_host="g++"
need_patch_0001_versions="v24.2.0 v24.3.0 v24.4.0 v24.4.1 v24.5.0 v24.6.0"
if echo " $need_patch_0001_versions " | grep -q " $version "; then
patch -p1 < ../0001-fix-argument-list-too-long.patch
fi
need_patch_0002_versions="^v22\."
if echo "$version" | grep -q "$need_patch_0002_versions"; then
patch -p1 < ../0002-use-C++20-for-Node.js-core.patch
fi
need_no_error_versions="v24.2.0 v24.3.0 v24.4.0 v24.4.1 v24.5.0 \
v24.6.0 v24.7.0 v24.8.0 v22.17.0 v22.17.1 \
v22.18.0 v22.19.0"
if echo " $need_no_error_versions " | grep -q " $version "; then
export CC="$CC -Wno-error=implicit-function-declaration"
export CXX="$CXX -Wno-error=implicit-function-declaration"
fi
CONFIGURE_ARGS="--dest-cpu=arm64 \
--dest-os=openharmony \
--cross-compiling \
--openssl-no-asm \
--prefix=$workdir/node-${version}-openharmony-arm64"
# Node.js's build system enables Temporal by default when a Rust environment
# is available on the build machine.
# For details, see this PR: https://github.com/nodejs/node/pull/61806.
# However, enabling Temporal causes build failures during cross-compilation for OHOS.
# To ensure this build script works correctly on machines with Rust environments
# (such as GitHub Actions runners), Temporal is explicitly disabled here.
if ./configure --help 2>&1 | grep -q -- "--v8-disable-temporal-support"; then
CONFIGURE_ARGS="$CONFIGURE_ARGS --v8-disable-temporal-support"
fi
./configure $CONFIGURE_ARGS
make -j$(nproc)
make install
cd ..
# code signing
$workdir/ohos-sdk/linux/toolchains/lib/binary-sign-tool sign \
-inFile node-${version}-openharmony-arm64/bin/node \
-outFile node-${version}-openharmony-arm64/bin/node \
-selfSign 1
cp LICENSE node-${version}-openharmony-arm64
tar -zcf node-${version}-openharmony-arm64.tar.gz node-${version}-openharmony-arm64
tar -Jcf node-${version}-openharmony-arm64.tar.xz node-${version}-openharmony-arm64