Skip to content

Commit 86eedcb

Browse files
authored
Merge pull request #59 from gf3/binary-install
feat: offer pre-built binaries by default
2 parents 1f37b3c + eeaf2d2 commit 86eedcb

File tree

6 files changed

+517
-56
lines changed

6 files changed

+517
-56
lines changed

.github/workflows/tests.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@ jobs:
1111
name: Node ${{ matrix.node }} test
1212
steps:
1313
- uses: actions/checkout@v2
14+
- uses: actions-rs/toolchain@v1
15+
with:
16+
toolchain: stable
1417
- name: Setup node
1518
uses: actions/setup-node@v2
1619
with:
1720
node-version: ${{ matrix.node }}
1821
cache: 'npm'
1922
- run: npm install
23+
- run: npm run build
2024
- run: npm test

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ index.node
33
**/node_modules
44
**/.DS_Store
55
npm-debug.log*
6+
*.tar.gz

binary.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
const { Binary } = require("binary-install");
2+
const os = require("os");
3+
const { bugs, version, name, repository } = require("./package.json");
4+
5+
const supportedPlatforms = [
6+
{
7+
TYPE: "Windows_NT",
8+
ARCHITECTURE: "x64",
9+
RUST_TARGET: "x86_64-pc-windows-msvc",
10+
BINARY_NAME: "index.node",
11+
},
12+
{
13+
TYPE: "Linux",
14+
ARCHITECTURE: "x64",
15+
RUST_TARGET: "x86_64-unknown-linux-gnu",
16+
BINARY_NAME: "index.node",
17+
},
18+
{
19+
TYPE: "Darwin",
20+
ARCHITECTURE: "x64",
21+
RUST_TARGET: "x86_64-apple-darwin",
22+
BINARY_NAME: "index.node",
23+
},
24+
{
25+
TYPE: "Darwin",
26+
ARCHITECTURE: "arm64",
27+
RUST_TARGET: "aarch64-apple-darwin",
28+
BINARY_NAME: "index.node",
29+
},
30+
];
31+
32+
function error(message) {
33+
console.error(message);
34+
process.exit(1);
35+
}
36+
37+
function getPlatform() {
38+
const type = os.type();
39+
const arch = os.arch();
40+
41+
for (let platform of supportedPlatforms) {
42+
if (type === platform.TYPE && arch === platform.ARCHITECTURE) {
43+
return platform;
44+
}
45+
}
46+
47+
error(
48+
`Platform "${type}" and architecture "${arch}" are not supported by ${name}. Please file an issue: ${bugs.url}`,
49+
);
50+
}
51+
52+
function getBinary() {
53+
const platform = getPlatform();
54+
const url = `${repository.url}/releases/download/v${version}/${name}-v${version}-${platform.RUST_TARGET}.tar.gz`;
55+
56+
return new Binary(name, url);
57+
}
58+
59+
function install() {
60+
return getBinary().install();
61+
}
62+
63+
module.exports = {
64+
install,
65+
};

install.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env node
2+
3+
const { install } = require("./binary");
4+
5+
install();

0 commit comments

Comments
 (0)