ci: add musl-cross toolchains into alpine.Dockerfile

This commit is contained in:
LongYinan 2021-07-21 23:46:45 +08:00
parent 27af46110c
commit 660dbddb67
No known key found for this signature in database
GPG key ID: C3666B7FC82ADAD7
7 changed files with 121 additions and 12 deletions

View file

@ -29,7 +29,7 @@ jobs:
uses: docker/build-push-action@v2 uses: docker/build-push-action@v2
with: with:
file: alpine.Dockerfile file: alpine.Dockerfile
platforms: linux/amd64,linux/arm64 platforms: linux/amd64
push: true push: true
tags: ghcr.io/${{ github.repository }}/nodejs-rust:lts-alpine tags: ghcr.io/${{ github.repository }}/nodejs-rust:lts-alpine

View file

@ -0,0 +1,89 @@
name: Linux-aarch64-musl
env:
DEBUG: 'napi:*'
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER: 'aarch64-linux-musl-gcc'
on:
push:
branches:
- main
pull_request:
jobs:
build:
name: stable - aarch64-unknown-linux-gnu - node@14
runs-on: ubuntu-20.04
steps:
- run: docker run --rm --privileged multiarch/qemu-user-static:register --reset
- uses: actions/checkout@v2
- name: Setup node
uses: actions/setup-node@v2
with:
node-version: 14
check-latest: true
- name: Install
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
- name: Install aarch64 toolchain
run: rustup target add aarch64-unknown-linux-gnu
- name: Generate Cargo.lock
uses: actions-rs/cargo@v1
with:
command: generate-lockfile
- name: Cache cargo registry
uses: actions/cache@v1
with:
path: ~/.cargo/registry
key: stable-linux-aarch64-gnu-node@14-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v1
with:
path: ~/.cargo/git
key: stable-linux-aarch64-gnu-node@14-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }}
- name: Cache NPM dependencies
uses: actions/cache@v1
with:
path: node_modules
key: npm-cache-linux-aarch64-gnu-node@14-${{ hashFiles('yarn.lock') }}
- name: Install dependencies
run: yarn install --frozen-lockfile --ignore-platform --registry https://registry.npmjs.org --network-timeout 300000
- name: 'Build TypeScript'
run: yarn build
- name: Pull docker image
run: |
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD $DOCKER_REGISTRY_URL
docker pull $DOCKER_REGISTRY_URL/${{ github.repository }}/nodejs-rust:lts-alpine
docker tag $DOCKER_REGISTRY_URL/${{ github.repository }}/nodejs-rust:lts-alpine builder
env:
DOCKER_REGISTRY_URL: ghcr.io
DOCKER_USERNAME: ${{ github.actor }}
DOCKER_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
- name: Cross build native tests
run: |
docker run -v ~/.cargo/git:/root/.cargo/git -v ~/.cargo/registry:/root/.cargo/registry -v $(pwd):/napi-rs -w /napi-rs -e CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=aarch64-linux-musl-gcc builder yarn --cwd ./test_module build --target aarch64-unknown-linux-musl
- name: Setup and run tests
uses: docker://multiarch/alpine:aarch64-latest-stable
with:
args: >
sh -c "
apk add nodejs yarn && \
yarn test
"

View file

@ -63,7 +63,7 @@ jobs:
run: sudo apt-get install gcc-9-aarch64-linux-gnu g++-9-aarch64-linux-gnu -y run: sudo apt-get install gcc-9-aarch64-linux-gnu g++-9-aarch64-linux-gnu -y
- name: Install dependencies - name: Install dependencies
run: yarn install --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000 run: yarn install --frozen-lockfile --ignore-platform --registry https://registry.npmjs.org --network-timeout 300000
- name: 'Build TypeScript' - name: 'Build TypeScript'
run: yarn build run: yarn build

View file

@ -63,7 +63,7 @@ jobs:
run: sudo apt-get install gcc-9-arm-linux-gnueabihf -y run: sudo apt-get install gcc-9-arm-linux-gnueabihf -y
- name: Install dependencies - name: Install dependencies
run: yarn install --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000 run: yarn install --frozen-lockfile --ignore-platform --registry https://registry.npmjs.org --network-timeout 300000
- name: 'Build TypeScript' - name: 'Build TypeScript'
run: yarn build run: yarn build

View file

@ -60,7 +60,7 @@ jobs:
key: npm-cache-${{ matrix.os }}-node@${{ matrix.node }}-${{ hashFiles('yarn.lock') }} key: npm-cache-${{ matrix.os }}-node@${{ matrix.node }}-${{ hashFiles('yarn.lock') }}
- name: 'Install dependencies' - name: 'Install dependencies'
run: yarn install --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000 run: yarn install --frozen-lockfile --ignore-platform --registry https://registry.npmjs.org --network-timeout 300000
- name: 'Build TypeScript' - name: 'Build TypeScript'
run: yarn build run: yarn build

View file

@ -1,11 +1,30 @@
FROM node:lts-alpine FROM node:lts-alpine
ENV RUSTFLAGS="-C target-feature=-crt-static" \ ENV PATH="/aarch64-linux-musl-cross/bin:/usr/local/cargo/bin/rustup:/root/.cargo/bin:$PATH" \
PATH="/usr/local/cargo/bin/rustup:/root/.cargo/bin:$PATH" \ RUSTFLAGS="-C target-feature=-crt-static" \
CC="clang" \ CC="clang" \
CXX="clang++" CXX="clang++" \
GN_EXE=gn
RUN sed -i -e 's/v[[:digit:]]\..*\//edge\//g' /etc/apk/repositories && \ RUN apk add --update --no-cache musl-dev && \
apk update && \ sed -i -e 's/v[[:digit:]]\..*\//edge\//g' /etc/apk/repositories && \
apk add rustup musl-dev build-base && \ apk add --update --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing \
rustup-init -y rustup \
bash \
python3 \
python2 \
git \
build-base \
wget \
clang \
llvm \
gn \
tar \
ninja
RUN rustup-init -y && \
yarn global add pnpm && \
rustup target add aarch64-unknown-linux-musl && \
wget https://musl.cc/aarch64-linux-musl-cross.tgz && \
tar -xvf aarch64-linux-musl-cross.tgz && \
rm aarch64-linux-musl-cross.tgz

View file

@ -3,7 +3,8 @@
"include": ["."], "include": ["."],
"compilerOptions": { "compilerOptions": {
"outDir": "./dist", "outDir": "./dist",
"rootDir": "__test__" "rootDir": "__test__",
"target": "ES2015"
}, },
"exclude": ["dist"] "exclude": ["dist"]
} }