diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 35031e0..c4e71fa 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,17 +8,41 @@ on: branches: - main +concurrency: + group: ${{ github.ref }} + cancel-in-progress: true + env: NODE_VERSION: "v18.16.1" jobs: build: strategy: - fail-fast: false + fail-fast: true matrix: arch: [x64] os: [macos-latest, ubuntu-latest, windows-2019] + include: + - arch: x64 + os: macos-latest + - arch: x64 + os: windows-2019 + - arch: x64 + os: ubuntu-latest + + - arch: x86 + os: windows-2019 + # https://github.com/nodejs/node/issues/33019 + # - arch: x86 + # os: ubuntu-latest + + # - arch: armv7 + # os: ubuntu-latest + - arch: arm64 + os: ubuntu-latest runs-on: ${{ matrix.os }} + env: + TARGET_ARCH: ${{ matrix.arch }} steps: - uses: actions/checkout@v2 - name: Download source code @@ -26,14 +50,7 @@ jobs: run: ./scripts/download.sh - name: Build shell: bash - run: | - if [ "$RUNNER_OS" == "Linux" ]; then - ./scripts/build-linux.sh - elif [ "$RUNNER_OS" == "Windows" ]; then - ./scripts/build-windows.sh - else - ./scripts/build-macos.sh - fi + run: ./scripts/build.sh - name: Upload artifacts uses: actions/upload-artifact@v2.3.1 with: diff --git a/patches/configure.py.patch b/patches/configure.py.patch new file mode 100644 index 0000000..04999dd --- /dev/null +++ b/patches/configure.py.patch @@ -0,0 +1,13 @@ +diff --git a/configure.py b/configure.py +index 40e0395..b70d238 100755 +--- a/configure.py ++++ b/configure.py +@@ -1296,7 +1296,7 @@ def configure_node(o): + + # Enable branch protection for arm64 + if target_arch == 'arm64': +- o['cflags']+=['-msign-return-address=all'] ++ # o['cflags']+=['-msign-return-address=all'] + o['variables']['arm_fpu'] = options.arm_fpu or 'neon' + + if options.node_snapshot_main is not None: diff --git a/scripts/build-linux.sh b/scripts/build-linux.sh deleted file mode 100755 index 084547a..0000000 --- a/scripts/build-linux.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -set -ex - -. "$(dirname "$0")"/prepare-env.sh -cd ./node - -./configure --prefix=$OUTPUT_PREFIX --shared - -make -j`nproc` -make install -cp ./LICENSE "${OUTPUT_PREFIX}/LICENSE" diff --git a/scripts/build-windows.sh b/scripts/build-windows.sh deleted file mode 100755 index 1f961a1..0000000 --- a/scripts/build-windows.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -set -ex - -choco install nasm -. "$(dirname "$0")"/prepare-env.sh -cd ./node - -./vcbuild.bat release dll package - -mv ./out/Release/node-${NODE_VERSION}-win-x64 "${OUTPUT_PREFIX}/" -cp ./LICENSE "${OUTPUT_PREFIX}/LICENSE" diff --git a/scripts/build.sh b/scripts/build.sh new file mode 100755 index 0000000..17e5e66 --- /dev/null +++ b/scripts/build.sh @@ -0,0 +1,18 @@ +#!/bin/bash +set -ex + +. "$(dirname "$0")"/prepare-env.sh +SCRIPTS_DIR=$WORKSPACE/scripts +cd $WORKSPACE/node + +if [[ "$RUNNER_OS" == "Linux" ]]; then + TARGET_OS="linux" +elif [[ "$RUNNER_OS" == "macOS" ]]; then + TARGET_OS="macos" +elif [[ "$RUNNER_OS" == "Windows" ]]; then + TARGET_OS="win" +else + echo "Unknown OS: $RUNNER_OS" + exit 1 +fi +. $SCRIPTS_DIR/build/$TARGET_OS.sh diff --git a/scripts/build/linux.sh b/scripts/build/linux.sh new file mode 100644 index 0000000..c4b9f29 --- /dev/null +++ b/scripts/build/linux.sh @@ -0,0 +1,32 @@ +#!/bin/bash +set -ex + +export CC_host=gcc +export CXX_host=g++ + +if [[ "$TARGET_ARCH" == "x64" ]]; then + ./configure --prefix=$OUTPUT_PREFIX --shared --no-cross-compiling +else + DEST_CPU=$TARGET_ARCH + if [[ "$TARGET_ARCH" == "armv7" ]]; then + DEST_CPU="arm" + sudo apt-get install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf + # FIXME: gcc-multilib conflicts. + # libstdc++-6-dev-armhf-cross gcc-multilib g++-multilib + export CC=arm-linux-gnueabihf-gcc + export CXX=arm-linux-gnueabihf-g++ + elif [[ "$TARGET_ARCH" == "x86" ]]; then + sudo apt-get install gcc-multilib g++-multilib + elif [[ "$TARGET_ARCH" == "arm64" ]]; then + sudo apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu + export CC=aarch64-linux-gnu-gcc + export CXX=aarch64-linux-gnu-g++ + fi + patch -p1 < $WORKSPACE/patches/configure.py.patch + ./configure --prefix=$OUTPUT_PREFIX --shared \ + --cross-compiling --dest-cpu=$DEST_CPU --dest-os=linux +fi + +make -j`nproc` +make install +cp ./LICENSE "${OUTPUT_PREFIX}/LICENSE" diff --git a/scripts/build-macos.sh b/scripts/build/macos.sh old mode 100755 new mode 100644 similarity index 68% rename from scripts/build-macos.sh rename to scripts/build/macos.sh index 5bef1ff..1578f32 --- a/scripts/build-macos.sh +++ b/scripts/build/macos.sh @@ -1,10 +1,6 @@ #!/bin/bash set -ex -brew install coreutils -. "$(dirname "$0")"/prepare-env.sh -cd ./node - ./configure --prefix=$OUTPUT_PREFIX --shared make -j`sysctl -n hw.ncpu` diff --git a/scripts/build/win.sh b/scripts/build/win.sh new file mode 100644 index 0000000..a599141 --- /dev/null +++ b/scripts/build/win.sh @@ -0,0 +1,9 @@ +#!/bin/bash +set -ex + +choco install nasm + +./vcbuild.bat release dll package ${TARGET_ARCH} + +mv ./out/Release/node-${NODE_VERSION}-win-${TARGET_ARCH} "${OUTPUT_PREFIX}/" +cp ./LICENSE "${OUTPUT_PREFIX}/LICENSE" diff --git a/scripts/prepare-env.sh b/scripts/prepare-env.sh index e7ed698..88c8093 100755 --- a/scripts/prepare-env.sh +++ b/scripts/prepare-env.sh @@ -1,6 +1,11 @@ #!/bin/bash set -ex +if [[ "$RUNNER_OS" == "macOS" ]]; then + brew install coreutils + TARGET_OS="linux" +fi + export WORKSPACE=$(realpath "$(dirname "$0")"/..) export OUTPUT_PREFIX="${WORKSPACE}/artifacts" mkdir -p "${OUTPUT_PREFIX}"