@napi-rs/cli 3.0.0-alpha.3 → 3.0.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli.mjs +0 -0
- package/dist/api/build.js +8 -2
- package/dist/api/templates/ci-template.js +9 -8
- package/dist/api/templates/js-binding.js +242 -109
- package/dist/cli.js +0 -0
- package/dist/commands/artifacts.js +2 -1
- package/dist/commands/help.js +2 -1
- package/dist/def/artifacts.js +2 -1
- package/dist/def/build.d.ts +12 -0
- package/dist/def/build.js +10 -1
- package/dist/def/create-npm-dirs.js +2 -1
- package/dist/def/new.js +2 -1
- package/dist/def/pre-publish.js +2 -1
- package/dist/def/rename.js +2 -1
- package/dist/def/universalize.js +2 -1
- package/dist/def/version.js +2 -1
- package/dist/index.cjs +274 -116
- package/dist/utils/ci.js +9 -0
- package/dist/utils/target.d.ts +2 -2
- package/dist/utils/target.js +4 -0
- package/package.json +5 -5
- package/src/api/build.ts +11 -7
- package/src/api/templates/ci-template.ts +9 -8
- package/src/api/templates/js-binding.ts +231 -104
- package/src/def/build.ts +19 -0
- package/src/utils/__tests__/__snapshots__/target.spec.ts.md +7 -0
- package/src/utils/__tests__/__snapshots__/target.spec.ts.snap +0 -0
- package/src/utils/ci.ts +9 -0
- package/src/utils/target.ts +5 -0
- package/dist/def/commands/artifacts.d.ts +0 -15
- package/dist/def/commands/artifacts.js +0 -29
- package/dist/def/commands/build.d.ts +0 -53
- package/dist/def/commands/build.js +0 -105
- package/dist/def/commands/create-npm-dirs.d.ts +0 -15
- package/dist/def/commands/create-npm-dirs.js +0 -29
- package/dist/def/commands/new.d.ts +0 -27
- package/dist/def/commands/new.js +0 -53
- package/dist/def/commands/pre-publish.d.ts +0 -23
- package/dist/def/commands/pre-publish.js +0 -45
- package/dist/def/commands/rename.d.ts +0 -25
- package/dist/def/commands/rename.js +0 -49
- package/dist/def/commands/universalize.d.ts +0 -13
- package/dist/def/commands/universalize.js +0 -25
- package/dist/def/commands/version.d.ts +0 -13
- package/dist/def/commands/version.js +0 -25
- package/dist/def/options/artifacts.d.ts +0 -35
- package/dist/def/options/artifacts.js +0 -11
- package/dist/def/options/build.d.ts +0 -97
- package/dist/def/options/build.js +0 -3
- package/dist/def/options/create-npm-dirs.d.ts +0 -35
- package/dist/def/options/create-npm-dirs.js +0 -11
- package/dist/def/options/new.d.ts +0 -79
- package/dist/def/options/new.js +0 -15
- package/dist/def/options/pre-publish.d.ts +0 -65
- package/dist/def/options/pre-publish.js +0 -13
- package/dist/def/options/rename.d.ts +0 -75
- package/dist/def/options/rename.js +0 -11
- package/dist/def/options/universalize.d.ts +0 -28
- package/dist/def/options/universalize.js +0 -10
- package/dist/def/options/version.d.ts +0 -28
- package/dist/def/options/version.js +0 -10
package/src/api/build.ts
CHANGED
|
@@ -150,7 +150,9 @@ class Builder {
|
|
|
150
150
|
const controller = new AbortController()
|
|
151
151
|
|
|
152
152
|
const buildTask = new Promise<void>((resolve, reject) => {
|
|
153
|
-
const
|
|
153
|
+
const command =
|
|
154
|
+
process.env.CARGO ?? (this.options.useCross ? 'cross' : 'cargo')
|
|
155
|
+
const buildProcess = spawn(command, this.args, {
|
|
154
156
|
env: {
|
|
155
157
|
...process.env,
|
|
156
158
|
...this.envs,
|
|
@@ -401,6 +403,10 @@ class Builder {
|
|
|
401
403
|
this.args.push('--target-dir', this.options.targetDir)
|
|
402
404
|
}
|
|
403
405
|
|
|
406
|
+
if (this.options.profile) {
|
|
407
|
+
this.args.push('--profile', this.options.profile)
|
|
408
|
+
}
|
|
409
|
+
|
|
404
410
|
if (this.options.cargoOptions?.length) {
|
|
405
411
|
this.args.push(...this.options.cargoOptions)
|
|
406
412
|
}
|
|
@@ -459,12 +465,10 @@ class Builder {
|
|
|
459
465
|
return
|
|
460
466
|
}
|
|
461
467
|
|
|
462
|
-
const
|
|
463
|
-
this.
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
srcName,
|
|
467
|
-
)
|
|
468
|
+
const profile =
|
|
469
|
+
this.options.profile ?? (this.options.release ? 'release' : 'debug')
|
|
470
|
+
const src = join(this.targetDir, this.target.triple, profile, srcName)
|
|
471
|
+
debug(`Copy artifact from: [${src}]`)
|
|
468
472
|
const dest = join(this.outputDir, destName)
|
|
469
473
|
|
|
470
474
|
try {
|
|
@@ -94,6 +94,14 @@ jobs:
|
|
|
94
94
|
- host: windows-latest
|
|
95
95
|
target: 'aarch64-pc-windows-msvc'
|
|
96
96
|
build: yarn build --platform --target aarch64-pc-windows-msvc
|
|
97
|
+
- host: ubuntu-latest
|
|
98
|
+
target: 'riscv64gc-unknown-linux-gnu'
|
|
99
|
+
setup: |
|
|
100
|
+
sudo apt-get update
|
|
101
|
+
sudo apt-get install gcc-riscv64-linux-gnu -y
|
|
102
|
+
build: |
|
|
103
|
+
yarn build --platform --target riscv64gc-unknown-linux-gnu
|
|
104
|
+
riscv64-linux-gnu-strip *.node
|
|
97
105
|
|
|
98
106
|
name: stable - \${{ matrix.settings.target }} - node@18
|
|
99
107
|
runs-on: \${{ matrix.settings.host }}
|
|
@@ -106,7 +114,6 @@ jobs:
|
|
|
106
114
|
if: \${{ !matrix.settings.docker }}
|
|
107
115
|
with:
|
|
108
116
|
node-version: 18
|
|
109
|
-
check-latest: true
|
|
110
117
|
cache: yarn
|
|
111
118
|
|
|
112
119
|
- name: Install
|
|
@@ -150,7 +157,6 @@ jobs:
|
|
|
150
157
|
if: matrix.settings.target == 'i686-pc-windows-msvc'
|
|
151
158
|
with:
|
|
152
159
|
node-version: 18
|
|
153
|
-
check-latest: true
|
|
154
160
|
cache: yarn
|
|
155
161
|
architecture: x86
|
|
156
162
|
|
|
@@ -247,7 +253,6 @@ jobs:
|
|
|
247
253
|
uses: actions/setup-node@v3
|
|
248
254
|
with:
|
|
249
255
|
node-version: \${{ matrix.node }}
|
|
250
|
-
check-latest: true
|
|
251
256
|
cache: 'yarn'
|
|
252
257
|
|
|
253
258
|
- name: 'Install dependencies'
|
|
@@ -283,7 +288,6 @@ jobs:
|
|
|
283
288
|
uses: actions/setup-node@v3
|
|
284
289
|
with:
|
|
285
290
|
node-version: \${{ matrix.node }}
|
|
286
|
-
check-latest: true
|
|
287
291
|
cache: 'yarn'
|
|
288
292
|
|
|
289
293
|
- name: 'Install dependencies'
|
|
@@ -319,7 +323,6 @@ jobs:
|
|
|
319
323
|
uses: actions/setup-node@v3
|
|
320
324
|
with:
|
|
321
325
|
node-version: \${{ matrix.node }}
|
|
322
|
-
check-latest: true
|
|
323
326
|
cache: 'yarn'
|
|
324
327
|
|
|
325
328
|
- name: 'Install dependencies'
|
|
@@ -368,7 +371,7 @@ jobs:
|
|
|
368
371
|
yarn config set supportedArchitectures.cpu "arm64"
|
|
369
372
|
yarn config set supportedArchitectures.libc "glibc"
|
|
370
373
|
yarn install
|
|
371
|
-
|
|
374
|
+
|
|
372
375
|
- name: Set up QEMU
|
|
373
376
|
uses: docker/setup-qemu-action@v2
|
|
374
377
|
with:
|
|
@@ -483,7 +486,6 @@ jobs:
|
|
|
483
486
|
uses: actions/setup-node@v3
|
|
484
487
|
with:
|
|
485
488
|
node-version: 18
|
|
486
|
-
check-latest: true
|
|
487
489
|
cache: yarn
|
|
488
490
|
|
|
489
491
|
- name: 'Install dependencies'
|
|
@@ -529,7 +531,6 @@ jobs:
|
|
|
529
531
|
uses: actions/setup-node@v3
|
|
530
532
|
with:
|
|
531
533
|
node-version: 18
|
|
532
|
-
check-latest: true
|
|
533
534
|
cache: 'yarn'
|
|
534
535
|
|
|
535
536
|
- name: 'Install dependencies'
|
|
@@ -1,130 +1,257 @@
|
|
|
1
|
-
|
|
1
|
+
export function createJsBinding(localName: string, pkgName: string): string {
|
|
2
|
+
return `// prettier-ignore
|
|
3
|
+
/* tslint:disable */
|
|
4
|
+
/* eslint-disable */
|
|
2
5
|
|
|
3
|
-
|
|
4
|
-
const { existsSync, readFileSync } = require('fs')
|
|
5
|
-
const { join } = require('path')
|
|
6
|
-
const { platform, arch } = process
|
|
6
|
+
/* auto-generated by NAPI-RS */
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
const { existsSync, readFileSync } = require('fs')
|
|
9
|
+
const { join } = require('path')
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const { glibcVersionRuntime } = process.report.getReport().header
|
|
25
|
-
return !glibcVersionRuntime
|
|
11
|
+
const { platform, arch } = process
|
|
12
|
+
|
|
13
|
+
let nativeBinding = null
|
|
14
|
+
let localFileExisted = false
|
|
15
|
+
let loadError = null
|
|
16
|
+
|
|
17
|
+
function isMusl() {
|
|
18
|
+
// For Node 10
|
|
19
|
+
if (!process.report || typeof process.report.getReport !== 'function') {
|
|
20
|
+
try {
|
|
21
|
+
const lddPath = require('child_process').execSync('which ldd').toString().trim()
|
|
22
|
+
return readFileSync(lddPath, 'utf8').includes('musl')
|
|
23
|
+
} catch (e) {
|
|
24
|
+
return true
|
|
26
25
|
}
|
|
26
|
+
} else {
|
|
27
|
+
const { glibcVersionRuntime } = process.report.getReport().header
|
|
28
|
+
return !glibcVersionRuntime
|
|
27
29
|
}
|
|
30
|
+
}
|
|
28
31
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
break
|
|
38
|
-
}
|
|
39
|
-
break
|
|
40
|
-
case 'win32':
|
|
41
|
-
switch (arch) {
|
|
42
|
-
case 'x64':
|
|
43
|
-
candidates.push('win32-x64-msvc')
|
|
44
|
-
break
|
|
45
|
-
case 'ia32':
|
|
46
|
-
candidates.push('win32-ia32-msvc')
|
|
47
|
-
break
|
|
48
|
-
case 'arm64':
|
|
49
|
-
candidates.push('win32-arm64-msvc')
|
|
50
|
-
break
|
|
51
|
-
}
|
|
52
|
-
break
|
|
53
|
-
case 'darwin':
|
|
54
|
-
candidates.push('darwin-universal')
|
|
55
|
-
switch (arch) {
|
|
56
|
-
case 'x64':
|
|
57
|
-
candidates.push('darwin-x64')
|
|
58
|
-
break
|
|
59
|
-
case 'arm64':
|
|
60
|
-
candidates.push('darwin-arm64')
|
|
61
|
-
break
|
|
62
|
-
}
|
|
63
|
-
break
|
|
64
|
-
case 'freebsd':
|
|
65
|
-
if (arch === 'x64') {
|
|
66
|
-
candidates.push('freebsd-x64')
|
|
67
|
-
}
|
|
68
|
-
break
|
|
69
|
-
case 'linux':
|
|
70
|
-
switch (arch) {
|
|
71
|
-
case 'x64':
|
|
72
|
-
if (isMusl()) {
|
|
73
|
-
candidates.push('linux-x64-musl')
|
|
32
|
+
switch (platform) {
|
|
33
|
+
case 'android':
|
|
34
|
+
switch (arch) {
|
|
35
|
+
case 'arm64':
|
|
36
|
+
localFileExisted = existsSync(join(__dirname, '${localName}.android-arm64.node'))
|
|
37
|
+
try {
|
|
38
|
+
if (localFileExisted) {
|
|
39
|
+
nativeBinding = require('./${localName}.android-arm64.node')
|
|
74
40
|
} else {
|
|
75
|
-
|
|
41
|
+
nativeBinding = require('${pkgName}-android-arm64')
|
|
76
42
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
43
|
+
} catch (e) {
|
|
44
|
+
loadError = e
|
|
45
|
+
}
|
|
46
|
+
break
|
|
47
|
+
case 'arm':
|
|
48
|
+
localFileExisted = existsSync(join(__dirname, '${localName}.android-arm-eabi.node'))
|
|
49
|
+
try {
|
|
50
|
+
if (localFileExisted) {
|
|
51
|
+
nativeBinding = require('./${localName}.android-arm-eabi.node')
|
|
81
52
|
} else {
|
|
82
|
-
|
|
53
|
+
nativeBinding = require('${pkgName}-android-arm-eabi')
|
|
83
54
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
55
|
+
} catch (e) {
|
|
56
|
+
loadError = e
|
|
57
|
+
}
|
|
58
|
+
break
|
|
59
|
+
default:
|
|
60
|
+
throw new Error(\`Unsupported architecture on Android \${arch}\`)
|
|
61
|
+
}
|
|
62
|
+
break
|
|
63
|
+
case 'win32':
|
|
64
|
+
switch (arch) {
|
|
65
|
+
case 'x64':
|
|
66
|
+
localFileExisted = existsSync(
|
|
67
|
+
join(__dirname, '${localName}.win32-x64-msvc.node')
|
|
68
|
+
)
|
|
69
|
+
try {
|
|
70
|
+
if (localFileExisted) {
|
|
71
|
+
nativeBinding = require('./${localName}.win32-x64-msvc.node')
|
|
72
|
+
} else {
|
|
73
|
+
nativeBinding = require('${pkgName}-win32-x64-msvc')
|
|
74
|
+
}
|
|
75
|
+
} catch (e) {
|
|
76
|
+
loadError = e
|
|
77
|
+
}
|
|
78
|
+
break
|
|
79
|
+
case 'ia32':
|
|
80
|
+
localFileExisted = existsSync(
|
|
81
|
+
join(__dirname, '${localName}.win32-ia32-msvc.node')
|
|
82
|
+
)
|
|
83
|
+
try {
|
|
84
|
+
if (localFileExisted) {
|
|
85
|
+
nativeBinding = require('./${localName}.win32-ia32-msvc.node')
|
|
86
|
+
} else {
|
|
87
|
+
nativeBinding = require('${pkgName}-win32-ia32-msvc')
|
|
88
|
+
}
|
|
89
|
+
} catch (e) {
|
|
90
|
+
loadError = e
|
|
91
|
+
}
|
|
92
|
+
break
|
|
93
|
+
case 'arm64':
|
|
94
|
+
localFileExisted = existsSync(
|
|
95
|
+
join(__dirname, '${localName}.win32-arm64-msvc.node')
|
|
96
|
+
)
|
|
97
|
+
try {
|
|
98
|
+
if (localFileExisted) {
|
|
99
|
+
nativeBinding = require('./${localName}.win32-arm64-msvc.node')
|
|
100
|
+
} else {
|
|
101
|
+
nativeBinding = require('${pkgName}-win32-arm64-msvc')
|
|
102
|
+
}
|
|
103
|
+
} catch (e) {
|
|
104
|
+
loadError = e
|
|
105
|
+
}
|
|
106
|
+
break
|
|
107
|
+
default:
|
|
108
|
+
throw new Error(\`Unsupported architecture on Windows: \${arch}\`)
|
|
109
|
+
}
|
|
110
|
+
break
|
|
111
|
+
case 'darwin':
|
|
112
|
+
localFileExisted = existsSync(join(__dirname, '${localName}.darwin-universal.node'))
|
|
113
|
+
try {
|
|
114
|
+
if (localFileExisted) {
|
|
115
|
+
nativeBinding = require('./${localName}.darwin-universal.node')
|
|
116
|
+
} else {
|
|
117
|
+
nativeBinding = require('${pkgName}-darwin-universal')
|
|
88
118
|
}
|
|
89
119
|
break
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
120
|
+
} catch {}
|
|
121
|
+
switch (arch) {
|
|
122
|
+
case 'x64':
|
|
123
|
+
localFileExisted = existsSync(join(__dirname, '${localName}.darwin-x64.node'))
|
|
124
|
+
try {
|
|
125
|
+
if (localFileExisted) {
|
|
126
|
+
nativeBinding = require('./${localName}.darwin-x64.node')
|
|
127
|
+
} else {
|
|
128
|
+
nativeBinding = require('${pkgName}-darwin-x64')
|
|
129
|
+
}
|
|
130
|
+
} catch (e) {
|
|
131
|
+
loadError = e
|
|
132
|
+
}
|
|
133
|
+
break
|
|
134
|
+
case 'arm64':
|
|
135
|
+
localFileExisted = existsSync(
|
|
136
|
+
join(__dirname, '${localName}.darwin-arm64.node')
|
|
137
|
+
)
|
|
138
|
+
try {
|
|
139
|
+
if (localFileExisted) {
|
|
140
|
+
nativeBinding = require('./${localName}.darwin-arm64.node')
|
|
141
|
+
} else {
|
|
142
|
+
nativeBinding = require('${pkgName}-darwin-arm64')
|
|
143
|
+
}
|
|
144
|
+
} catch (e) {
|
|
145
|
+
loadError = e
|
|
146
|
+
}
|
|
147
|
+
break
|
|
148
|
+
default:
|
|
149
|
+
throw new Error(\`Unsupported architecture on macOS: \${arch}\`)
|
|
150
|
+
}
|
|
151
|
+
break
|
|
152
|
+
case 'freebsd':
|
|
153
|
+
if (arch !== 'x64') {
|
|
154
|
+
throw new Error(\`Unsupported architecture on FreeBSD: \${arch}\`)
|
|
155
|
+
}
|
|
156
|
+
localFileExisted = existsSync(join(__dirname, '${localName}.freebsd-x64.node'))
|
|
99
157
|
try {
|
|
100
|
-
if (
|
|
101
|
-
nativeBinding = require(
|
|
158
|
+
if (localFileExisted) {
|
|
159
|
+
nativeBinding = require('./${localName}.freebsd-x64.node')
|
|
102
160
|
} else {
|
|
103
|
-
nativeBinding = require(
|
|
161
|
+
nativeBinding = require('${pkgName}-freebsd-x64')
|
|
104
162
|
}
|
|
105
163
|
} catch (e) {
|
|
106
164
|
loadError = e
|
|
107
|
-
continue
|
|
108
165
|
}
|
|
109
|
-
|
|
110
|
-
loadError = null
|
|
111
166
|
break
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
167
|
+
case 'linux':
|
|
168
|
+
switch (arch) {
|
|
169
|
+
case 'x64':
|
|
170
|
+
if (isMusl()) {
|
|
171
|
+
localFileExisted = existsSync(
|
|
172
|
+
join(__dirname, '${localName}.linux-x64-musl.node')
|
|
173
|
+
)
|
|
174
|
+
try {
|
|
175
|
+
if (localFileExisted) {
|
|
176
|
+
nativeBinding = require('./${localName}.linux-x64-musl.node')
|
|
177
|
+
} else {
|
|
178
|
+
nativeBinding = require('${pkgName}-linux-x64-musl')
|
|
179
|
+
}
|
|
180
|
+
} catch (e) {
|
|
181
|
+
loadError = e
|
|
182
|
+
}
|
|
183
|
+
} else {
|
|
184
|
+
localFileExisted = existsSync(
|
|
185
|
+
join(__dirname, '${localName}.linux-x64-gnu.node')
|
|
186
|
+
)
|
|
187
|
+
try {
|
|
188
|
+
if (localFileExisted) {
|
|
189
|
+
nativeBinding = require('./${localName}.linux-x64-gnu.node')
|
|
190
|
+
} else {
|
|
191
|
+
nativeBinding = require('${pkgName}-linux-x64-gnu')
|
|
192
|
+
}
|
|
193
|
+
} catch (e) {
|
|
194
|
+
loadError = e
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
break
|
|
198
|
+
case 'arm64':
|
|
199
|
+
if (isMusl()) {
|
|
200
|
+
localFileExisted = existsSync(
|
|
201
|
+
join(__dirname, '${localName}.linux-arm64-musl.node')
|
|
202
|
+
)
|
|
203
|
+
try {
|
|
204
|
+
if (localFileExisted) {
|
|
205
|
+
nativeBinding = require('./${localName}.linux-arm64-musl.node')
|
|
206
|
+
} else {
|
|
207
|
+
nativeBinding = require('${pkgName}-linux-arm64-musl')
|
|
208
|
+
}
|
|
209
|
+
} catch (e) {
|
|
210
|
+
loadError = e
|
|
211
|
+
}
|
|
212
|
+
} else {
|
|
213
|
+
localFileExisted = existsSync(
|
|
214
|
+
join(__dirname, '${localName}.linux-arm64-gnu.node')
|
|
215
|
+
)
|
|
216
|
+
try {
|
|
217
|
+
if (localFileExisted) {
|
|
218
|
+
nativeBinding = require('./${localName}.linux-arm64-gnu.node')
|
|
219
|
+
} else {
|
|
220
|
+
nativeBinding = require('${pkgName}-linux-arm64-gnu')
|
|
221
|
+
}
|
|
222
|
+
} catch (e) {
|
|
223
|
+
loadError = e
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
break
|
|
227
|
+
case 'arm':
|
|
228
|
+
localFileExisted = existsSync(
|
|
229
|
+
join(__dirname, '${localName}.linux-arm-gnueabihf.node')
|
|
230
|
+
)
|
|
231
|
+
try {
|
|
232
|
+
if (localFileExisted) {
|
|
233
|
+
nativeBinding = require('./${localName}.linux-arm-gnueabihf.node')
|
|
234
|
+
} else {
|
|
235
|
+
nativeBinding = require('${pkgName}-linux-arm-gnueabihf')
|
|
236
|
+
}
|
|
237
|
+
} catch (e) {
|
|
238
|
+
loadError = e
|
|
239
|
+
}
|
|
240
|
+
break
|
|
241
|
+
default:
|
|
242
|
+
throw new Error(\`Unsupported architecture on Linux: \${arch}\`)
|
|
117
243
|
}
|
|
244
|
+
break
|
|
245
|
+
default:
|
|
246
|
+
throw new Error(\`Unsupported OS: \${platform}, architecture: \${arch}\`)
|
|
247
|
+
}
|
|
118
248
|
|
|
119
|
-
|
|
249
|
+
if (!nativeBinding) {
|
|
250
|
+
if (loadError) {
|
|
251
|
+
throw loadError
|
|
120
252
|
}
|
|
121
|
-
|
|
122
|
-
return nativeBinding
|
|
253
|
+
throw new Error(\`Failed to load native binding\`)
|
|
123
254
|
}
|
|
124
255
|
|
|
125
|
-
export function createJsBinding(localName: string, pkgName: string): string {
|
|
126
|
-
return `${loadNapiModule.toString()}
|
|
127
|
-
|
|
128
|
-
module.exports = loadNapiModule('${localName}', '${pkgName}')
|
|
129
256
|
`
|
|
130
257
|
}
|
package/src/def/build.ts
CHANGED
|
@@ -92,11 +92,20 @@ export abstract class BaseBuildCommand extends Command {
|
|
|
92
92
|
description: 'Build the specified library or the one at cwd',
|
|
93
93
|
})
|
|
94
94
|
|
|
95
|
+
profile?: string = Option.String('--profile', {
|
|
96
|
+
description: 'Build artifacts with the specified profile',
|
|
97
|
+
})
|
|
98
|
+
|
|
95
99
|
crossCompile?: boolean = Option.Boolean('--cross-compile,-x', {
|
|
96
100
|
description:
|
|
97
101
|
'[experimental] cross-compile for the specified target with `cargo-xwin` on windows and `cargo-zigbuild` on other platform',
|
|
98
102
|
})
|
|
99
103
|
|
|
104
|
+
useCross?: boolean = Option.Boolean('--use-cross', {
|
|
105
|
+
description:
|
|
106
|
+
'[experimental] use [cross](https://github.com/cross-rs/cross) instead of `cargo`',
|
|
107
|
+
})
|
|
108
|
+
|
|
100
109
|
watch?: boolean = Option.Boolean('--watch,-w', {
|
|
101
110
|
description:
|
|
102
111
|
'watch the crate changes and build continiously with `cargo-watch` crates',
|
|
@@ -134,7 +143,9 @@ export abstract class BaseBuildCommand extends Command {
|
|
|
134
143
|
verbose: this.verbose,
|
|
135
144
|
bin: this.bin,
|
|
136
145
|
package: this.package,
|
|
146
|
+
profile: this.profile,
|
|
137
147
|
crossCompile: this.crossCompile,
|
|
148
|
+
useCross: this.useCross,
|
|
138
149
|
watch: this.watch,
|
|
139
150
|
features: this.features,
|
|
140
151
|
allFeatures: this.allFeatures,
|
|
@@ -219,10 +230,18 @@ export interface BuildOptions {
|
|
|
219
230
|
* Build the specified library or the one at cwd
|
|
220
231
|
*/
|
|
221
232
|
package?: string
|
|
233
|
+
/**
|
|
234
|
+
* Build artifacts with the specified profile
|
|
235
|
+
*/
|
|
236
|
+
profile?: string
|
|
222
237
|
/**
|
|
223
238
|
* [experimental] cross-compile for the specified target with `cargo-xwin` on windows and `cargo-zigbuild` on other platform
|
|
224
239
|
*/
|
|
225
240
|
crossCompile?: boolean
|
|
241
|
+
/**
|
|
242
|
+
* [experimental] use [cross](https://github.com/cross-rs/cross) instead of `cargo`
|
|
243
|
+
*/
|
|
244
|
+
useCross?: boolean
|
|
226
245
|
/**
|
|
227
246
|
* watch the crate changes and build continiously with `cargo-watch` crates
|
|
228
247
|
*/
|
|
@@ -107,4 +107,11 @@ Generated by [AVA](https://avajs.dev).
|
|
|
107
107
|
platformArchABI: 'darwin-universal',
|
|
108
108
|
triple: 'universal-apple-darwin',
|
|
109
109
|
},
|
|
110
|
+
{
|
|
111
|
+
abi: 'gnu',
|
|
112
|
+
arch: 'riscv64',
|
|
113
|
+
platform: 'linux',
|
|
114
|
+
platformArchABI: 'linux-riscv64-gnu',
|
|
115
|
+
triple: 'riscv64gc-unknown-linux-gnu',
|
|
116
|
+
},
|
|
110
117
|
]
|
|
Binary file
|
package/src/utils/ci.ts
CHANGED
|
@@ -99,4 +99,13 @@ export const CIConfig: Partial<
|
|
|
99
99
|
],
|
|
100
100
|
test: false,
|
|
101
101
|
},
|
|
102
|
+
'riscv64gc-unknown-linux-gnu': {
|
|
103
|
+
host: 'ubuntu-latest',
|
|
104
|
+
build_setup: [
|
|
105
|
+
'sudo apt-get update',
|
|
106
|
+
'sudo apt-get install g++-riscv64-linux-gnu gcc-riscv64-linux-gnu -y',
|
|
107
|
+
],
|
|
108
|
+
// No official nodejs docker image for riscv64
|
|
109
|
+
test: false,
|
|
110
|
+
},
|
|
102
111
|
}
|
package/src/utils/target.ts
CHANGED
|
@@ -15,6 +15,7 @@ export const AVAILABLE_TARGETS = [
|
|
|
15
15
|
'armv7-unknown-linux-gnueabihf',
|
|
16
16
|
'armv7-linux-androideabi',
|
|
17
17
|
'universal-apple-darwin',
|
|
18
|
+
'riscv64gc-unknown-linux-gnu',
|
|
18
19
|
] as const
|
|
19
20
|
|
|
20
21
|
export type TargetTriple = (typeof AVAILABLE_TARGETS)[number]
|
|
@@ -27,6 +28,7 @@ export const DEFAULT_TARGETS = [
|
|
|
27
28
|
|
|
28
29
|
export const TARGET_LINKER: Record<string, string> = {
|
|
29
30
|
'aarch64-unknown-linux-musl': 'aarch64-linux-musl-gcc',
|
|
31
|
+
'riscv64gc-unknown-linux-gnu': 'riscv64-linux-gnu-gcc',
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
// https://nodejs.org/api/process.html#process_process_arch
|
|
@@ -38,6 +40,7 @@ type NodeJSArch =
|
|
|
38
40
|
| 'mipsel'
|
|
39
41
|
| 'ppc'
|
|
40
42
|
| 'ppc64'
|
|
43
|
+
| 'riscv64'
|
|
41
44
|
| 's390'
|
|
42
45
|
| 's390x'
|
|
43
46
|
| 'x32'
|
|
@@ -49,6 +52,7 @@ const CpuToNodeArch: Record<string, NodeJSArch> = {
|
|
|
49
52
|
aarch64: 'arm64',
|
|
50
53
|
i686: 'ia32',
|
|
51
54
|
armv7: 'arm',
|
|
55
|
+
riscv64gc: 'riscv64',
|
|
52
56
|
}
|
|
53
57
|
|
|
54
58
|
export const NodeArchToCpu: Record<string, string> = {
|
|
@@ -56,6 +60,7 @@ export const NodeArchToCpu: Record<string, string> = {
|
|
|
56
60
|
arm64: 'aarch64',
|
|
57
61
|
ia32: 'i686',
|
|
58
62
|
arm: 'armv7',
|
|
63
|
+
riscv64: 'riscv64gc',
|
|
59
64
|
}
|
|
60
65
|
|
|
61
66
|
const SysToNodePlatform: Record<string, NodeJS.Platform> = {
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Command } from 'clipanion';
|
|
2
|
-
export declare abstract class BaseArtifactsCommand extends Command {
|
|
3
|
-
static paths: string[][];
|
|
4
|
-
static usage: import("clipanion").Usage;
|
|
5
|
-
cwd: string;
|
|
6
|
-
packageJsonPath: string;
|
|
7
|
-
outputDir: string;
|
|
8
|
-
npmDir: string;
|
|
9
|
-
getOptions(): {
|
|
10
|
-
cwd: string;
|
|
11
|
-
packageJsonPath: string;
|
|
12
|
-
outputDir: string;
|
|
13
|
-
npmDir: string;
|
|
14
|
-
};
|
|
15
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
// This file is generated by codegen/index.ts
|
|
2
|
-
// Do not edit this file manually
|
|
3
|
-
import { Command, Option } from 'clipanion';
|
|
4
|
-
export class BaseArtifactsCommand extends Command {
|
|
5
|
-
static paths = [['artifacts']];
|
|
6
|
-
static usage = Command.Usage({
|
|
7
|
-
description: 'Copy artifacts from Github Actions into npm packages and ready to publish',
|
|
8
|
-
});
|
|
9
|
-
cwd = Option.String('--cwd', process.cwd(), {
|
|
10
|
-
description: 'The working directory of where napi command will be executed in, all other paths options are relative to this path',
|
|
11
|
-
});
|
|
12
|
-
packageJsonPath = Option.String('--package-json-path', 'package.json', {
|
|
13
|
-
description: 'Path to `package.json`',
|
|
14
|
-
});
|
|
15
|
-
outputDir = Option.String('--output-dir,-o', './', {
|
|
16
|
-
description: 'Path to the folder where all built `.node` files put, same as `--output-dir` of build command',
|
|
17
|
-
});
|
|
18
|
-
npmDir = Option.String('--npm-dir', 'npm', {
|
|
19
|
-
description: 'Path to the folder where the npm packages put',
|
|
20
|
-
});
|
|
21
|
-
getOptions() {
|
|
22
|
-
return {
|
|
23
|
-
cwd: this.cwd,
|
|
24
|
-
packageJsonPath: this.packageJsonPath,
|
|
25
|
-
outputDir: this.outputDir,
|
|
26
|
-
npmDir: this.npmDir,
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
}
|