Skip to content

Commit ac9f766

Browse files
committed
Review Feedabck
Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>
1 parent 8797ef1 commit ac9f766

5 files changed

Lines changed: 80 additions & 6 deletions

File tree

.github/workflows/npm-publish.yml

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ jobs:
4545
- target: x86_64-unknown-linux-gnu
4646
os: [self-hosted, Linux, X64, "1ES.Pool=hld-kvm-amd"]
4747
build_name: linux-x64-gnu
48+
- target: x86_64-unknown-linux-musl
49+
os: [self-hosted, Linux, X64, "1ES.Pool=hld-kvm-amd"]
50+
build_name: linux-x64-musl
4851
- target: x86_64-pc-windows-msvc
4952
os: [self-hosted, Windows, X64, "1ES.Pool=hld-win2022-amd"]
5053
build_name: win32-x64-msvc
@@ -76,9 +79,17 @@ jobs:
7679
run: |
7780
npm version ${{ inputs.version }} --no-git-tag-version --allow-same-version
7881
82+
- name: Install musl tools
83+
if: contains(matrix.target, 'musl')
84+
run: sudo apt-get update && sudo apt-get install -y musl-tools
85+
86+
- name: Add musl Rust target
87+
if: contains(matrix.target, 'musl')
88+
run: rustup target add x86_64-unknown-linux-musl
89+
7990
- name: Build native module
8091
working-directory: ${{ env.WORKING_DIR }}
81-
run: npm run build
92+
run: npm run build -- --target ${{ matrix.target }}
8293

8394
- name: Upload artifact
8495
uses: actions/upload-artifact@v8
@@ -105,12 +116,18 @@ jobs:
105116
working-directory: ${{ env.WORKING_DIR }}
106117
run: npm ci --ignore-scripts --omit=optional
107118

108-
- name: Download Linux artifact
119+
- name: Download Linux GNU artifact
109120
uses: actions/download-artifact@v8
110121
with:
111122
name: bindings-linux-x64-gnu
112123
path: ${{ env.WORKING_DIR }}/artifacts/linux-x64-gnu
113124

