Skip to content

Commit c691bd1

Browse files
authored
Fix musl builds (#149)
1 parent 1fdc022 commit c691bd1

File tree

11 files changed

+170
-349
lines changed

11 files changed

+170
-349
lines changed

.github/workflows/bump-version.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ jobs:
1818
uses: IronCoreLabs/workflows/.github/workflows/bump-version.yaml@bump-version-v1
1919
with:
2020
version: ${{ inputs.version }}
21-
release_mode: prerelease
21+
release_prereleases: false
2222
secrets: inherit

.github/workflows/publish.yaml

Lines changed: 37 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,11 @@
11
# Creates and publishes assets for a new release.
2-
# To manually trigger this workflow, create a release in the GitHub UI.
3-
42
name: Publish
53

64
on:
7-
# https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#release
85
release:
96
types:
10-
- created
11-
# workflow_dispatch is just for testing, and it won't fully work.
7+
- created # triggered by Bump Version creating a release
128
workflow_dispatch:
13-
inputs:
14-
name:
15-
description: fake version name
16-
required: true
17-
18-
env:
19-
# hack to get dynlibs working with musl
20-
# https://github.com/rust-lang/rust/pull/55163#issuecomment-436631090
21-
RUSTFLAGS: -C target-feature=-crt-static
229

2310
jobs:
2411
publish-github:
@@ -72,97 +59,50 @@ jobs:
7259
PRE_GYP_ARCH: ${{ matrix.system.pre_gyp_arch }}
7360
CARGO_BUILD_TARGET: ${{ matrix.system.target }}
7461
run: |
75-
node publish.js
62+
node build.js
7663
cd bin-package
7764
echo "asset=$(echo *.tar.gz)" >> "$GITHUB_OUTPUT"
7865
- name: Upload release asset
7966
run: gh release upload ${{ github.event.release.tag_name }}${{ github.event.inputs.name }} bin-package/${{ steps.build.outputs.asset }} --clobber
8067
env:
8168
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8269

83-
# The # WORKAROUND below doesn't work anymore, actions are forced to use a node20 runtime that doesn't work on alpine
84-
# publish-github-docker:
85-
# runs-on: ${{ matrix.os }}
86-
# container:
87-
# image: node:${{ matrix.node_version }}-alpine
88-
# strategy:
89-
# fail-fast: false
90-
# matrix:
91-
# node_version:
92-
# - 20
93-
# - 22
94-
# - 24
95-
# os:
96-
# - ubuntu-24.04
97-
# - ubuntu-24.04-arm
98-
# steps:
99-
# - run: apk add build-base git python3 wget github-cli
100-
# # WORKAROUND
101-
# # https://github.com/actions/runner/issues/801#issuecomment-1374967227
102-
# - run: |
103-
# apk add gcompat
104-
# sed -i "s:ID=alpine:ID=NotpineForGHA:" /etc/os-release
105-
# - uses: actions/checkout@v4
106-
# with:
107-
# ref: ${{ github.event.release.tag_name }}${{ github.event.inputs.name }}
108-
# - uses: c-hive/gha-yarn-cache@v2
109-
# - uses: actions-rs/toolchain@v1
110-
# with:
111-
# profile: minimal
112-
# toolchain: stable
113-
# override: true
114-
# - name: Install modules
115-
# run: yarn install --ignore-scripts
116-
# - name: Build
117-
# id: build
118-
# run: |
119-
# node publish.js
120-
# cd bin-package
121-
# echo "asset=$(echo *.tar.gz)" >> "$GITHUB_OUTPUT"
122-
# - name: Upload release asset
123-
# run: |
124-
# git config --global --add safe.directory $(pwd)
125-
# gh release upload ${{ github.event.release.tag_name }}${{ github.event.inputs.name }} bin-package/${{ steps.build.outputs.asset }} --clobber
126-
# env:
127-
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
70+
# Release musl binaries
71+
publish-github-docker:
72+
runs-on: ${{ matrix.os }}
73+
strategy:
74+
matrix:
75+
# These Node versions should match those above in the `publish-github` job.
76+
node_version:
77+
- 20
78+
- 22
79+
- 24
80+
os:
81+
- ubuntu-24.04
82+
- ubuntu-24.04-arm
83+
fail-fast: false
84+
steps:
85+
- uses: actions/checkout@v5
86+
- name: Build
87+
id: build
88+
run: docker build --build-arg NODE_VERSION=${{matrix.node_version}} --output type=local,dest=./host-artifacts .
89+
- name: Output
90+
run: |
91+
cd host-artifacts/out
92+
echo "asset=$(echo *.tar.gz)" >> "$GITHUB_OUTPUT"
93+
- name: Upload release asset
94+
run: |
95+
git config --global --add safe.directory $(pwd)
96+
gh release upload ${{ github.event.release.tag_name }}${{ github.event.inputs.name }} host-artifacts/out/${{ steps.build.outputs.asset }} --clobber
97+
env:
98+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
12899

129100
publish-npm:
130-
if: "${{ github.event.release.tag_name }}"
131101
needs:
132102
- publish-github
133-
# - publish-github-docker
134-
runs-on: ubuntu-24.04
135-
steps:
136-
- uses: actions/checkout@v5
137-
with:
138-
ref: ${{ github.event.release.tag_name }}
139-
- uses: actions/setup-node@v4
140-
with:
141-
node-version: 24
142-
cache: yarn
143-
- uses: actions-rs/toolchain@v1
144-
with:
145-
profile: minimal
146-
toolchain: stable
147-
override: true
148-
- name: Install modules
149-
run: yarn install --ignore-scripts
150-
- run: npm config set //registry.npmjs.org/:_authToken=$NPM_TOKEN
151-
env:
152-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
153-
- name: Publish NPM release
154-
run: |
155-
set -x
156-
# If it's not a simple 1.2.3 version, then it's a prerelease of some kind.
157-
if [[ ${{ github.event.release.tag_name }} =~ .*-.* ]] ; then
158-
PRE="--prerelease"
159-
fi
160-
node publish.js --publish "${PRE}"
161-
- name: Finalize GitHub release
162-
uses: ncipollo/release-action@v1
163-
with:
164-
token: ${{ secrets.WORKFLOW_PAT }}
165-
prerelease: ${{ contains(github.event.release.name, '-') }}
166-
allowUpdates: true
167-
tag: ${{ github.event.release.tag_name }}
168-
name: ${{ github.event.release.name }}
103+
- publish-github-docker
104+
uses: IronCoreLabs/workflows/.github/workflows/typescript-release.yaml@typescript-release-v1
105+
with:
106+
pre_publish_steps: "./build.js"
107+
publish_working_directory: "dist"
108+
secrets: inherit

.github/workflows/typescript-napi-ci.yaml

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ jobs:
1515
matrix:
1616
rust_version:
1717
- stable
18-
# Uncomment after Rust 1.90.0 comes out: https://github.com/rust-lang/rust/issues/145699
19-
# - beta
18+
- beta
19+
# These should match those in the `docker-test` job
2020
node_version:
2121
- 20
2222
- 22
@@ -54,35 +54,15 @@ jobs:
5454
run: yarn run compile
5555
- name: Run tests
5656
run: yarn run test
57-
58-
# broken now that node20 is forced even for checkout@v3, which doesn't work using the # WORKAROUND below any more.
59-
# test-docker:
60-
# runs-on: ${{ matrix.os }}
61-
# container:
62-
# image: node:${{ matrix.node_version }}-alpine
63-
# strategy:
64-
# matrix:
65-
# rust_version:
66-
# - stable
67-
# - beta
68-
# node_version:
69-
# - 20
70-
# - 22
71-
# - 24
72-
# os:
73-
# - ubuntu-24.04
74-
# - ubuntu-24.04-arm
75-
# fail-fast: false
76-
# steps:
77-
# - run: apk add build-base git python3 wget
78-
# - run: echo RUSTFLAGS="-C target-feature=-crt-static" >> "${GITHUB_ENV}"
79-
# - uses: actions/checkout@v5
80-
# - uses: IronCoreLabs/rust-toolchain@v1
81-
# with:
82-
# toolchain: ${{ matrix.rust_version }}
83-
# - name: Install modules
84-
# run: yarn install --ignore-scripts
85-
# - name: Compile
86-
# run: yarn run compile
87-
# - name: Run tests
88-
# run: yarn run test
57+
58+
# Used to create musl binaries
59+
docker-test:
60+
runs-on: ${{ matrix.os }}
61+
strategy:
62+
matrix:
63+
os: [ubuntu-24.04, ubuntu-24.04-arm]
64+
fail-fast: false
65+
steps:
66+
- uses: actions/checkout@v5
67+
# These Node versions should match those above in the `test` job.
68+
- run: for NODE_VERSION in 20 22 24; do docker build --build-arg NODE_VERSION=$NODE_VERSION .; done

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ target
88
artifacts.json
99
dist/*
1010
bin-package/*
11+
host-artifacts/*
1112
build/*
1213
.idea/*
1314
.direnv

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 0.11.1
2+
3+
### Changes
4+
5+
- Fix build process issues preventing musl releases.
6+
17
## 0.11.0
28

39
### Changes

Dockerfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# This Dockerfile produces a musl binary for recrypt-node-binding.
2+
# It can be built with this command to copy the result out into ./host-artifacts/out
3+
# docker build --build-arg NODE_VERSION=24 --output type=local,dest=./host-artifacts .
4+
5+
ARG NODE_VERSION=24
6+
FROM node:${NODE_VERSION}-alpine3.22 AS build
7+
8+
RUN apk add --no-cache \
9+
build-base \
10+
rust \
11+
cargo
12+
COPY . /app
13+
WORKDIR /app
14+
RUN yarn install
15+
RUN node build.js
16+
17+
FROM scratch AS artifacts
18+
WORKDIR /out
19+
COPY --from=build /app/bin-package ./

RELEASING.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
Release Checklist
2-
=================
1+
# Release Checklist
32

4-
* Decide on the new version number and write the CHANGELOG.md entry for the release by looking at the PRs.
5-
* Commit the `CHANGELOG.md`.
6-
* Update to the new version number using the [Bump Version](https://github.com/IronCoreLabs/recrypt-node-binding/actions/workflows/bump-version.yaml) workflow. This will be used as the NPM version number.
7-
* The [Publish](https://github.com/IronCoreLabs/recrypt-node-binding/actions/workflows/publish.yaml) action will automatically publish the release to NPM.
8-
* Find the release on the [releases](https://github.com/IronCoreLabs/recrypt-node-binding/releases) page, edit it, and mark it
9-
as NOT a prerelease.
3+
- PR and merge the `CHANGELOG.md` entry for the release by looking at the commits.
4+
- Decide on the new version number and run the [Bump Version](https://github.com/IronCoreLabs/recrypt-node-binding/actions/workflows/bump-version.yaml) action. This will create a GitHub release and trigger the Typescript Release action.

publish.js renamed to build.js

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
22

33
/**
4-
* recrypt-node-binding NPM publish script
4+
* recrypt-node-binding NPM build script
55
* ==================================
66
*
77
* This script is responsible for compiling and building the NPM release bundle for this repo. The following steps are taken:
@@ -11,8 +11,7 @@
1111
* + Compile rust code into index.node file.
1212
* + Run unit tests to ensure the library is in good shape for publishing.
1313
* + Move all expected content into a `dist` directory.
14-
* + Generate a binary distrubtion in `bin-package`.
15-
* + Do a dry run of npm publishing via irish-pub or perform an actual publish step if `--publish` option is provided.
14+
* + Generate a binary distribution in `bin-package`.
1615
*/
1716

1817
const fs = require("fs");
@@ -24,7 +23,6 @@ shell.set("-e");
2423
//Ensure that our directory is set to the root of the repo
2524
const rootDirectory = path.dirname(process.argv[1]);
2625
shell.cd(rootDirectory);
27-
const shouldPublish = process.argv.slice(2).indexOf("--publish") !== -1;
2826
const isPreRelease = process.argv.slice(2).indexOf("--prerelease") !== -1;
2927

3028
// Cleanup any previous Rust builds, update deps, and compile
@@ -61,17 +59,4 @@ const replacementPlatform = process.env.PRE_GYP_PLATFORM ? `--target_platform=${
6159
shell.exec(`${cwd}/node_modules/@mapbox/node-pre-gyp/bin/node-pre-gyp package ${replacementArch} ${replacementPlatform}`);
6260
var tgz = shell.exec("find ./build -name *.tar.gz");
6361
shell.cp(tgz, "./bin-package/");
64-
shell.pushd("./dist");
65-
66-
var publishCmd = "echo 'Skipping publishing to npm...'"
67-
if (shouldPublish) {
68-
publishCmd = "npm publish --access public";
69-
// If we're publishing a branch build or prerelease like "1.2.3-pre.4", use "--tag next".
70-
if (isPreRelease) {
71-
publishCmd += " --tag next";
72-
}
73-
}
74-
shell.exec(publishCmd);
75-
shell.popd();
76-
77-
shell.echo("publish.js COMPLETE");
62+
shell.echo("build.js COMPLETE");

index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
/**
44
* WARNING!
5-
*
5+
*
66
* This file is the bridge between the generated Rust binary and the JavaScript interface users call into.
7-
*
8-
* This file is not generated. Any changes made in the Rust code will need to be propogated out here, either by adding
7+
*
8+
* This file is not generated. Any changes made in the Rust code will need to be propagated out here, either by adding
99
* bare functions to the export declaration at the bottom, or by adding new methods to the Api256 class.
10-
*
10+
*
1111
* The `index.d.ts` file is also manually maintained, add any new signatures to it.
12-
*/
12+
*/
1313

1414
const internal = require("./bin-package/index.node");
1515

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@
2727
"compile": "cargo-cp-artifact -a cdylib recrypt_node ./bin-package/index.node -- cargo build --release --message-format=json-render-diagnostics",
2828
"clean": "cargo clean && rm -rf dist && rm -rf bin-package && rm -rf build",
2929
"benchmark": "node benchmark/index.js",
30-
"test": "jest --maxWorkers=50%"
30+
"test": "jest --maxWorkers=50%",
31+
"prepublishOnly": "[ ! -f Cargo.toml ] || (echo \"Cargo.toml mistakenly found. Ensure you're publishing from ./dist.\" && exit 1)"
3132
},
3233
"dependencies": {
33-
"@mapbox/node-pre-gyp": "^1.0.7"
34+
"@mapbox/node-pre-gyp": "^2.0.0"
3435
},
3536
"devDependencies": {
3637
"@types/node": "^16.11.11",

0 commit comments

Comments
 (0)