Skip to content

Commit 275aa58

Browse files
committed
switch to script to determine target
1 parent bee3fbc commit 275aa58

File tree

3 files changed

+71
-22
lines changed

3 files changed

+71
-22
lines changed

.github/workflows/release.yaml

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
name: Build And Release
22

3-
on: [workflow_dispatch, push]
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
48

59
jobs:
610
Build:
@@ -24,31 +28,22 @@ jobs:
2428
- name: Install pnpm
2529
uses: pnpm/action-setup@v4
2630

27-
# linux
28-
- name: Install Rust
29-
if: ${{ matrix.os == 'ubuntu-latest' }}
30-
uses: dtolnay/rust-toolchain@master
31-
with:
32-
toolchain: stable
33-
targets: ${{ matrix.arch == 'arm64' && 'aarch64-unknown-linux-gnu' || 'x86_64-unknown-linux-gnu' }}
34-
35-
# macos
36-
- name: Install Rust
37-
if: ${{ matrix.os == 'macos-latest' }}
38-
uses: dtolnay/rust-toolchain@master
39-
with:
40-
toolchain: stable
41-
targets: ${{ matrix.arch == 'arm64' && 'aarch64-apple-darwin' || 'x86_64-apple-darwin' }}
31+
- name: Get Target Name
32+
id: get_target
33+
env:
34+
npm_config_arch: ${{ matrix.arch }}
35+
run: |
36+
echo "target_name=$(node ./utils/getTarget.js)" >> $GITHUB_ENV
4237
43-
# windows
4438
- name: Install Rust
45-
if: ${{ matrix.os == 'windows-latest' }}
4639
uses: dtolnay/rust-toolchain@master
4740
with:
4841
toolchain: stable
49-
targets: ${{ matrix.arch == 'arm64' && 'aarch64-pc-windows-msvc' || 'x86_64-pc-windows-msvc' }}
42+
targets: ${{ steps.get_target.outputs.target_name }}
5043

5144
- name: Building
45+
env:
46+
npm_config_arch: ${{ matrix.arch }}
5247
run: pnpm install
5348

5449
- name: Uploading
@@ -68,6 +63,12 @@ jobs:
6863
with:
6964
submodules: true
7065

66+
- name: Update npm
67+
run: npm install -g npm@latest
68+
69+
- name: Install pnpm
70+
uses: pnpm/action-setup@v4
71+
7172
- name: Download Artifacts
7273
uses: actions/download-artifact@v3
7374

@@ -78,8 +79,26 @@ jobs:
7879
rm -rf bin-*
7980
sudo chmod -R +x bin
8081
82+
- name: Verify Binaries
83+
run: |
84+
// make sure all binaries are present
85+
if [ ! -f bin/dump-syms-linux-x64 ]; then echo "Missing bin/dump-syms-linux-x64" && exit 1; fi
86+
if [ ! -f bin/dump-syms-linux-arm64 ]; then echo "Missing bin/dump-syms-linux-arm64" && exit 1; fi
87+
if [ ! -f bin/dump-syms-macos-x64 ]; then echo "Missing bin/dump-syms-macos-x64" && exit 1; fi
88+
if [ ! -f bin/dump-syms-macos-arm64 ]; then echo "Missing bin/dump-syms-macos-arm64" && exit 1; fi
89+
if [ ! -f bin/dump-syms-windows-x64.exe ]; then echo "Missing bin/dump-syms-windows-x64.exe" && exit 1; fi
90+
if [ ! -f bin/dump-syms-windows-arm64.exe ]; then echo "Missing bin/dump-syms-windows-arm64.exe" && exit 1; fi
91+
92+
- name: Verify Version
93+
run: |
94+
TAG_VERSION=${GITHUB_REF#refs/tags/v}
95+
PACKAGE_VERSION=$(node -p "require('./package.json').version")
96+
if [ "$TAG_VERSION" != "$PACKAGE_VERSION" ]; then
97+
echo "Tag version ($TAG_VERSION) does not match package.json version ($PACKAGE_VERSION)"
98+
exit 1
99+
fi
100+
81101
# this will only publish if the version has been updated
82102
- name: NPM Publish
83-
uses: JS-DevTools/[email protected]
84-
with:
85-
token: ${{secrets.NPM_TOKEN}}
103+
run: |
104+
npm publish

build.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const path = require('path');
33
const { promises: fs, constants } = require('fs');
44
const { promisify } = require('util');
55
const execFile = promisify(require('child_process').execFile);
6+
const getTarget = require('./utils/getTarget');
67

78
const { spawn, paths, exists } = require('./shared');
89

@@ -15,8 +16,13 @@ const { spawn, paths, exists } = require('./shared');
1516
await fs.mkdir(paths.bin, { recursive: true });
1617
}
1718

19+
// I don't think we can cross-compile platforms easily?
20+
const target_arch = process.env.npm_config_arch || process.arch;
21+
const target = getTarget(process.platform, target_arch);
22+
1823
await spawn('cargo', [
1924
'build',
25+
`--target=${target}`,
2026
`--manifest-path=${path.join(paths.submodule, 'Cargo.toml')}`,
2127
`--target-dir=${paths.build}`,
2228
'--release'

utils/getTarget.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
const getTarget = (platform, arch) => {
3+
let target = '';
4+
5+
if (platform === 'linux') {
6+
target += arch === 'arm64' ? 'aarch64-unknown-linux-gnu' : 'x86_64-unknown-linux-gnu';
7+
} else if (platform === 'darwin') {
8+
target += arch === 'arm64' ? 'aarch64-apple-darwin' : 'x86_64-apple-darwin';
9+
} else if (platform === 'win32') {
10+
target += arch === 'arm64' ? 'aarch64-pc-windows-msvc' : 'x86_64-pc-windows-msvc';
11+
} else {
12+
throw new Error(`Unsupported platform: ${platform}`);
13+
}
14+
15+
return target;
16+
};
17+
18+
module.exports = getTarget;
19+
20+
if (require.main === module) {
21+
const arch = process.env.npm_config_arch || process.arch;
22+
const target = getTarget(process.platform, arch);
23+
console.log(target);
24+
}

0 commit comments

Comments
 (0)