Skip to content

Commit

Permalink
First pass at adding arm64 to the build. (#77)
Browse files Browse the repository at this point in the history
* First pass at adding arm64 to the build.

Both node-pre-gyp and rust need different platform and architecture
arguments since we have to cross compile. There aren't currently M1
action runners available to do this natively.

Uses rust-toolchain to set the default to the current matrix option,
need to make sure that works and that the linker used doesn't get messed
up for musl builds for ex.

* Might be a better matrix setup

* Forgot to alter runs-on for docker-test

* Didn't patch :/

* :/
  • Loading branch information
skeet70 authored Jan 15, 2022
1 parent c25eb5b commit 3ba5812
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 37 deletions.
34 changes: 22 additions & 12 deletions .github/typescript-ci-patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,29 @@
- op: replace
path: /jobs/test/strategy/matrix
value:
node_version:
- "12"
- "14"
- "16"
rust_version:
rust_version:
- 1.56.0
- stable
- beta
os:
- macos-10.15
- ubuntu-20.04
- windows-2019
node_version:
- 12
- 14
- 16
system:
- os: macos-10.15
target: x86_64-apple-darwin
- os: macos-11
target: aarch64-apple-darwin
- os: ubuntu-20.04
target: x86_64-unknown-linux-gnu
- os: windows-2019
target: x86_64-pc-windows-msvc
- op: add
path: /jobs/test/strategy/fail-fast
value: false
- op: replace
path: /jobs/test/runs-on
value: "${{ matrix.os }}"
value: "${{ matrix.system.os }}"

# These steps are lifted from the Rust CI workflow, cargo-test job.
- op: add
Expand All @@ -44,17 +49,22 @@
# Only check coverage in one of the matrix job instances.
- op: add
path: /jobs/test/steps/6/if
value: ${{ contains(matrix.os, 'ubuntu') && matrix.node_version == '16' && matrix.rust_version == 'stable' && github.base_ref != '' }}
value: ${{ contains(matrix.system.os, 'ubuntu') && matrix.node_version == '16' && matrix.rust_version == 'stable' && github.base_ref != '' }}

# Also run on musl. That means we need to run it in a Docker container. To do that, we copy the entire job and modify its
# strategy/matrix.
- op: copy
from: /jobs/test
path: /jobs/test-docker
- op: replace
- op: remove
path: /jobs/test-docker/strategy/matrix/system
- op: add
path: /jobs/test-docker/strategy/matrix/os
value:
- ubuntu-20.04
- op: replace
path: /jobs/test-docker/runs-on
value: "${{ matrix.os }}"
- op: add
path: /jobs/test-docker/container
value:
Expand Down
29 changes: 21 additions & 8 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,26 @@ env:

jobs:
publish-github:
runs-on: ${{ matrix.os }}
runs-on: ${{ matrix.system.os }}
strategy:
fail-fast: false
matrix:
node_version:
- '12'
- '14'
- '16'
os:
- macos-10.15
- ubuntu-20.04
- windows-2019
- 12
- 14
- 16
system:
- os: macos-10.15
target: x86_64-apple-darwin
- os: macos-11
target: aarch64-apple-darwin
# only needed in this case, where we're cross compiling until runners with m1 chips exist
pre_gyp_platform: darwin
pre_gyp_arch: arm64
- os: ubuntu-20.04
target: x86_64-unknown-linux-gnu
- os: windows-2019
target: x86_64-pc-windows-msvc
steps:
- uses: actions/checkout@v2
with:
Expand All @@ -40,13 +48,18 @@ jobs:
with:
profile: minimal
toolchain: stable
target: ${{ matrix.system.target }}
default: true
override: true
- name: Install modules
run: yarn install --ignore-scripts
- name: Build
id: build
# Use bash, even on Windows.
shell: bash
env:
PRE_GYP_PLATFORM: ${{ matrix.system.pre_gyp_platform }}
PRE_GYP_ARCH: ${{ matrix.system.pre_gyp_arch }}
run: |
node publish.js
cd bin-package
Expand Down
35 changes: 20 additions & 15 deletions .github/workflows/typescript-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,26 @@ name: TypeScript CI
workflow_dispatch: null
jobs:
test:
runs-on: ${{ matrix.os }}
runs-on: ${{ matrix.system.os }}
strategy:
matrix:
node_version:
- '12'
- '14'
- '16'
rust_version:
- 1.56.0
- stable
- beta
os:
- macos-10.15
- ubuntu-20.04
- windows-2019
node_version:
- 12
- 14
- 16
system:
- os: macos-10.15
target: x86_64-apple-darwin
- os: macos-11
target: aarch64-apple-darwin
- os: ubuntu-20.04
target: x86_64-unknown-linux-gnu
- os: windows-2019
target: x86_64-pc-windows-msvc
fail-fast: false
steps:
- uses: actions/checkout@v2
Expand All @@ -45,8 +50,8 @@ jobs:
- name: Run tests
run: yarn run test
- name: Check test coverage
if: ${{ contains(matrix.os, 'ubuntu') && matrix.node_version == '16' && matrix.rust_version
== 'stable' && github.base_ref != '' }}
if: ${{ contains(matrix.system.os, 'ubuntu') && matrix.node_version == '16'
&& matrix.rust_version == 'stable' && github.base_ref != '' }}
uses: anuraag016/[email protected]
with:
fullCoverageDiff: false
Expand All @@ -56,14 +61,14 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node_version:
- '12'
- '14'
- '16'
rust_version:
- 1.56.0
- stable
- beta
node_version:
- 12
- 14
- 16
os:
- ubuntu-20.04
fail-fast: false
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"win32"
],
"cpu": [
"x64"
"x64",
"arm64"
],
"scripts": {
"compile": "cargo-cp-artifact -a cdylib recrypt_node ./bin-package/index.node -- cargo build --release --message-format=json-render-diagnostics",
Expand Down
4 changes: 3 additions & 1 deletion publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ fs.writeFileSync("./dist/package.json", JSON.stringify(npmPackageJson, null, 2))

//Use a fully qualified path to pre-gyp binary for Windows support
const cwd = shell.pwd().toString();
shell.exec(`${cwd}/node_modules/@mapbox/node-pre-gyp/bin/node-pre-gyp package`);
const replacementArch = process.env.PRE_GYP_ARCH ? `--target_arch=${process.env.PRE_GYP_ARCH}` : "";
const replacementPlatform = process.env.PRE_GYP_PLATFORM ? `--target_platform=${process.env.PRE_GYP_PLATFORM}` : "";
shell.exec(`${cwd}/node_modules/@mapbox/node-pre-gyp/bin/node-pre-gyp package ${replacementArch} ${replacementPlatform}`);
var tgz = shell.exec("find ./build -name *.tar.gz");
shell.cp(tgz, "./bin-package/");
shell.pushd("./dist");
Expand Down

0 comments on commit 3ba5812

Please sign in to comment.