Skip to content

Commit

Permalink
Error for armv7 musl build (#5255)
Browse files Browse the repository at this point in the history
* Sort build targets

* Add error for missing arm musl build

* Cancel in-progress REPL builds
  • Loading branch information
lukastaegert authored Nov 18, 2023
1 parent 1df8b49 commit 86bdd2b
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 38 deletions.
75 changes: 41 additions & 34 deletions .github/workflows/build-and-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ jobs:
fail-fast: false
matrix:
settings:
# WASM
- host: windows-latest
target: x86_64-pc-windows-msvc
name: wasm
Expand All @@ -81,12 +82,8 @@ jobs:
path: |
wasm-node/
.empty
- host: macos-latest
target: x86_64-apple-darwin
build: >-
set -e &&
npm run build:napi -- --release &&
strip -x *.node
# Windows
- host: windows-latest
build: npm run build:napi -- --release
target: x86_64-pc-windows-msvc
Expand All @@ -96,6 +93,26 @@ jobs:
rustup target add i686-pc-windows-msvc &&
npm run build:napi -- --release --target i686-pc-windows-msvc
target: i686-pc-windows-msvc
- host: windows-latest
target: aarch64-pc-windows-msvc
build: npm run build:napi -- --release --target aarch64-pc-windows-msvc

# MacOS
- host: macos-latest
target: x86_64-apple-darwin
build: >-
set -e &&
npm run build:napi -- --release &&
strip -x *.node
- host: macos-latest
target: aarch64-apple-darwin
build: >-
set -e &&
rustup target add aarch64-apple-darwin &&
npm run build:napi -- --release --target aarch64-apple-darwin &&
strip -x *.node
# Linux
- host: ubuntu-latest
target: x86_64-unknown-linux-gnu
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian
Expand All @@ -110,13 +127,16 @@ jobs:
build: >-
set -e &&
npm run build:napi -- --release && strip *.node
- host: macos-latest
target: aarch64-apple-darwin
- host: ubuntu-latest
target: armv7-unknown-linux-gnueabihf
zig: true
setup: |
sudo apt-get update
sudo apt-get install gcc-arm-linux-gnueabihf -y
build: >-
set -e &&
rustup target add aarch64-apple-darwin &&
npm run build:napi -- --release --target aarch64-apple-darwin &&
strip -x *.node
npm run build:napi -- --release --target armv7-unknown-linux-gnueabihf &&
arm-linux-gnueabihf-strip *.node
- host: ubuntu-latest
target: aarch64-unknown-linux-gnu
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian-aarch64
Expand All @@ -128,40 +148,27 @@ jobs:
npm run build:napi -- --release --target aarch64-unknown-linux-gnu &&
aarch64-unknown-linux-gnu-strip *.node
- host: ubuntu-latest
target: armv7-unknown-linux-gnueabihf
zig: true
setup: |
sudo apt-get update
sudo apt-get install gcc-arm-linux-gnueabihf -y
build: >-
set -e &&
npm run build:napi -- --release --target armv7-unknown-linux-gnueabihf &&
arm-linux-gnueabihf-strip *.node
- host: ubuntu-latest
target: aarch64-linux-android
target: aarch64-unknown-linux-musl
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine
build: >-
set -e &&
npm run build:napi -- --release --target aarch64-linux-android &&
${ANDROID_NDK_LATEST_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip *.node
export JEMALLOC_SYS_WITH_LG_PAGE=16 &&
rustup default nightly-2023-10-05 &&
rustup target add aarch64-unknown-linux-musl &&
RUSTFLAGS='-C target-feature=-crt-static -C linker=aarch64-linux-musl-gcc' npm run build:napi -- --release --target aarch64-unknown-linux-musl &&
/aarch64-linux-musl-cross/bin/aarch64-linux-musl-strip *.node
- host: ubuntu-latest
target: armv7-linux-androideabi
build: >-
set -e &&
npm run build:napi -- --release --target armv7-linux-androideabi &&
${ANDROID_NDK_LATEST_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip *.node
- host: ubuntu-latest
target: aarch64-unknown-linux-musl
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine
target: aarch64-linux-android
build: >-
set -e &&
export JEMALLOC_SYS_WITH_LG_PAGE=16 &&
rustup default nightly-2023-10-05 &&
rustup target add aarch64-unknown-linux-musl &&
RUSTFLAGS='-C target-feature=-crt-static -C linker=aarch64-linux-musl-gcc' npm run build:napi -- --release --target aarch64-unknown-linux-musl &&
/aarch64-linux-musl-cross/bin/aarch64-linux-musl-strip *.node
- host: windows-latest
target: aarch64-pc-windows-msvc
build: npm run build:napi -- --release --target aarch64-pc-windows-msvc
npm run build:napi -- --release --target aarch64-linux-android &&
${ANDROID_NDK_LATEST_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip *.node
name: Build ${{ matrix.settings.name || matrix.settings.target }}
runs-on: ${{ matrix.settings.host }}
timeout-minutes: 30
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/repl-artefacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ on:
- reopened
- labeled

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

permissions:
contents: read

Expand Down
19 changes: 15 additions & 4 deletions native.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const bindingsByPlatformAndArch = {
x64: { base: 'darwin-x64' }
},
linux: {
arm: { base: 'linux-arm-gnueabihf' },
arm: { base: 'linux-arm-gnueabihf', musl: null },
arm64: { base: 'linux-arm64-gnu', musl: 'linux-arm64-musl' },
x64: { base: 'linux-x64-gnu', musl: 'linux-x64-musl' }
},
Expand All @@ -25,8 +25,9 @@ const bindingsByPlatformAndArch = {
}
};

const imported = bindingsByPlatformAndArch[platform]?.[arch];
if (!imported) {
const packageBase = getPackageBase();

if (!packageBase) {
throw new Error(
`Your current platform "${platform}" and architecture "${arch}" combination is not yet supported by the native Rollup build. Please use the WASM build "@rollup/wasm-node" instead.
Expand All @@ -44,7 +45,17 @@ If this is important to you, please consider supporting Rollup to make a native
);
}

const packageBase = imported.musl && isMusl() ? imported.musl : imported.base;
function getPackageBase() {
const imported = bindingsByPlatformAndArch[platform]?.[arch];
if (!imported) {
return null;
}
if ('musl' in imported && isMusl()) {
return imported.musl;
}
return imported.base;
}

const localName = `./rollup.${packageBase}.node`;
const { parse, parseAsync, xxhashBase64Url } = require(
existsSync(join(__dirname, localName)) ? localName : `@rollup/rollup-${packageBase}`
Expand Down

0 comments on commit 86bdd2b

Please sign in to comment.