Skip to content

Commit 114857b

Browse files
committed
use script to determine target
1 parent bee3fbc commit 114857b

File tree

3 files changed

+42
-17
lines changed

3 files changed

+42
-17
lines changed

.github/workflows/release.yaml

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,26 @@ jobs:
2424
- name: Install pnpm
2525
uses: pnpm/action-setup@v4
2626

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' }}
27+
- name: Install Linux Dependencies
28+
if: runner.os == 'Linux'
29+
run: sudo apt-get install -y aarch64-linux-gnu-gcc
3430

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_OUTPUT
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

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)