@napi-rs/cli 3.0.0-alpha.2 → 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.
Files changed (63) hide show
  1. package/cli.mjs +0 -0
  2. package/dist/api/build.js +8 -2
  3. package/dist/api/templates/ci-template.js +18 -17
  4. package/dist/api/templates/js-binding.js +242 -109
  5. package/dist/api/templates/package.json.js +1 -2
  6. package/dist/cli.js +0 -0
  7. package/dist/commands/artifacts.js +2 -1
  8. package/dist/commands/help.js +2 -1
  9. package/dist/def/artifacts.js +2 -1
  10. package/dist/def/build.d.ts +12 -0
  11. package/dist/def/build.js +10 -1
  12. package/dist/def/create-npm-dirs.js +2 -1
  13. package/dist/def/new.js +2 -1
  14. package/dist/def/pre-publish.js +2 -1
  15. package/dist/def/rename.js +2 -1
  16. package/dist/def/universalize.js +2 -1
  17. package/dist/def/version.js +2 -1
  18. package/dist/index.cjs +284 -127
  19. package/dist/utils/ci.js +9 -0
  20. package/dist/utils/target.d.ts +2 -2
  21. package/dist/utils/target.js +4 -0
  22. package/package.json +5 -5
  23. package/src/api/build.ts +11 -7
  24. package/src/api/templates/ci-template.ts +18 -17
  25. package/src/api/templates/js-binding.ts +231 -104
  26. package/src/api/templates/package.json.ts +1 -2
  27. package/src/def/build.ts +19 -0
  28. package/src/utils/__tests__/__snapshots__/target.spec.ts.md +7 -0
  29. package/src/utils/__tests__/__snapshots__/target.spec.ts.snap +0 -0
  30. package/src/utils/ci.ts +9 -0
  31. package/src/utils/target.ts +5 -0
  32. package/dist/def/commands/artifacts.d.ts +0 -15
  33. package/dist/def/commands/artifacts.js +0 -29
  34. package/dist/def/commands/build.d.ts +0 -53
  35. package/dist/def/commands/build.js +0 -105
  36. package/dist/def/commands/create-npm-dirs.d.ts +0 -15
  37. package/dist/def/commands/create-npm-dirs.js +0 -29
  38. package/dist/def/commands/new.d.ts +0 -27
  39. package/dist/def/commands/new.js +0 -53
  40. package/dist/def/commands/pre-publish.d.ts +0 -23
  41. package/dist/def/commands/pre-publish.js +0 -45
  42. package/dist/def/commands/rename.d.ts +0 -25
  43. package/dist/def/commands/rename.js +0 -49
  44. package/dist/def/commands/universalize.d.ts +0 -13
  45. package/dist/def/commands/universalize.js +0 -25
  46. package/dist/def/commands/version.d.ts +0 -13
  47. package/dist/def/commands/version.js +0 -25
  48. package/dist/def/options/artifacts.d.ts +0 -35
  49. package/dist/def/options/artifacts.js +0 -11
  50. package/dist/def/options/build.d.ts +0 -97
  51. package/dist/def/options/build.js +0 -3
  52. package/dist/def/options/create-npm-dirs.d.ts +0 -35
  53. package/dist/def/options/create-npm-dirs.js +0 -11
  54. package/dist/def/options/new.d.ts +0 -79
  55. package/dist/def/options/new.js +0 -15
  56. package/dist/def/options/pre-publish.d.ts +0 -65
  57. package/dist/def/options/pre-publish.js +0 -13
  58. package/dist/def/options/rename.d.ts +0 -75
  59. package/dist/def/options/rename.js +0 -11
  60. package/dist/def/options/universalize.d.ts +0 -28
  61. package/dist/def/options/universalize.js +0 -10
  62. package/dist/def/options/version.d.ts +0 -28
  63. package/dist/def/options/version.js +0 -10
@@ -14,6 +14,7 @@ export const AVAILABLE_TARGETS = [
14
14
  'armv7-unknown-linux-gnueabihf',
15
15
  'armv7-linux-androideabi',
16
16
  'universal-apple-darwin',
17
+ 'riscv64gc-unknown-linux-gnu',
17
18
  ];
