Skip to content

Commit

Permalink
Merge pull request #178 from napi-rs/fix-musl-build
Browse files Browse the repository at this point in the history
fix: linux aarch64 musl build
  • Loading branch information
Brooooooklyn authored Jul 23, 2021
2 parents 7c729b7 + da40c86 commit 1faf66c
Show file tree
Hide file tree
Showing 15 changed files with 848 additions and 758 deletions.
12 changes: 5 additions & 7 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc-10"
linker = "aarch64-linux-gnu-gcc"

[target.armv7-unknown-linux-gnueabihf]
linker = "arm-linux-gnueabihf-gcc-10"
linker = "arm-linux-gnueabihf-gcc"

[target.x86_64-unknown-linux-musl]
rustflags = [
"-C",
"target-feature=-crt-static",
]
[target.aarch64-unknown-linux-musl]
linker = "aarch64-linux-musl-gcc"
rustflags = ["-C", "target-feature=-crt-static"]
198 changes: 135 additions & 63 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,30 @@ jobs:
- host: ubuntu-20.04
target: 'aarch64-unknown-linux-gnu'
setup: |
sudo apt-get install g++-10-aarch64-linux-gnu gcc-10-aarch64-linux-gnu -y
sudo apt-get install g++-aarch64-linux-gnu gcc-aarch64-linux-gnu -y
build: yarn build --target=aarch64-unknown-linux-gnu
- host: ubuntu-20.04
target: 'armv7-unknown-linux-gnueabihf'
setup: |
sudo apt-get install gcc-10-arm-linux-gnueabihf g++-10-arm-linux-gnueabihf -y
sudo apt-get install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf -y
build: yarn build --target=armv7-unknown-linux-gnueabihf
- host: ubuntu-20.04
target: 'aarch64-linux-android'
build: |
export CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang"
yarn build --target aarch64-linux-android
- host: ubuntu-latest
target: 'aarch64-unknown-linux-musl'
downloadTarget: 'aarch64-unknown-linux-musl'
docker: |
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD $DOCKER_REGISTRY_URL
docker pull ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine
docker tag ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine builder
build: docker run --rm -v ~/.cargo/git:/root/.cargo/git -v ~/.cargo/registry:/root/.cargo/registry -v $(pwd):/escape -w /escape builder sh -c "yarn build -- --target=aarch64-unknown-linux-musl"
- host: windows-latest
target: 'aarch64-pc-windows-msvc'
build: yarn build --target aarch64-pc-windows-msvc

name: stable - ${{ matrix.settings.target }} - node@14
runs-on: ${{ matrix.settings.host }}

Expand All @@ -96,19 +108,19 @@ jobs:
command: generate-lockfile

- name: Cache cargo registry
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ~/.cargo/registry
key: ${{ matrix.settings.target }}-node@14-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }}

- name: Cache cargo index
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ~/.cargo/git
key: ${{ matrix.settings.target }}-node@14-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }}

- name: Cache NPM dependencies
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: node_modules
key: npm-cache-${{ matrix.settings.target }}-node@14-${{ hashFiles('yarn.lock') }}
Expand Down Expand Up @@ -139,6 +151,52 @@ jobs:
name: bindings-${{ matrix.settings.target }}
path: ${{ env.APP_NAME }}.*.node

build-freebsd:
runs-on: macos-latest
name: Build FreeBSD
steps:
- uses: actions/checkout@v2
- name: Build
id: build
uses: vmactions/freebsd-vm@v0.1.5
env:
DEBUG: 'napi:*'
RUSTUP_HOME: /usr/local/rustup
CARGO_HOME: /usr/local/cargo
RUSTUP_IO_THREADS: 1
with:
envs: 'DEBUG RUSTUP_HOME CARGO_HOME RUSTUP_IO_THREADS'
usesh: true
mem: 3000
prepare: |
pkg install -y curl node yarn npm python2
curl https://sh.rustup.rs -sSf --output rustup.sh
sh rustup.sh -y --profile minimal --default-toolchain stable
export PATH="/usr/local/cargo/bin:$PATH"
echo "~~~~ rustc --version ~~~~"
rustc --version
echo "~~~~ node -v ~~~~"
node -v
echo "~~~~ yarn --version ~~~~"
yarn --version
run: |
export PATH="/usr/local/cargo/bin:$PATH"
pwd
ls -lah
whoami
env
freebsd-version
yarn install --ignore-scripts --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
yarn build
yarn test
rm -rf node_modules
rm -rf target
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: bindings-freebsd
path: ${{ env.APP_NAME }}.*.node

