@napi-rs/cli 3.0.0-alpha.3 → 3.0.0-alpha.5
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/dist/api/build.js +34 -14
- package/dist/api/templates/ci-template.js +10 -11
- package/dist/api/templates/ci.yml.js +8 -2
- package/dist/api/templates/js-binding.d.ts +1 -1
- package/dist/api/templates/js-binding.js +243 -109
- package/dist/api/templates/package.json.js +29 -27
- package/dist/cli.js +0 -0
- package/dist/commands/new.js +1 -4
- package/dist/def/build.d.ts +12 -0
- package/dist/def/build.js +8 -0
- package/dist/index.cjs +2734 -7836
- package/dist/utils/__tests__/typegen.spec.js +1 -1
- package/dist/utils/ci.js +9 -0
- package/dist/utils/config.d.ts +9 -1
- package/dist/utils/target.d.ts +2 -2
- package/dist/utils/target.js +4 -0
- package/dist/utils/typegen.d.ts +4 -1
- package/dist/utils/typegen.js +20 -1
- package/dist/utils/version.js +2 -2
- package/package.json +13 -13
- package/src/api/artifacts.ts +2 -2
- package/src/api/build.ts +45 -18
- package/src/api/pre-publish.ts +8 -5
- package/src/api/templates/ci-template.ts +10 -11
- package/src/api/templates/ci.yml.ts +8 -2
- package/src/api/templates/js-binding.ts +236 -104
- package/src/api/templates/package.json.ts +31 -26
- package/src/commands/new.ts +1 -5
- 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/__tests__/__snapshots__/version.spec.ts.md +7 -7
- package/src/utils/__tests__/__snapshots__/version.spec.ts.snap +0 -0
- package/src/utils/__tests__/typegen.spec.ts +1 -1
- package/src/utils/ci.ts +9 -0
- package/src/utils/config.ts +12 -1
- package/src/utils/target.ts +5 -0
- package/src/utils/typegen.ts +20 -1
- package/src/utils/version.ts +1 -1
- 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
|
@@ -1,130 +1,262 @@
|
|
|
1
|
-
|
|
1
|
+
export function createCjsBinding(
|
|
2
|
+
localName: string,
|
|
3
|
+
pkgName: string,
|
|
4
|
+
idents: string[],
|
|
5
|
+
): string {
|
|
6
|
+
return `// prettier-ignore
|
|
7
|
+
/* eslint-disable */
|
|
8
|
+
/* auto-generated by NAPI-RS */
|
|
2
9
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const { join } = require('path')
|
|
6
|
-
const { platform, arch } = process
|
|
10
|
+
const { existsSync, readFileSync } = require('fs')
|
|
11
|
+
const { join } = require('path')
|
|
7
12
|
|
|
8
|
-
|
|
13
|
+
const { platform, arch } = process
|
|
9
14
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
} else {
|
|
23
|
-
// @ts-expect-error
|
|
24
|
-
const { glibcVersionRuntime } = process.report.getReport().header
|
|
25
|
-
return !glibcVersionRuntime
|
|
15
|
+
let nativeBinding = null
|
|
16
|
+
let localFileExisted = false
|
|
17
|
+
let loadError = null
|
|
18
|
+
|
|
19
|
+
function isMusl() {
|
|
20
|
+
// For Node 10
|
|
21
|
+
if (!process.report || typeof process.report.getReport !== 'function') {
|
|
22
|
+
try {
|
|
23
|
+
const lddPath = require('child_process').execSync('which ldd').toString().trim()
|
|
24
|
+
return readFileSync(lddPath, 'utf8').includes('musl')
|
|
25
|
+
} catch (e) {
|
|
26
|
+
return true
|
|
26
27
|
}
|
|
28
|
+
} else {
|
|
29
|
+
const { glibcVersionRuntime } = process.report.getReport().header
|
|
30
|
+
return !glibcVersionRuntime
|
|
27
31
|
}
|
|
32
|
+
}
|
|
28
33
|
|
|
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')
|
|
34
|
+
switch (platform) {
|
|
35
|
+
case 'android':
|
|
36
|
+
switch (arch) {
|
|
37
|
+
case 'arm64':
|
|
38
|
+
localFileExisted = existsSync(join(__dirname, '${localName}.android-arm64.node'))
|
|
39
|
+
try {
|
|
40
|
+
if (localFileExisted) {
|
|
41
|
+
nativeBinding = require('./${localName}.android-arm64.node')
|
|
74
42
|
} else {
|
|
75
|
-
|
|
43
|
+
nativeBinding = require('${pkgName}-android-arm64')
|
|
76
44
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
45
|
+
} catch (e) {
|
|
46
|
+
loadError = e
|
|
47
|
+
}
|
|
48
|
+
break
|
|
49
|
+
case 'arm':
|
|
50
|
+
localFileExisted = existsSync(join(__dirname, '${localName}.android-arm-eabi.node'))
|
|
51
|
+
try {
|
|
52
|
+
if (localFileExisted) {
|
|
53
|
+
nativeBinding = require('./${localName}.android-arm-eabi.node')
|
|
81
54
|
} else {
|
|
82
|
-
|
|
55
|
+
nativeBinding = require('${pkgName}-android-arm-eabi')
|
|
83
56
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
57
|
+
} catch (e) {
|
|
58
|
+
loadError = e
|
|
59
|
+
}
|
|
60
|
+
break
|
|
61
|
+
default:
|
|
62
|
+
throw new Error(\`Unsupported architecture on Android \${arch}\`)
|
|
63
|
+
}
|
|
64
|
+
break
|
|
65
|
+
case 'win32':
|
|
66
|
+
switch (arch) {
|
|
67
|
+
case 'x64':
|
|
68
|
+
localFileExisted = existsSync(
|
|
69
|
+
join(__dirname, '${localName}.win32-x64-msvc.node')
|
|
70
|
+
)
|
|
71
|
+
try {
|
|
72
|
+
if (localFileExisted) {
|
|
73
|
+
nativeBinding = require('./${localName}.win32-x64-msvc.node')
|
|
74
|
+
} else {
|
|
75
|
+
nativeBinding = require('${pkgName}-win32-x64-msvc')
|
|
76
|
+
}
|
|
77
|
+
} catch (e) {
|
|
78
|
+
loadError = e
|
|
79
|
+
}
|
|
80
|
+
break
|
|
81
|
+
case 'ia32':
|
|
82
|
+
localFileExisted = existsSync(
|
|
83
|
+
join(__dirname, '${localName}.win32-ia32-msvc.node')
|
|
84
|
+
)
|
|
85
|
+
try {
|
|
86
|
+
if (localFileExisted) {
|
|
87
|
+
nativeBinding = require('./${localName}.win32-ia32-msvc.node')
|
|
88
|
+
} else {
|
|
89
|
+
nativeBinding = require('${pkgName}-win32-ia32-msvc')
|
|
90
|
+
}
|
|
91
|
+
} catch (e) {
|
|
92
|
+
loadError = e
|
|
93
|
+
}
|
|
94
|
+
break
|
|
95
|
+
case 'arm64':
|
|
96
|
+
localFileExisted = existsSync(
|
|
97
|
+
join(__dirname, '${localName}.win32-arm64-msvc.node')
|
|
98
|
+
)
|
|
99
|
+
try {
|
|
100
|
+
if (localFileExisted) {
|
|
101
|
+
nativeBinding = require('./${localName}.win32-arm64-msvc.node')
|
|
102
|
+
} else {
|
|
103
|
+
nativeBinding = require('${pkgName}-win32-arm64-msvc')
|
|
104
|
+
}
|
|
105
|
+
} catch (e) {
|
|
106
|
+
loadError = e
|
|
107
|
+
}
|
|
108
|
+
break
|
|
109
|
+
default:
|
|
110
|
+
throw new Error(\`Unsupported architecture on Windows: \${arch}\`)
|
|
111
|
+
}
|
|
112
|
+
break
|
|
113
|
+
case 'darwin':
|
|
114
|
+
localFileExisted = existsSync(join(__dirname, '${localName}.darwin-universal.node'))
|
|
115
|
+
try {
|
|
116
|
+
if (localFileExisted) {
|
|
117
|
+
nativeBinding = require('./${localName}.darwin-universal.node')
|
|
118
|
+
} else {
|
|
119
|
+
nativeBinding = require('${pkgName}-darwin-universal')
|
|
88
120
|
}
|
|
89
121
|
break
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
122
|
+
} catch {}
|
|
123
|
+
switch (arch) {
|
|
124
|
+
case 'x64':
|
|
125
|
+
localFileExisted = existsSync(join(__dirname, '${localName}.darwin-x64.node'))
|
|
126
|
+
try {
|
|
127
|
+
if (localFileExisted) {
|
|
128
|
+
nativeBinding = require('./${localName}.darwin-x64.node')
|
|
129
|
+
} else {
|
|
130
|
+
nativeBinding = require('${pkgName}-darwin-x64')
|
|
131
|
+
}
|
|
132
|
+
} catch (e) {
|
|
133
|
+
loadError = e
|
|
134
|
+
}
|
|
135
|
+
break
|
|
136
|
+
case 'arm64':
|
|
137
|
+
localFileExisted = existsSync(
|
|
138
|
+
join(__dirname, '${localName}.darwin-arm64.node')
|
|
139
|
+
)
|
|
140
|
+
try {
|
|
141
|
+
if (localFileExisted) {
|
|
142
|
+
nativeBinding = require('./${localName}.darwin-arm64.node')
|
|
143
|
+
} else {
|
|
144
|
+
nativeBinding = require('${pkgName}-darwin-arm64')
|
|
145
|
+
}
|
|
146
|
+
} catch (e) {
|
|
147
|
+
loadError = e
|
|
148
|
+
}
|
|
149
|
+
break
|
|
150
|
+
default:
|
|
151
|
+
throw new Error(\`Unsupported architecture on macOS: \${arch}\`)
|
|
152
|
+
}
|
|
153
|
+
break
|
|
154
|
+
case 'freebsd':
|
|
155
|
+
if (arch !== 'x64') {
|
|
156
|
+
throw new Error(\`Unsupported architecture on FreeBSD: \${arch}\`)
|
|
157
|
+
}
|
|
158
|
+
localFileExisted = existsSync(join(__dirname, '${localName}.freebsd-x64.node'))
|
|
99
159
|
try {
|
|
100
|
-
if (
|
|
101
|
-
nativeBinding = require(
|
|
160
|
+
if (localFileExisted) {
|
|
161
|
+
nativeBinding = require('./${localName}.freebsd-x64.node')
|
|
102
162
|
} else {
|
|
103
|
-
nativeBinding = require(
|
|
163
|
+
nativeBinding = require('${pkgName}-freebsd-x64')
|
|
104
164
|
}
|
|
105
165
|
} catch (e) {
|
|
106
166
|
loadError = e
|
|
107
|
-
continue
|
|
108
167
|
}
|
|
109
|
-
|
|
110
|
-
loadError = null
|
|
111
168
|
break
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
169
|
+
case 'linux':
|
|
170
|
+
switch (arch) {
|
|
171
|
+
case 'x64':
|
|
172
|
+
if (isMusl()) {
|
|
173
|
+
localFileExisted = existsSync(
|
|
174
|
+
join(__dirname, '${localName}.linux-x64-musl.node')
|
|
175
|
+
)
|
|
176
|
+
try {
|
|
177
|
+
if (localFileExisted) {
|
|
178
|
+
nativeBinding = require('./${localName}.linux-x64-musl.node')
|
|
179
|
+
} else {
|
|
180
|
+
nativeBinding = require('${pkgName}-linux-x64-musl')
|
|
181
|
+
}
|
|
182
|
+
} catch (e) {
|
|
183
|
+
loadError = e
|
|
184
|
+
}
|
|
185
|
+
} else {
|
|
186
|
+
localFileExisted = existsSync(
|
|
187
|
+
join(__dirname, '${localName}.linux-x64-gnu.node')
|
|
188
|
+
)
|
|
189
|
+
try {
|
|
190
|
+
if (localFileExisted) {
|
|
191
|
+
nativeBinding = require('./${localName}.linux-x64-gnu.node')
|
|
192
|
+
} else {
|
|
193
|
+
nativeBinding = require('${pkgName}-linux-x64-gnu')
|
|
194
|
+
}
|
|
195
|
+
} catch (e) {
|
|
196
|
+
loadError = e
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
break
|
|
200
|
+
case 'arm64':
|
|
201
|
+
if (isMusl()) {
|
|
202
|
+
localFileExisted = existsSync(
|
|
203
|
+
join(__dirname, '${localName}.linux-arm64-musl.node')
|
|
204
|
+
)
|
|
205
|
+
try {
|
|
206
|
+
if (localFileExisted) {
|
|
207
|
+
nativeBinding = require('./${localName}.linux-arm64-musl.node')
|
|
208
|
+
} else {
|
|
209
|
+
nativeBinding = require('${pkgName}-linux-arm64-musl')
|
|
210
|
+
}
|
|
211
|
+
} catch (e) {
|
|
212
|
+
loadError = e
|
|
213
|
+
}
|
|
214
|
+
} else {
|
|
215
|
+
localFileExisted = existsSync(
|
|
216
|
+
join(__dirname, '${localName}.linux-arm64-gnu.node')
|
|
217
|
+
)
|
|
218
|
+
try {
|
|
219
|
+
if (localFileExisted) {
|
|
220
|
+
nativeBinding = require('./${localName}.linux-arm64-gnu.node')
|
|
221
|
+
} else {
|
|
222
|
+
nativeBinding = require('${pkgName}-linux-arm64-gnu')
|
|
223
|
+
}
|
|
224
|
+
} catch (e) {
|
|
225
|
+
loadError = e
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
break
|
|
229
|
+
case 'arm':
|
|
230
|
+
localFileExisted = existsSync(
|
|
231
|
+
join(__dirname, '${localName}.linux-arm-gnueabihf.node')
|
|
232
|
+
)
|
|
233
|
+
try {
|
|
234
|
+
if (localFileExisted) {
|
|
235
|
+
nativeBinding = require('./${localName}.linux-arm-gnueabihf.node')
|
|
236
|
+
} else {
|
|
237
|
+
nativeBinding = require('${pkgName}-linux-arm-gnueabihf')
|
|
238
|
+
}
|
|
239
|
+
} catch (e) {
|
|
240
|
+
loadError = e
|
|
241
|
+
}
|
|
242
|
+
break
|
|
243
|
+
default:
|
|
244
|
+
throw new Error(\`Unsupported architecture on Linux: \${arch}\`)
|
|
117
245
|
}
|
|
246
|
+
break
|
|
247
|
+
default:
|
|
248
|
+
throw new Error(\`Unsupported OS: \${platform}, architecture: \${arch}\`)
|
|
249
|
+
}
|
|
118
250
|
|
|
119
|
-
|
|
251
|
+
if (!nativeBinding) {
|
|
252
|
+
if (loadError) {
|
|
253
|
+
throw loadError
|
|
120
254
|
}
|
|
121
|
-
|
|
122
|
-
return nativeBinding
|
|
255
|
+
throw new Error(\`Failed to load native binding\`)
|
|
123
256
|
}
|
|
124
257
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
module.exports = loadNapiModule('${localName}', '${pkgName}')
|
|
258
|
+
${idents
|
|
259
|
+
.map((ident) => `module.exports.${ident} = binding.${ident}`)
|
|
260
|
+
.join('\n')}
|
|
129
261
|
`
|
|
130
262
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { CommonPackageJsonFields } from '../../utils/config.js'
|
|
2
|
+
|
|
1
3
|
export const createPackageJson = ({
|
|
2
4
|
name,
|
|
3
5
|
binaryName,
|
|
@@ -13,31 +15,34 @@ export const createPackageJson = ({
|
|
|
13
15
|
engineRequirement: string
|
|
14
16
|
cliVersion: string
|
|
15
17
|
}) => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
18
|
+
const content: CommonPackageJsonFields = {
|
|
19
|
+
name,
|
|
20
|
+
version: '1.0.0',
|
|
21
|
+
license,
|
|
22
|
+
engines: {
|
|
23
|
+
node: engineRequirement,
|
|
24
|
+
},
|
|
25
|
+
type: 'commonjs',
|
|
26
|
+
main: 'index.js',
|
|
27
|
+
types: 'index.d.ts',
|
|
28
|
+
module: undefined,
|
|
29
|
+
exports: undefined,
|
|
30
|
+
napi: {
|
|
31
|
+
binaryName,
|
|
32
|
+
targets,
|
|
33
|
+
},
|
|
34
|
+
scripts: {
|
|
35
|
+
test: 'node -e "assert(require(\'.\').sum(1, 2) === 3)"',
|
|
36
|
+
build: 'napi build --release --platform --strip',
|
|
37
|
+
'build:debug': 'napi build',
|
|
38
|
+
prepublishOnly: 'napi prepublish -t npm',
|
|
39
|
+
artifacts: 'napi artifacts',
|
|
40
|
+
version: 'napi version',
|
|
41
|
+
},
|
|
42
|
+
devDependencies: {
|
|
43
|
+
'@napi-rs/cli': `^${cliVersion}`,
|
|
44
|
+
},
|
|
41
45
|
}
|
|
42
|
-
|
|
46
|
+
|
|
47
|
+
return JSON.stringify(content, null, 2)
|
|
43
48
|
}
|
package/src/commands/new.ts
CHANGED
|
@@ -94,10 +94,6 @@ export class NewCommand extends BaseNewCommand {
|
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
private async fetchTargets(): Promise<TargetTriple[]> {
|
|
97
|
-
if (this.enableDefaultTargets) {
|
|
98
|
-
return DEFAULT_TARGETS.concat()
|
|
99
|
-
}
|
|
100
|
-
|
|
101
97
|
if (this.enableAllTargets) {
|
|
102
98
|
return AVAILABLE_TARGETS.concat()
|
|
103
99
|
}
|
|
@@ -107,7 +103,7 @@ export class NewCommand extends BaseNewCommand {
|
|
|
107
103
|
type: 'checkbox',
|
|
108
104
|
loop: false,
|
|
109
105
|
message: 'Choose target(s) your crate will be compiled to',
|
|
110
|
-
default: DEFAULT_TARGETS,
|
|
106
|
+
default: this.enableDefaultTargets ? DEFAULT_TARGETS : [],
|
|
111
107
|
choices: AVAILABLE_TARGETS,
|
|
112
108
|
})
|
|
113
109
|
|
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
|
|
@@ -10,11 +10,11 @@ Generated by [AVA](https://avajs.dev).
|
|
|
10
10
|
|
|
11
11
|
[
|
|
12
12
|
'>= 8.6.0',
|
|
13
|
-
'>= 8.10.0
|
|
14
|
-
'>= 6.14.2
|
|
15
|
-
'>= 10.16.0
|
|
16
|
-
'>= 10.17.0
|
|
17
|
-
'>= 10.20.0
|
|
18
|
-
'>= 10.23.0
|
|
19
|
-
'>= 12.22.0
|
|
13
|
+
'>= 8.10.0 < 9 || >= 9.3.0',
|
|
14
|
+
'>= 6.14.2 < 7 || >= 8.11.2 < 9 || >= 9.11.0',
|
|
15
|
+
'>= 10.16.0 < 11 || >= 11.8.0',
|
|
16
|
+
'>= 10.17.0 < 11 || >= 12.11.0',
|
|
17
|
+
'>= 10.20.0 < 11 || >= 12.17.0 < 13 || >= 14.0.0',
|
|
18
|
+
'>= 10.23.0 < 11 || >= 12.19.0 < 13 || >= 14.12.0',
|
|
19
|
+
'>= 12.22.0 < 13 || >= 14.17.0 < 15 || >= 15.12.0',
|
|
20
20
|
]
|
|
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/config.ts
CHANGED
|
@@ -49,7 +49,7 @@ interface UserNapiConfig {
|
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
interface CommonPackageJsonFields {
|
|
52
|
+
export interface CommonPackageJsonFields {
|
|
53
53
|
name: string
|
|
54
54
|
version: string
|
|
55
55
|
description?: string
|
|
@@ -64,6 +64,17 @@ interface CommonPackageJsonFields {
|
|
|
64
64
|
bugs?: any
|
|
65
65
|
// eslint-disable-next-line no-use-before-define
|
|
66
66
|
napi?: UserNapiConfig
|
|
67
|
+
type?: 'module' | 'commonjs'
|
|
68
|
+
scripts?: Record<string, string>
|
|
69
|
+
|
|
70
|
+
// modules
|
|
71
|
+
main?: string
|
|
72
|
+
module?: string
|
|
73
|
+
types?: string
|
|
74
|
+
exports?: any
|
|
75
|
+
|
|
76
|
+
dependencies?: Record<string, string>
|
|
77
|
+
devDependencies?: Record<string, string>
|
|
67
78
|
}
|
|
68
79
|
|
|
69
80
|
export type NapiConfig = Required<
|
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> = {
|
package/src/utils/typegen.ts
CHANGED
|
@@ -54,6 +54,7 @@ export async function processTypeDef(
|
|
|
54
54
|
intermediateTypeFile: string,
|
|
55
55
|
header?: string,
|
|
56
56
|
) {
|
|
57
|
+
const exports: string[] = []
|
|
57
58
|
const defs = await readIntermediateTypeFile(intermediateTypeFile)
|
|
58
59
|
const groupedDefs = preprocessTypeDef(defs)
|
|
59
60
|
|
|
@@ -65,8 +66,23 @@ export async function processTypeDef(
|
|
|
65
66
|
if (namespace === TOP_LEVEL_NAMESPACE) {
|
|
66
67
|
for (const def of defs) {
|
|
67
68
|
dts += prettyPrint(def, 0) + '\n\n'
|
|
69
|
+
switch (def.kind) {
|
|
70
|
+
case TypeDefKind.Const:
|
|
71
|
+
case TypeDefKind.Enum:
|
|
72
|
+
case TypeDefKind.Fn:
|
|
73
|
+
case TypeDefKind.Struct: {
|
|
74
|
+
exports.push(def.name)
|
|
75
|
+
if (def.original_name && def.original_name !== def.name) {
|
|
76
|
+
exports.push(def.original_name)
|
|
77
|
+
}
|
|
78
|
+
break
|
|
79
|
+
}
|
|
80
|
+
default:
|
|
81
|
+
break
|
|
82
|
+
}
|
|
68
83
|
}
|
|
69
84
|
} else {
|
|
85
|
+
exports.push(namespace)
|
|
70
86
|
dts += `export namespace ${namespace} {\n`
|
|
71
87
|
for (const def of defs) {
|
|
72
88
|
dts += prettyPrint(def, 2) + '\n'
|
|
@@ -87,7 +103,10 @@ export class ExternalObject<T> {
|
|
|
87
103
|
`
|
|
88
104
|
}
|
|
89
105
|
|
|
90
|
-
return
|
|
106
|
+
return {
|
|
107
|
+
dts: header + dts,
|
|
108
|
+
exports,
|
|
109
|
+
}
|
|
91
110
|
}
|
|
92
111
|
|
|
93
112
|
async function readIntermediateTypeFile(file: string) {
|