Skip to content

Commit b4d8e37

Browse files
committed
build in binary
1 parent ecb5290 commit b4d8e37

File tree

3 files changed

+23
-63
lines changed

3 files changed

+23
-63
lines changed

.github/workflows/build.yaml

Lines changed: 15 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jobs:
6161
run: git diff --exit-code ./docs/README.md
6262

6363
binary:
64-
name: binary for ${{ matrix.name }}
64+
name: ${{ matrix.name }}
6565
if: github.event_name == 'push' || github.event_name == 'pull_request' || (github.event_name == 'release' && startsWith(github.event.release.tag_name, 'hive-router-v'))
6666
runs-on: ${{ matrix.action_runner }}
6767
strategy:
@@ -111,11 +111,23 @@ jobs:
111111
run: cargo build --release --target ${{ matrix.rust_target }}
112112
if: ${{ !matrix.zigbuild }}
113113

114+
# napi build will use zigbuild when cross compiling
115+
- name: node-addon build (${{ matrix.rust_target }})
116+
working-directory: lib/node-addon
117+
env:
118+
CROSS_COMPILE: ${{ matrix.zigbuild }}
119+
TARGET: ${{ matrix.rust_target }}
120+
run: |
121+
npm ci
122+
npm run build
123+
114124
- uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
115125
name: upload build artifact
116126
with:
117127
name: hive_router_${{ matrix.name }}
118-
path: target/${{ matrix.rust_target }}/release/${{ env.BINARY_NAME }}
128+
path: |
129+
target/${{ matrix.rust_target }}/release/${{ env.BINARY_NAME }}
130+
lib/node-addon/${{ env.BINARY_NAME }}.*.node
119131
if-no-files-found: error
120132
- name: Upload binaries to release
121133
uses: svenstaro/upload-release-action@81c65b7cd4de9b2570615ce3aad67a41de5b1a13 # v2
@@ -125,57 +137,12 @@ jobs:
125137
file: target/${{ matrix.rust_target }}/release/${{ env.BINARY_NAME }}
126138
asset_name: hive_router_${{ matrix.name }}
127139
tag: ${{ github.ref }}
128-
129-
node-addon:
130-
name: node-addon for ${{ matrix.name }}
131-
if: github.event_name == 'push' || github.event_name == 'pull_request' || (github.event_name == 'release' && startsWith(github.event.release.tag_name, 'hive-router-v'))
132-
runs-on: ${{ matrix.action_runner }}
133-
strategy:
134-
fail-fast: false # TODO: linux arm build fails
135-
matrix:
136-
include:
137-
- name: linux_arm64
138-
rust_target: aarch64-unknown-linux-gnu
139-
action_runner: ubuntu-latest
140-
- name: linux_amd64
141-
rust_target: x86_64-unknown-linux-gnu
142-
action_runner: ubuntu-latest
143-
- name: macos_arm64
144-
rust_target: aarch64-apple-darwin
145-
action_runner: macos-15
146-
- name: macos_amd64
147-
rust_target: x86_64-apple-darwin
148-
action_runner: macos-15
149-
steps:
150-
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
151-
name: checkout
152-
- uses: actions-rust-lang/setup-rust-toolchain@1780873c7b576612439a134613cc4cc74ce5538c # v1
153-
name: rust toolchain (${{ matrix.rust_target }})
154-
with:
155-
target: ${{ matrix.rust_target }}
156-
cache-key: ${{ matrix.name }}
157-
- name: napi-rs build (${{ matrix.rust_target }})
158-
working-directory: lib/node-addon
159-
env:
160-
TARGET: ${{ matrix.rust_target }}
161-
run: |
162-
npm ci
163-
npm run build
164-
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
165-
name: upload build artifact
166-
with:
167-
name: hive_router_${{ matrix.name }}
168-
# TODO: we dont use matrix.rust_target because napi-rs target is differenty named on output
169-
path: lib/node-addon/${{ env.BINARY_NAME }}.*.node
170-
if-no-files-found: error
171-
- name: Upload binaries to release
140+
- name: Upload node addons to release
172141
uses: svenstaro/upload-release-action@81c65b7cd4de9b2570615ce3aad67a41de5b1a13 # v2
173142
if: ${{ github.event_name == 'release' }}
174143
with:
175144
repo_token: ${{ secrets.GITHUB_TOKEN }}
176-
# TODO: we dont use matrix.rust_target because napi-rs target is differenty named on output
177145
file: lib/node-addon/${{ env.BINARY_NAME }}.*.node
178-
asset_name: hive_router_${{ matrix.name }}
179146
tag: ${{ github.ref }}
180147

181148
docker:

lib/node-addon/build.js

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,16 @@ import fs from "node:fs/promises";
33

44
const cli = new NapiCli();
55

6-
const release = process.env["RELEASE"] === "1";
6+
const release = process.env["RELEASE"] === "true";
7+
const crossCompile = process.env["CROSS_COMPILE"] === "true";
78

89
(async function build() {
910
const target = process.env["TARGET"];
10-
if (release) {
11-
console.log(
12-
`Building node-addon in release mode for ${
13-
target || "current os and arch"
14-
}...`
15-
);
16-
} else {
17-
console.log(
18-
`Building node-addon in debug mode for ${
19-
target || "current os and arch"
20-
}...`
21-
);
22-
}
11+
console.log(
12+
`Building node-addon in ${release ? "release" : "debug"} mode for ${
13+
target || "current os and arch"
14+
} ${crossCompile ? " with cross compile " : ""}...`
15+
);
2316
const { task } = await cli.build({
2417
release,
2518
platform: true,

lib/node-addon/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"bun": "^1"
2424
},
2525
"scripts": {
26-
"build": "RELEASE=1 node build.js",
26+
"build": "RELEASE=true node build.js",
2727
"build:debug": "node build.js",
2828
"test": "node tests",
2929
"test:updatesnaps": "node --test-update-snapshots tests"

0 commit comments

Comments
 (0)