|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -e |
| 3 | +set -x |
| 4 | + |
| 5 | +release_urlbase="$1" |
| 6 | +disttype="$2" |
| 7 | +customtag="$3" |
| 8 | +datestring="$4" |
| 9 | +commit="$5" |
| 10 | +fullversion="$6" |
| 11 | +source_url="$7" |
| 12 | +source_urlbase="$8" |
| 13 | +config_flags="" |
| 14 | + |
| 15 | +cd /home/node |
| 16 | + |
| 17 | +tar -xf node.tar.xz |
| 18 | +cd "node-${fullversion}" |
| 19 | + |
| 20 | +major=$(echo ${fullversion} | cut -d . -f 1 | tr -d v) |
| 21 | + |
| 22 | +# Patch needed to support cross compilation for arm64 on amd64 for node 16 and 18. |
| 23 | +# The PR introducing the issue (https://github.com/nodejs/node/pull/43200) was merged in main released in v20 and backported to v18 (https://github.com/nodejs/node/pull/44353) and v16 (https://github.com/nodejs/node/pull/44886) |
| 24 | +# The fix for the issue (https://github.com/nodejs/node/pull/51256) was only merged into v20 (https://github.com/nodejs/node/pull/52793) |
| 25 | +# Therefore the fix needs to be re-applied to v16 and v18 if we want to compile those too. |
| 26 | +# the initial patch works on v18, for v16 a reroll was required. |
| 27 | +# @see https://github.com/nodejs/node/pull/51256 |
| 28 | +if [ "$major" == "18" ]; then |
| 29 | + wget -O /home/node/51256.diff https://patch-diff.githubusercontent.com/raw/nodejs/node/pull/51256.diff |
| 30 | + patch -p1 < /home/node/51256.diff || true |
| 31 | +elif [ "$major" == "16" ]; then |
| 32 | + patch -p1 < /home/node/51256-v16.diff || true |
| 33 | + rm /home/node/51256-v16.diff |
| 34 | +fi |
| 35 | + |
| 36 | +# Patch needed so we can depend on newer Python versions for older NodeJS versions. |
| 37 | +# This allows us to use the same Dockerfile and Alpine version. |
| 38 | +if [ "$major" == "18" ] || [ "$major" == "16" ] ; then |
| 39 | + wget -O /home/node/50209.diff https://patch-diff.githubusercontent.com/raw/nodejs/node/pull/50209.diff |
| 40 | + patch -p1 < /home/node/50209.diff || true |
| 41 | +fi |
| 42 | + |
| 43 | +# For v16, and additional patch is needed to replace the dependency on distutils, as it was removed in Python 3.12 |
| 44 | +# There is both usage of distutils in node itself, and in the gyp dependency. |
| 45 | +# This also requires the packaging module, which is installed in the Dockerfile (see py3-packaging) |
| 46 | +if [ "$major" == "16" ] ; then |
| 47 | + wget -O /home/node/50582.diff https://patch-diff.githubusercontent.com/raw/nodejs/node/pull/50582.diff |
| 48 | + patch -p1 < /home/node/50582.diff || true |
| 49 | + |
| 50 | + wget -O /home/node/2888.diff https://patch-diff.githubusercontent.com/raw/nodejs/node-gyp/pull/2888.diff |
| 51 | + patch -d tools -p1 < /home/node/2888.diff |
| 52 | +fi |
| 53 | + |
| 54 | +# Patch needed to support compilation of Node 22 using musl |
| 55 | +# @see https://github.com/nodejs/node/issues/55596#issuecomment-2451411974 |
| 56 | +# Although the GCC version in Alpine 3.22 is 14, The musl toolchain used is compiled using 11.2 (see https://musl.cc/) |
| 57 | +# recompiling musl is a step too far, so we add a simple patch that allows us to compile v22 |
| 58 | +if [ "$major" == "22" ]; then |
| 59 | + patch -p1 < /home/node/55596.diff |
| 60 | +fi |
| 61 | + |
| 62 | +export CC_host="ccache gcc" |
| 63 | +export CXX_host="ccache g++" |
| 64 | +export CC="ccache /opt/aarch64-linux-musl-cross/bin/aarch64-linux-musl-gcc" |
| 65 | +export CXX="ccache /opt/aarch64-linux-musl-cross/bin/aarch64-linux-musl-g++ -static-libstdc++" |
| 66 | + |
| 67 | +make -j$(getconf _NPROCESSORS_ONLN) binary V= \ |
| 68 | + DESTCPU="arm64" \ |
| 69 | + ARCH="arm64" \ |
| 70 | + VARIATION="musl" \ |
| 71 | + DISTTYPE="$disttype" \ |
| 72 | + CUSTOMTAG="$customtag" \ |
| 73 | + DATESTRING="$datestring" \ |
| 74 | + COMMIT="$commit" \ |
| 75 | + RELEASE_URLBASE="$release_urlbase" \ |
| 76 | + CONFIG_FLAGS="$config_flags" |
| 77 | + |
| 78 | +mv node-*.tar.?z /out/ |
0 commit comments