test-macOS-windows-binding:
name: Test bindings on ${{ matrix.settings.target }} - node@${{ matrix.node }}
needs:
Expand All @@ -151,7 +209,7 @@ jobs:
target: 'x86_64-apple-darwin'
- host: windows-latest
target: 'x86_64-pc-windows-msvc'
node: ['10', '12', '14', '15']
node: ['12', '14', '16']
runs-on: ${{ matrix.settings.host }}

steps:
Expand All @@ -164,7 +222,7 @@ jobs:
check-latest: true

- name: Cache NPM dependencies
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: node_modules
key: npm-cache-test-${{ matrix.settings.target }}-${{ matrix.node }}-${{ hashFiles('yarn.lock') }}
Expand Down Expand Up @@ -192,7 +250,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node: ['10', '12', '14', '15']
node: ['12', '14', '16']
runs-on: ubuntu-20.04

steps:
Expand All @@ -205,7 +263,7 @@ jobs:
check-latest: true

- name: Cache NPM dependencies
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: node_modules
key: npm-cache-test-linux-x64-gnu-${{ matrix.node }}-${{ hashFiles('yarn.lock') }}
Expand All @@ -224,7 +282,7 @@ jobs:
shell: bash

- name: Test bindings
run: docker run --rm -v $(pwd):/canvas -w /canvas node:${{ matrix.node }}-slim yarn test
run: docker run --rm -v $(pwd):/escape -w /escape node:${{ matrix.node }}-slim yarn test

test-linux-x64-musl-binding:
name: Test bindings on x86_64-unknown-linux-musl - node@${{ matrix.node }}
Expand All @@ -233,7 +291,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node: ['10', '12', '14', '15']
node: ['12', '14', '16']
runs-on: ubuntu-20.04

steps:
Expand All @@ -246,7 +304,7 @@ jobs:
check-latest: true

- name: Cache NPM dependencies
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: node_modules
key: npm-cache-test-x86_64-unknown-linux-musl-${{ matrix.node }}-${{ hashFiles('yarn.lock') }}
Expand All @@ -265,7 +323,7 @@ jobs:
shell: bash

- name: Test bindings
run: docker run --rm -v $(pwd):/canvas -w /canvas node:${{ matrix.node }}-alpine yarn test
run: docker run --rm -v $(pwd):/escape -w /escape node:${{ matrix.node }}-alpine yarn test

test-linux-aarch64-gnu-binding:
name: Test bindings on aarch64-unknown-linux-gnu - node@${{ matrix.node }}
Expand All @@ -274,7 +332,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node: ['10', '12', '14', '15']
node: ['12', '14', '16']
runs-on: ubuntu-20.04

steps:
Expand All @@ -292,38 +350,60 @@ jobs:
run: ls -R .
shell: bash

- uses: uraimo/run-on-arch-action@v2.0.9
name: Setup and run tests
id: runcmd
- name: Setup and run tests
uses: docker://multiarch/ubuntu-core:arm64-focal
with:
arch: aarch64
distro: ubuntu20.04

dockerRunArgs: |
--volume "${PWD}:/canvas"
-w /canvas
# Not required, but speeds up builds by storing container images in
# a GitHub package registry.
githubToken: ${{ github.token }}