18
19
  export const DEFAULT_TARGETS = [
19
20
  'x86_64-apple-darwin',
@@ -22,18 +23,21 @@ export const DEFAULT_TARGETS = [
22
23
  ];
23
24
  export const TARGET_LINKER = {
24
25
  'aarch64-unknown-linux-musl': 'aarch64-linux-musl-gcc',
26
+ 'riscv64gc-unknown-linux-gnu': 'riscv64-linux-gnu-gcc',
25
27
  };
26
28
  const CpuToNodeArch = {
27
29
  x86_64: 'x64',
28
30
  aarch64: 'arm64',
29
31
  i686: 'ia32',
30
32
  armv7: 'arm',
33
+ riscv64gc: 'riscv64',
31
34
  };
32
35
  export const NodeArchToCpu = {
33
36
  x64: 'x86_64',
34
37
  arm64: 'aarch64',
35
38
  ia32: 'i686',
36
39
  arm: 'armv7',
40
+ riscv64: 'riscv64gc',
37
41
  };
38
42
  const SysToNodePlatform = {
39
43
  linux: 'linux',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@napi-rs/cli",
3
- "version": "3.0.0-alpha.2",
3
+ "version": "3.0.0-alpha.4",
4
4
  "description": "Cli tools for napi-rs",
5
5
  "author": "LongYinan <lynweklm@gmail.com>",
6
6
  "homepage": "https://github.com/napi-rs/napi-rs",
@@ -79,12 +79,12 @@
79
79
  "devDependencies": {
80
80
  "@types/inquirer": "^9.0.3",
81
81
  "@types/js-yaml": "^4.0.5",
82
- "@types/lodash-es": "^4.17.6",
82
+ "@types/lodash-es": "^4.17.7",
83
83
  "ava": "^5.2.0",
84
- "esbuild": "^0.17.14",
84
+ "esbuild": "^0.17.16",
85
85
  "prettier": "^2.8.7",
86
86
  "ts-node": "^10.9.1",
87
- "typescript": "^4.9.4"
87
+ "typescript": "^5.0.4"
88
88
  },
89
89
  "funding": {
90
90
  "type": "github",
@@ -96,5 +96,5 @@
96
96
  "build:cjs": "node ./esbuild.mjs",
97
97
  "test": "ava"
98
98
  },
99
- "gitHead": "c3b49f0ca6a199029c4a8a893594d0b76c2a6d01"
99
+ "gitHead": "0302e564faad54dcfe6c91c9a7f26749a6a0d8e8"
100
100
  }
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 buildProcess = spawn('cargo', this.args, {
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 src = join(
463
- this.targetDir,
464
- this.target.triple,
465
- this.options.release ? 'release' : 'debug',
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 {
@@ -71,7 +71,7 @@ jobs:
71
71
  sudo apt-get update
72
72
  sudo apt-get install gcc-arm-linux-gnueabihf -y
73
73
  build: |
74
- yarn build --platform --target armv7-unknown-linux-gnueabihf
74
+ yarn build --platform --target armv7-unknown-linux-gnueabihf --cross-compile
75
75
  arm-linux-gnueabihf-strip *.node
76
76
  - host: ubuntu-latest
77
77
  target: 'aarch64-linux-android'
@@ -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
 
@@ -237,7 +243,7 @@ jobs:
237
243
  target: 'x86_64-apple-darwin'
238
244
  - host: windows-latest
239
245
  target: 'x86_64-pc-windows-msvc'
240
- node: ['14', '16', '18']
246
+ node: ['16', '18']
241
247
  runs-on: \${{ matrix.settings.host }}
242
248
 
243
249
  steps:
@@ -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'
@@ -273,7 +278,7 @@ jobs:
273
278
  strategy:
274
279
  fail-fast: false
275
280
  matrix:
276
- node: ['14', '16', '18']
281
+ node: ['16', '18']
277
282
  runs-on: ubuntu-latest
278
283
 
279
284
  steps:
@@ -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'
@@ -309,7 +313,7 @@ jobs:
309
313
  strategy:
310
314
  fail-fast: false
311
315
  matrix:
312
- node: ['14', '16', '18']
316
+ node: ['16', '18']
313
317
  runs-on: ubuntu-latest
314
318
 
315
319
  steps:
@@ -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'
@@ -347,7 +350,7 @@ jobs:
347
350
  strategy:
348
351
  fail-fast: false
349
352
  matrix:
350
- node: ['14', '16', '18']
353
+ node: ['16', '18']
351
354
  runs-on: ubuntu-latest
352
355
 
353
356
  steps:
@@ -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:
@@ -433,7 +436,7 @@ jobs:
433
436
  strategy:
434
437
  fail-fast: false
435
438
  matrix:
436
- node: ['14', '16', '18']
439
+ node: ['16', '18']
437
440
  runs-on: ubuntu-latest
438
441
 
439
442
  steps:
@@ -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'
@@ -493,15 +495,15 @@ jobs:
493
495
  uses: actions/download-artifact@v3
494
496
  with:
495
497
  name: bindings-x86_64-apple-darwin
496
- path: artifacts
498
+ path: .
497
499
  - name: Download macOS arm64 artifact
498
500
  uses: actions/download-artifact@v3
499
501
  with:
500
502
  name: bindings-aarch64-apple-darwin
501
- path: artifacts
503
+ path: .
502
504
 
503
505
  - name: Combine binaries
504
- run: yarn universal
506
+ run: yarn napi universalize
505
507
 
506
508
  - name: Upload artifact
507
509
  uses: actions/upload-artifact@v3
@@ -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
- /* eslint-disable @typescript-eslint/switch-exhaustiveness-check */
1
+ export function createJsBinding(localName: string, pkgName: string): string {
2
+ return `// prettier-ignore
3
+ /* tslint:disable */
4
+ /* eslint-disable */
2
5
 
3
- function loadNapiModule(binaryName: string, packageName: string) {
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
- const candidates: string[] = []
8
+ const { existsSync, readFileSync } = require('fs')
9
+ const { join } = require('path')
9
10
 
10
- function isMusl() {
11
- // For Node 10
12
- if (!process.report || typeof process.report.getReport !== 'function') {
13
- try {
14
- const lddPath = require('child_process')
15
- .execSync('which ldd')
16
- .toString()
17
- .trim()
18
- return readFileSync(lddPath, 'utf8').includes('musl')
19
- } catch (e) {
20
- return true
21
- }
22
- } else {
23
- // @ts-expect-error
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
- switch (platform) {
30
- case 'android':
31
- switch (arch) {
32
- case 'arm64':
33
- candidates.push('android-arm64')
34
- break
35
- case 'arm':
36
- candidates.push('android-arm-eabi')
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
- candidates.push('linux-x64-gnu')
41
+ nativeBinding = require('${pkgName}-android-arm64')
76
42
  }
77
- break
78
- case 'arm64':
79
- if (isMusl()) {
80
- candidates.push('linux-arm64-musl')
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
- candidates.push('linux-arm64-gnu')
53
+ nativeBinding = require('${pkgName}-android-arm-eabi')
83
54
  }
84
- break
85
- case 'arm':
86
- candidates.push('linux-arm-gnueabihf')
87
- break
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
- let nativeBinding: any
93
- let loadError: any
94
-
95
- for (const suffix of candidates) {
96
- const localPath = join(__dirname, `${binaryName}.${suffix}.node`)
97
- const pkgPath = `${packageName}-${suffix}`
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 (existsSync(localPath)) {
101
- nativeBinding = require(localPath)
158
+ if (localFileExisted) {
159
+ nativeBinding = require('./${localName}.freebsd-x64.node')
102
160
  } else {
103
- nativeBinding = require(pkgPath)
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
- if (!nativeBinding) {
115
- if (loadError) {
116
- throw loadError
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
- throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`)
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
  }
@@ -29,12 +29,11 @@ export const createPackageJson = ({
29
29
  ]
30
30
  },
31
31
  "scripts": {
32
- "test": "yarn build:debug --platform && node -e \\"assert(require('.').sum(1, 2) === 3)\\"",
32
+ "test": "node -e \\"assert(require('.').sum(1, 2) === 3)\\"",
33
33
  "build": "napi build --release --platform --strip",
34
34
  "build:debug": "napi build",
35
35
  "prepublishOnly": "napi prepublish -t npm",
36
36
  "artifacts": "napi artifacts",
37
- "universal": "napi universal",
38
37
  "version": "napi version"
39
38
  },
40
39
  "devDependencies": {
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
  ]