125+
- name: Download Linux musl artifact
126+
uses: actions/download-artifact@v8
127+
with:
128+
name: bindings-linux-x64-musl
129+
path: ${{ env.WORKING_DIR }}/artifacts/linux-x64-musl
130+
114131
- name: Download Windows artifact
115132
uses: actions/download-artifact@v8
116133
with:
@@ -125,8 +142,10 @@ jobs:
125142
run: |
126143
# Rename artifacts to match napi-rs naming convention
127144
mv artifacts/linux-x64-gnu/*.node npm/linux-x64-gnu/js-host-api.linux-x64-gnu.node
145+
mv artifacts/linux-x64-musl/*.node npm/linux-x64-musl/js-host-api.linux-x64-musl.node
128146
mv artifacts/win32-x64-msvc/*.node npm/win32-x64-msvc/js-host-api.win32-x64-msvc.node
129147
ls -la npm/linux-x64-gnu/
148+
ls -la npm/linux-x64-musl/
130149
ls -la npm/win32-x64-msvc/
131150
132151
- name: Set package versions
@@ -137,6 +156,7 @@ jobs:
137156
138157
# Update platform package versions
139158
cd npm/linux-x64-gnu && npm version ${{ inputs.version }} --no-git-tag-version --allow-same-version
159+
cd ../linux-x64-musl && npm version ${{ inputs.version }} --no-git-tag-version --allow-same-version
140160
cd ../win32-x64-msvc && npm version ${{ inputs.version }} --no-git-tag-version --allow-same-version
141161
142162
- name: Update optionalDependencies versions
@@ -162,13 +182,20 @@ jobs:
162182
npx napi prepublish -t npm --skip-gh-release
163183
ls -la index.js index.d.ts
164184
165-
- name: Publish Linux package
185+
- name: Publish Linux GNU package
166186
if: ${{ !inputs.dry-run }}
167187
working-directory: ${{ env.WORKING_DIR }}/npm/linux-x64-gnu
168188
run: npm publish --access public
169189
env:
170190
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
171191

192+
- name: Publish Linux musl package
193+
if: ${{ !inputs.dry-run }}
194+
working-directory: ${{ env.WORKING_DIR }}/npm/linux-x64-musl
195+
run: npm publish --access public
196+
env:
197+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
198+
172199
- name: Publish Windows package
173200
if: ${{ !inputs.dry-run }}
174201
working-directory: ${{ env.WORKING_DIR }}/npm/win32-x64-msvc
@@ -192,6 +219,9 @@ jobs:
192219
echo "--- @hyperlight/js-host-api-linux-x64-gnu ---"
193220
npm pack ./npm/linux-x64-gnu --dry-run
194221
echo ""
222+
echo "--- @hyperlight/js-host-api-linux-x64-musl ---"
223+
npm pack ./npm/linux-x64-musl --dry-run
224+
echo ""
195225
echo "--- @hyperlight/js-host-api-win32-x64-msvc ---"
196226
npm pack ./npm/win32-x64-msvc --dry-run
197227
echo ""

src/js-host-api/README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -634,10 +634,19 @@ To create an npm token:
634634

635635
### Package Structure
636636

637-
The npm release consists of three packages:
637+
The npm release consists of the following packages:
638638

639639
| Package | Description |
640640
|---------|-------------|
641641
| `@hyperlight/js-host-api` | Main package (installs correct binary automatically) |
642-
| `@hyperlight/js-host-api-linux-x64-gnu` | Linux x86_64 native binary |
642+
| `@hyperlight/js-host-api-linux-x64-gnu` | Linux x86_64 (glibc) native binary |
643+
| `@hyperlight/js-host-api-linux-x64-musl` | Linux x86_64 (musl/Alpine) native binary |
643644
| `@hyperlight/js-host-api-win32-x64-msvc` | Windows x86_64 native binary |
645+
646+
### How Platform Selection Works
647+
648+
This project uses the [napi-rs](https://napi.rs/docs/deep-dive/release#3-the-native-addon-for-different-platforms-is-distributed-through-different-npm-packages) approach for distributing native addons across platforms. Each platform-specific binary is published as a separate npm package and listed as an `optionalDependency` of the main package.
649+
650+
**At install time:** npm uses the `os`, `cpu`, and `libc` fields in each platform sub-package's `package.json` to determine which optional dependency to install. Packages that don't match the user's platform are silently skipped. The main package itself does **not** have `os`/`cpu` fields because it contains only JavaScript — restricting it would prevent installation on unsupported platforms even for type-checking or development purposes.
651+
652+
**At runtime:** The napi-rs generated `index.js` detects the platform (including glibc vs musl on Linux) and loads the correct `.node` binary.

src/js-host-api/npm/linux-x64-gnu/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,8 @@
2323
},
2424
"engines": {
2525
"node": ">= 18"
26-
}
26+
},
27+
"libc": [
28+
"glibc"
29+
]
2730
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "@hyperlight/js-host-api-linux-x64-musl",
3+
"version": "0.17.0",
4+
"os": [
5+
"linux"
6+
],
7+
"cpu": [
8+
"x64"
9+
],
10+
"main": "js-host-api.linux-x64-musl.node",
11+
"files": [
12+
"js-host-api.linux-x64-musl.node"
13+
],
14+
"description": "Node.js API bindings for Hyperlight JS - Linux x64 musl",
15+
"license": "Apache-2.0",
16+
"repository": {
17+
"type": "git",
18+
"url": "git+https://github.com/hyperlight-dev/hyperlight-js.git"
19+
},
20+
"homepage": "https://github.com/hyperlight-dev/hyperlight-js#readme",
21+
"bugs": {
22+
"url": "https://github.com/hyperlight-dev/hyperlight-js/issues"
23+
},
24+
"engines": {
25+
"node": ">= 18"
26+
},
27+
"libc": [
28+
"musl"
29+
]
30+
}

src/js-host-api/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616
"binaryName": "js-host-api",
1717
"targets": [
1818
"x86_64-unknown-linux-gnu",
19+
"x86_64-unknown-linux-musl",
1920
"x86_64-pc-windows-msvc"
2021
]
2122
},
2223
"license": "Apache-2.0",
2324
"optionalDependencies": {
2425
"@hyperlight/js-host-api-linux-x64-gnu": "0.17.0",
26+
"@hyperlight/js-host-api-linux-x64-musl": "0.17.0",
2527
"@hyperlight/js-host-api-win32-x64-msvc": "0.17.0"
2628
},
2729
"devDependencies": {

0 commit comments

Comments
 (0)