install: |
apt-get update && \
apt-get install -y ca-certificates gnupg2 curl apt-transport-https && \
curl -sL https://deb.nodesource.com/setup_${{ matrix.node }}.x | bash - && \
apt-get install -y nodejs && \
npm install -g yarn
run: |
yarn install --ignore-scripts --registry https://registry.npmjs.org --network-timeout 300000
yarn test
ls -la
args: >
sh -c "
apt-get update && \
apt-get install -y ca-certificates gnupg2 curl apt-transport-https && \
curl -sL https://deb.nodesource.com/setup_${{ matrix.node }}.x | bash - && \
apt-get install -y nodejs && \
npm install -g yarn && \
yarn install --ignore-scripts --registry https://registry.npmjs.org --network-timeout 300000 && \
yarn test && \
ls -la
"
test-linux-aarch64-musl-binding:
name: Test bindings on aarch64-unknown-linux-musl - node@${{ matrix.node }}
needs:
- build

runs-on: ubuntu-20.04

steps:
- run: docker run --rm --privileged multiarch/qemu-user-static:register --reset

- uses: actions/checkout@v2

- name: Download artifacts
uses: actions/download-artifact@v2
with:
name: bindings-aarch64-unknown-linux-musl
path: .

- name: List packages
run: ls -R .
shell: bash

- name: Setup and run tests
uses: docker://multiarch/alpine:aarch64-latest-stable
with:
args: >
sh -c "
apk add nodejs npm && \
npm install -g yarn && \
yarn install --ignore-scripts --registry https://registry.npmjs.org --network-timeout 300000 && \
npm test
"
test-linux-arm-gnueabihf-binding:
name: Test bindings on armv7-unknown-linux-gnueabihf - node@${{ matrix.node }}
needs:
- build
strategy:
fail-fast: false
matrix:
node: ['10', '12', '14', '15']
node: ['12', '14', '16']
runs-on: ubuntu-20.04

steps:
Expand All @@ -341,30 +421,20 @@ jobs:
run: ls -R .
shell: bash

- uses: uraimo/run-on-arch-action@v2.0.9
name: Setup and run tests
id: runcmd
- name: Setup and run tests
uses: docker://multiarch/ubuntu-core:armhf-focal
with:
arch: armv7
distro: ubuntu20.04

dockerRunArgs: |
--volume "${PWD}:/canvas"
-w /canvas
# Not required, but speeds up builds by storing container images in
# a GitHub package registry.
githubToken: ${{ github.token }}

install: |
apt-get update && \
apt-get install -y ca-certificates gnupg2 curl apt-transport-https && \
curl -sL https://deb.nodesource.com/setup_${{ matrix.node }}.x | bash - && \
apt-get install -y nodejs && \
npm install -g yarn
run: |
yarn install --ignore-scripts --registry https://registry.npmjs.org --network-timeout 300000
yarn test
ls -la
args: >
sh -c "
apt-get update && \
apt-get install -y ca-certificates gnupg2 curl apt-transport-https && \
curl -sL https://deb.nodesource.com/setup_${{ matrix.node }}.x | bash - && \
apt-get install -y nodejs && \
npm install -g yarn && \
yarn install --ignore-scripts --registry https://registry.npmjs.org --network-timeout 300000 && \
yarn test && \
ls -la
"
publish:
name: Publish
runs-on: ubuntu-20.04
Expand All @@ -374,6 +444,8 @@ jobs:
- test-linux-aarch64-gnu-binding
- test-linux-arm-gnueabihf-binding
- test-macOS-windows-binding
- test-linux-aarch64-musl-binding
- build-freebsd

steps:
- uses: actions/checkout@v2
Expand All @@ -385,7 +457,7 @@ jobs:
check-latest: true

- name: Cache NPM dependencies
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: node_modules
key: npm-cache-ubuntu-latest-${{ hashFiles('yarn.lock') }}
Expand All @@ -403,7 +475,7 @@ jobs:
run: yarn artifacts

- name: List packages
run: ls -R .
run: ls -R ./npm
shell: bash

- name: Publish
Expand Down
Loading

0 comments on commit 1faf66c

Please sign in to comment.