@neon-rs/cli 0.0.1
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/LICENSE +21 -0
- package/LICENSE.triples.txt +21 -0
- package/README.md +10 -0
- package/data/llvm.json +42 -0
- package/data/node.json +281 -0
- package/dist/cargo.js +159 -0
- package/dist/commands/cross-dist.js +40 -0
- package/dist/commands/cross-install.js +42 -0
- package/dist/commands/cross-pack.js +81 -0
- package/dist/commands/dist.js +38 -0
- package/dist/index.js +52 -0
- package/dist/usage.js +150 -0
- package/package.json +56 -0
- package/types/cargo.d.ts +42 -0
- package/types/commands/cross-dist.d.ts +1 -0
- package/types/commands/cross-install.d.ts +1 -0
- package/types/commands/cross-pack.d.ts +1 -0
- package/types/commands/dist.d.ts +1 -0
- package/types/index.d.ts +3 -0
- package/types/usage.d.ts +3 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 David Herman
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 LongYinan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# `@neon-rs/cli`
|
|
2
|
+
|
|
3
|
+
A command-line tool for packaging and distributing Neon projects.
|
|
4
|
+
|
|
5
|
+
## License
|
|
6
|
+
|
|
7
|
+
This tool is provided under the MIT license.
|
|
8
|
+
|
|
9
|
+
Includes other software related under the MIT license:
|
|
10
|
+
- The file `node.json` is derived from [@napi-rs/triples](https://github.com/napi-rs/napi-rs/tree/main/triples) (see `LICENSE-triples.txt`).
|
package/data/llvm.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"aarch64-apple-darwin": ["darwin", "arm64", 0],
|
|
3
|
+
"x86_64-apple-darwin": ["darwin", "x64", 0],
|
|
4
|
+
"aarch64-apple-ios": ["ios", "arm64", 0],
|
|
5
|
+
"x86_64-apple-ios": ["ios", "x64", 0],
|
|
6
|
+
"aarch64-linux-android": ["android", "arm64", 0],
|
|
7
|
+
"armv7-linux-androideabi": ["android", "arm", 0],
|
|
8
|
+
"i686-linux-android": ["android", "ia32", 0],
|
|
9
|
+
"x86_64-linux-android": ["android", "x64", 0],
|
|
10
|
+
"aarch64-pc-windows-msvc": ["win32", "arm64", 0],
|
|
11
|
+
"i686-pc-windows-gnu": ["win32", "ia32", 0],
|
|
12
|
+
"i686-pc-windows-msvc": ["win32", "ia32", 1],
|
|
13
|
+
"x86_64-pc-windows-gnu": ["win32", "x64", 0],
|
|
14
|
+
"x86_64-pc-windows-msvc": ["win32", "x64", 1],
|
|
15
|
+
"aarch64-unknown-linux-gnu": ["linux", "arm64", 0],
|
|
16
|
+
"aarch64-unknown-linux-musl": ["linux", "arm64", 1],
|
|
17
|
+
"arm-unknown-linux-gnueabihf": ["linux", "arm", 0],
|
|
18
|
+
"arm-unknown-linux-musleabihf": ["linux", "arm", 1],
|
|
19
|
+
"armv7-unknown-linux-gnueabihf": ["linux", "arm", 2],
|
|
20
|
+
"armv7-unknown-linux-musleabihf": ["linux", "arm", 3],
|
|
21
|
+
"i686-unknown-linux-gnu": ["linux", "ia32", 0],
|
|
22
|
+
"i686-unknown-linux-musl": ["linux", "ia32", 1],
|
|
23
|
+
"mips-unknown-linux-gnu": ["linux", "mips", 0],
|
|
24
|
+
"mips-unknown-linux-musl": ["linux", "mips", 1],
|
|
25
|
+
"mips64-unknown-linux-gnuabi64": ["linux", "mips64", 0],
|
|
26
|
+
"mips64-unknown-linux-muslabi64": ["linux", "mips64", 1],
|
|
27
|
+
"mips64el-unknown-linux-gnuabi64": ["linux", "mips64el", 0],
|
|
28
|
+
"mips64el-unknown-linux-muslabi64": ["linux", "mips64el", 1],
|
|
29
|
+
"mipsel-unknown-linux-gnu": ["linux", "mipsel", 0],
|
|
30
|
+
"mipsel-unknown-linux-musl": ["linux", "mipsel", 1],
|
|
31
|
+
"powerpc-unknown-linux-gnu": ["linux", "powerpc", 0],
|
|
32
|
+
"powerpc64-unknown-linux-gnu": ["linux", "powerpc64", 0],
|
|
33
|
+
"powerpc64le-unknown-linux-gnu": ["linux", "powerpc64le", 0],
|
|
34
|
+
"riscv64gc-unknown-linux-gnu": ["linux", "riscv64gc", 0],
|
|
35
|
+
"s390x-unknown-linux-gnu": ["linux", "s390x", 0],
|
|
36
|
+
"sparc64-unknown-linux-gnu": ["linux", "sparc64", 0],
|
|
37
|
+
"x86_64-unknown-linux-gnu": ["linux", "x64", 0],
|
|
38
|
+
"x86_64-unknown-linux-gnux32": ["linux", "x64", 1],
|
|
39
|
+
"x86_64-unknown-linux-musl": ["linux", "x64", 2],
|
|
40
|
+
"i686-unknown-freebsd": ["freebsd", "ia32", 0],
|
|
41
|
+
"x86_64-unknown-freebsd": ["freebsd", "x64", 0]
|
|
42
|
+
}
|
package/data/node.json
ADDED
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
{
|
|
2
|
+
"darwin": {
|
|
3
|
+
"arm64": [{
|
|
4
|
+
"platform": "darwin",
|
|
5
|
+
"arch": "arm64",
|
|
6
|
+
"abi": null,
|
|
7
|
+
"node": "darwin-arm64",
|
|
8
|
+
"llvm": "aarch64-apple-darwin"
|
|
9
|
+
}],
|
|
10
|
+
"x64": [{
|
|
11
|
+
"platform": "darwin",
|
|
12
|
+
"arch": "x64",
|
|
13
|
+
"abi": null,
|
|
14
|
+
"node": "darwin-x64",
|
|
15
|
+
"llvm": "x86_64-apple-darwin"
|
|
16
|
+
}]
|
|
17
|
+
},
|
|
18
|
+
"ios": {
|
|
19
|
+
"arm64": [{
|
|
20
|
+
"platform": "ios",
|
|
21
|
+
"arch": "arm64",
|
|
22
|
+
"abi": null,
|
|
23
|
+
"node": "ios-arm64",
|
|
24
|
+
"llvm": "aarch64-apple-ios"
|
|
25
|
+
}],
|
|
26
|
+
"x64": [{
|
|
27
|
+
"platform": "ios",
|
|
28
|
+
"arch": "x64",
|
|
29
|
+
"abi": null,
|
|
30
|
+
"node": "ios-x64",
|
|
31
|
+
"llvm": "x86_64-apple-ios"
|
|
32
|
+
}]
|
|
33
|
+
},
|
|
34
|
+
"android": {
|
|
35
|
+
"arm64": [{
|
|
36
|
+
"platform": "android",
|
|
37
|
+
"arch": "arm64",
|
|
38
|
+
"abi": null,
|
|
39
|
+
"node": "android-arm64",
|
|
40
|
+
"llvm": "aarch64-linux-android"
|
|
41
|
+
}],
|
|
42
|
+
"arm": [{
|
|
43
|
+
"platform": "android",
|
|
44
|
+
"arch": "arm",
|
|
45
|
+
"abi": "eabi",
|
|
46
|
+
"node": "android-arm-eabi",
|
|
47
|
+
"llvm": "armv7-linux-androideabi"
|
|
48
|
+
}],
|
|
49
|
+
"ia32": [{
|
|
50
|
+
"platform": "android",
|
|
51
|
+
"arch": "ia32",
|
|
52
|
+
"abi": null,
|
|
53
|
+
"node": "android-ia32",
|
|
54
|
+
"llvm": "i686-linux-android"
|
|
55
|
+
}],
|
|
56
|
+
"x64": [{
|
|
57
|
+
"platform": "android",
|
|
58
|
+
"arch": "x64",
|
|
59
|
+
"abi": null,
|
|
60
|
+
"node": "android-x64",
|
|
61
|
+
"llvm": "x86_64-linux-android"
|
|
62
|
+
}]
|
|
63
|
+
},
|
|
64
|
+
"win32": {
|
|
65
|
+
"arm64": [{
|
|
66
|
+
"platform": "win32",
|
|
67
|
+
"arch": "arm64",
|
|
68
|
+
"abi": "msvc",
|
|
69
|
+
"node": "win32-arm64-msvc",
|
|
70
|
+
"llvm": "aarch64-pc-windows-msvc"
|
|
71
|
+
}],
|
|
72
|
+
"ia32": [{
|
|
73
|
+
"platform": "win32",
|
|
74
|
+
"arch": "ia32",
|
|
75
|
+
"abi": "gnu",
|
|
76
|
+
"node": "win32-ia32-gnu",
|
|
77
|
+
"llvm": "i686-pc-windows-gnu"
|
|
78
|
+
}, {
|
|
79
|
+
"platform": "win32",
|
|
80
|
+
"arch": "ia32",
|
|
81
|
+
"abi": "msvc",
|
|
82
|
+
"node": "win32-ia32-msvc",
|
|
83
|
+
"llvm": "i686-pc-windows-msvc"
|
|
84
|
+
}],
|
|
85
|
+
"x64": [{
|
|
86
|
+
"platform": "win32",
|
|
87
|
+
"arch": "x64",
|
|
88
|
+
"abi": "gnu",
|
|
89
|
+
"node": "win32-x64-gnu",
|
|
90
|
+
"llvm": "x86_64-pc-windows-gnu"
|
|
91
|
+
}, {
|
|
92
|
+
"platform": "win32",
|
|
93
|
+
"arch": "x64",
|
|
94
|
+
"abi": "msvc",
|
|
95
|
+
"node": "win32-x64-msvc",
|
|
96
|
+
"llvm": "x86_64-pc-windows-msvc"
|
|
97
|
+
}]
|
|
98
|
+
},
|
|
99
|
+
"linux": {
|
|
100
|
+
"arm64": [{
|
|
101
|
+
"platform": "linux",
|
|
102
|
+
"arch": "arm64",
|
|
103
|
+
"abi": "gnu",
|
|
104
|
+
"node": "linux-arm64-gnu",
|
|
105
|
+
"llvm": "aarch64-unknown-linux-gnu"
|
|
106
|
+
}, {
|
|
107
|
+
"platform": "linux",
|
|
108
|
+
"arch": "arm64",
|
|
109
|
+
"abi": "musl",
|
|
110
|
+
"node": "linux-arm64-musl",
|
|
111
|
+
"llvm": "aarch64-unknown-linux-musl"
|
|
112
|
+
}],
|
|
113
|
+
"arm": [{
|
|
114
|
+
"platform": "linux",
|
|
115
|
+
"arch": "arm",
|
|
116
|
+
"abi": "gnueabihf",
|
|
117
|
+
"node": "linux-arm-gnueabihf",
|
|
118
|
+
"llvm": "arm-unknown-linux-gnueabihf"
|
|
119
|
+
}, {
|
|
120
|
+
"platform": "linux",
|
|
121
|
+
"arch": "arm",
|
|
122
|
+
"abi": "musleabihf",
|
|
123
|
+
"node": "linux-arm-musleabihf",
|
|
124
|
+
"llvm": "arm-unknown-linux-musleabihf"
|
|
125
|
+
}, {
|
|
126
|
+
"platform": "linux",
|
|
127
|
+
"arch": "arm",
|
|
128
|
+
"abi": "gnueabihf",
|
|
129
|
+
"node": "linux-arm-gnueabihf",
|
|
130
|
+
"llvm": "armv7-unknown-linux-gnueabihf"
|
|
131
|
+
}, {
|
|
132
|
+
"platform": "linux",
|
|
133
|
+
"arch": "arm",
|
|
134
|
+
"abi": "musleabihf",
|
|
135
|
+
"node": "linux-arm-musleabihf",
|
|
136
|
+
"llvm": "armv7-unknown-linux-musleabihf"
|
|
137
|
+
}],
|
|
138
|
+
"ia32": [{
|
|
139
|
+
"platform": "linux",
|
|
140
|
+
"arch": "ia32",
|
|
141
|
+
"abi": "gnu",
|
|
142
|
+
"node": "linux-ia32-gnu",
|
|
143
|
+
"llvm": "i686-unknown-linux-gnu"
|
|
144
|
+
}, {
|
|
145
|
+
"platform": "linux",
|
|
146
|
+
"arch": "ia32",
|
|
147
|
+
"abi": "musl",
|
|
148
|
+
"node": "linux-ia32-musl",
|
|
149
|
+
"llvm": "i686-unknown-linux-musl"
|
|
150
|
+
}],
|
|
151
|
+
"mips": [{
|
|
152
|
+
"platform": "linux",
|
|
153
|
+
"arch": "mips",
|
|
154
|
+
"abi": "gnu",
|
|
155
|
+
"node": "linux-mips-gnu",
|
|
156
|
+
"llvm": "mips-unknown-linux-gnu"
|
|
157
|
+
}, {
|
|
158
|
+
"platform": "linux",
|
|
159
|
+
"arch": "mips",
|
|
160
|
+
"abi": "musl",
|
|
161
|
+
"node": "linux-mips-musl",
|
|
162
|
+
"llvm": "mips-unknown-linux-musl"
|
|
163
|
+
}],
|
|
164
|
+
"mips64": [{
|
|
165
|
+
"platform": "linux",
|
|
166
|
+
"arch": "mips64",
|
|
167
|
+
"abi": "gnuabi64",
|
|
168
|
+
"node": "linux-mips64-gnuabi64",
|
|
169
|
+
"llvm": "mips64-unknown-linux-gnuabi64"
|
|
170
|
+
}, {
|
|
171
|
+
"platform": "linux",
|
|
172
|
+
"arch": "mips64",
|
|
173
|
+
"abi": "muslabi64",
|
|
174
|
+
"node": "linux-mips64-muslabi64",
|
|
175
|
+
"llvm": "mips64-unknown-linux-muslabi64"
|
|
176
|
+
}],
|
|
177
|
+
"mips64el": [{
|
|
178
|
+
"platform": "linux",
|
|
179
|
+
"arch": "mips64el",
|
|
180
|
+
"abi": "gnuabi64",
|
|
181
|
+
"node": "linux-mips64el-gnuabi64",
|
|
182
|
+
"llvm": "mips64el-unknown-linux-gnuabi64"
|
|
183
|
+
}, {
|
|
184
|
+
"platform": "linux",
|
|
185
|
+
"arch": "mips64el",
|
|
186
|
+
"abi": "muslabi64",
|
|
187
|
+
"node": "linux-mips64el-muslabi64",
|
|
188
|
+
"llvm": "mips64el-unknown-linux-muslabi64"
|
|
189
|
+
}],
|
|
190
|
+
"mipsel": [{
|
|
191
|
+
"platform": "linux",
|
|
192
|
+
"arch": "mipsel",
|
|
193
|
+
"abi": "gnu",
|
|
194
|
+
"node": "linux-mipsel-gnu",
|
|
195
|
+
"llvm": "mipsel-unknown-linux-gnu"
|
|
196
|
+
}, {
|
|
197
|
+
"platform": "linux",
|
|
198
|
+
"arch": "mipsel",
|
|
199
|
+
"abi": "musl",
|
|
200
|
+
"node": "linux-mipsel-musl",
|
|
201
|
+
"llvm": "mipsel-unknown-linux-musl"
|
|
202
|
+
}],
|
|
203
|
+
"powerpc": [{
|
|
204
|
+
"platform": "linux",
|
|
205
|
+
"arch": "powerpc",
|
|
206
|
+
"abi": "gnu",
|
|
207
|
+
"node": "linux-powerpc-gnu",
|
|
208
|
+
"llvm": "powerpc-unknown-linux-gnu"
|
|
209
|
+
}],
|
|
210
|
+
"powerpc64": [{
|
|
211
|
+
"platform": "linux",
|
|
212
|
+
"arch": "powerpc64",
|
|
213
|
+
"abi": "gnu",
|
|
214
|
+
"node": "linux-powerpc64-gnu",
|
|
215
|
+
"llvm": "powerpc64-unknown-linux-gnu"
|
|
216
|
+
}],
|
|
217
|
+
"powerpc64le": [{
|
|
218
|
+
"platform": "linux",
|
|
219
|
+
"arch": "powerpc64le",
|
|
220
|
+
"abi": "gnu",
|
|
221
|
+
"node": "linux-powerpc64le-gnu",
|
|
222
|
+
"llvm": "powerpc64le-unknown-linux-gnu"
|
|
223
|
+
}],
|
|
224
|
+
"riscv64gc": [{
|
|
225
|
+
"platform": "linux",
|
|
226
|
+
"arch": "riscv64gc",
|
|
227
|
+
"abi": "gnu",
|
|
228
|
+
"node": "linux-riscv64gc-gnu",
|
|
229
|
+
"llvm": "riscv64gc-unknown-linux-gnu"
|
|
230
|
+
}],
|
|
231
|
+
"s390x": [{
|
|
232
|
+
"platform": "linux",
|
|
233
|
+
"arch": "s390x",
|
|
234
|
+
"abi": "gnu",
|
|
235
|
+
"node": "linux-s390x-gnu",
|
|
236
|
+
"llvm": "s390x-unknown-linux-gnu"
|
|
237
|
+
}],
|
|
238
|
+
"sparc64": [{
|
|
239
|
+
"platform": "linux",
|
|
240
|
+
"arch": "sparc64",
|
|
241
|
+
"abi": "gnu",
|
|
242
|
+
"node": "linux-sparc64-gnu",
|
|
243
|
+
"llvm": "sparc64-unknown-linux-gnu"
|
|
244
|
+
}],
|
|
245
|
+
"x64": [{
|
|
246
|
+
"platform": "linux",
|
|
247
|
+
"arch": "x64",
|
|
248
|
+
"abi": "gnu",
|
|
249
|
+
"node": "linux-x64-gnu",
|
|
250
|
+
"llvm": "x86_64-unknown-linux-gnu"
|
|
251
|
+
}, {
|
|
252
|
+
"platform": "linux",
|
|
253
|
+
"arch": "x64",
|
|
254
|
+
"abi": "gnux32",
|
|
255
|
+
"node": "linux-x64-gnux32",
|
|
256
|
+
"llvm": "x86_64-unknown-linux-gnux32"
|
|
257
|
+
}, {
|
|
258
|
+
"platform": "linux",
|
|
259
|
+
"arch": "x64",
|
|
260
|
+
"abi": "musl",
|
|
261
|
+
"node": "linux-x64-musl",
|
|
262
|
+
"llvm": "x86_64-unknown-linux-musl"
|
|
263
|
+
}]
|
|
264
|
+
},
|
|
265
|
+
"freebsd": {
|
|
266
|
+
"ia32": [{
|
|
267
|
+
"platform": "freebsd",
|
|
268
|
+
"arch": "ia32",
|
|
269
|
+
"abi": null,
|
|
270
|
+
"node": "freebsd-ia32",
|
|
271
|
+
"llvm": "i686-unknown-freebsd"
|
|
272
|
+
}],
|
|
273
|
+
"x64": [{
|
|
274
|
+
"platform": "freebsd",
|
|
275
|
+
"arch": "x64",
|
|
276
|
+
"abi": null,
|
|
277
|
+
"node": "freebsd-x64",
|
|
278
|
+
"llvm": "x86_64-unknown-freebsd"
|
|
279
|
+
}]
|
|
280
|
+
}
|
|
281
|
+
}
|
package/dist/cargo.js
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { createReadStream } from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import * as readline from 'node:readline';
|
|
4
|
+
import { execa } from 'execa';
|
|
5
|
+
export function messageReason(message) {
|
|
6
|
+
return message.reason;
|
|
7
|
+
}
|
|
8
|
+
export function isCompilerMessage(json) {
|
|
9
|
+
if (!(json instanceof Object)) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
if (!('reason' in json) || (json.reason !== 'compiler-message')) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
export function isBuildScriptExecuted(json) {
|
|
18
|
+
if (!(json instanceof Object)) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
if (!('reason' in json) || (json.reason !== 'build-script-executed')) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
export function isCompilerTarget(json) {
|
|
27
|
+
if (!(json instanceof Object)) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
if (!('kind' in json) || !isStringArray(json.kind)) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
if (!('crate_types' in json) || !isStringArray(json.crate_types)) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
if (!('name' in json) || (typeof json.name !== 'string')) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
export function isCompilerArtifact(json) {
|
|
42
|
+
if (!(json instanceof Object)) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
if (!('reason' in json) || (json.reason !== 'compiler-artifact')) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
if (!('package_id' in json) || (typeof json.package_id !== 'string')) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
if (!('manifest_path' in json) || (typeof json.manifest_path !== 'string')) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
if (!('target' in json) || !isCompilerTarget(json.target)) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
if (!('filenames' in json) || !isStringArray(json.filenames)) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
function isStringArray(json) {
|
|
63
|
+
if (!Array.isArray(json)) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
for (const val of json) {
|
|
67
|
+
if (typeof val !== 'string') {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
export function isBuildFinished(json) {
|
|
74
|
+
if (!(json instanceof Object)) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
if (!('reason' in json) || (json.reason !== 'build-finished')) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
return ('success' in json) && (typeof json.success === 'boolean');
|
|
81
|
+
}
|
|
82
|
+
export function parseMessage(line) {
|
|
83
|
+
try {
|
|
84
|
+
const json = JSON.parse(line);
|
|
85
|
+
if (isCompilerMessage(json) ||
|
|
86
|
+
isBuildScriptExecuted(json) ||
|
|
87
|
+
isCompilerArtifact(json) ||
|
|
88
|
+
isBuildFinished(json)) {
|
|
89
|
+
return json;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
catch (nope) { }
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
export class MessageStream {
|
|
96
|
+
constructor(file) {
|
|
97
|
+
const input = file ? createReadStream(file) : process.stdin;
|
|
98
|
+
this._stream = readline.createInterface({
|
|
99
|
+
input,
|
|
100
|
+
terminal: false
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
async findPath(pred) {
|
|
104
|
+
try {
|
|
105
|
+
for await (const line of this._stream) {
|
|
106
|
+
const msg = parseMessage(line);
|
|
107
|
+
if (!msg) {
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
const result = pred(msg);
|
|
111
|
+
if (result !== null) {
|
|
112
|
+
return result;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
finally {
|
|
118
|
+
this._stream.close();
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
export class CrossMessageStream extends MessageStream {
|
|
123
|
+
constructor(dir, file) {
|
|
124
|
+
super(file);
|
|
125
|
+
this._dir = dir;
|
|
126
|
+
}
|
|
127
|
+
async findPath(pred) {
|
|
128
|
+
// The base class's version reports paths as absolute paths from within
|
|
129
|
+
// the cross-rs Docker image's virtual filesystem.
|
|
130
|
+
const dockerPath = await super.findPath(pred);
|
|
131
|
+
if (!dockerPath) {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
// Convert the absolute path into a relative path from within the
|
|
135
|
+
// workspace's target directory.
|
|
136
|
+
const cross = await execa('cross', ['metadata', '--format-version=1', '--no-deps'], {
|
|
137
|
+
cwd: this._dir,
|
|
138
|
+
shell: true
|
|
139
|
+
});
|
|
140
|
+
if (cross.exitCode !== 0) {
|
|
141
|
+
throw new Error(`Invoking \`cross metadata\` failed: ${cross.stderr}`);
|
|
142
|
+
}
|
|
143
|
+
const crossMetadata = JSON.parse(cross.stdout);
|
|
144
|
+
// The path relative to the workspace's target directory.
|
|
145
|
+
const relPath = path.relative(crossMetadata.target_directory, dockerPath);
|
|
146
|
+
// Now find the true absolute path of the target directory on the host system.
|
|
147
|
+
const cargo = await execa('cargo', ['metadata', '--format-version=1', '--no-deps'], {
|
|
148
|
+
cwd: this._dir,
|
|
149
|
+
shell: true
|
|
150
|
+
});
|
|
151
|
+
if (cargo.exitCode !== 0) {
|
|
152
|
+
throw new Error(`Invoking \`cargo metadata\` failed: ${cargo.stderr}`);
|
|
153
|
+
}
|
|
154
|
+
const cargoMetadata = JSON.parse(cargo.stdout);
|
|
155
|
+
// Finally, re-parent the relative path into an absolute path on the host system.
|
|
156
|
+
const absPath = path.join(cargoMetadata.target_directory, relPath);
|
|
157
|
+
return absPath;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { copyFile } from 'node:fs/promises';
|
|
2
|
+
import commandLineArgs from 'command-line-args';
|
|
3
|
+
import { CrossMessageStream, isCompilerArtifact } from '../cargo.js';
|
|
4
|
+
// FIXME: add options to infer crate name from manifests
|
|
5
|
+
// --package <path/to/package.json>
|
|
6
|
+
// --crate <path/to/Cargo.toml>
|
|
7
|
+
const OPTIONS = [
|
|
8
|
+
{ name: 'name', alias: 'n', type: String, defaultValue: null },
|
|
9
|
+
{ name: 'log', alias: 'l', type: String, defaultValue: null },
|
|
10
|
+
{ name: 'dir', alias: 'd', type: String, defaultValue: null },
|
|
11
|
+
{ name: 'file', alias: 'f', type: String, defaultValue: null },
|
|
12
|
+
{ name: 'out', alias: 'o', type: String, defaultValue: 'index.node' }
|
|
13
|
+
];
|
|
14
|
+
async function findArtifact(log, crateName, dir) {
|
|
15
|
+
const stream = new CrossMessageStream(dir, log);
|
|
16
|
+
return await stream.findPath((msg) => {
|
|
17
|
+
if (!isCompilerArtifact(msg) || (msg.target.name !== crateName)) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
const index = msg.target.crate_types.indexOf('cdylib');
|
|
21
|
+
return (index < 0) ? null : msg.filenames[index];
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
export default async function main(argv) {
|
|
25
|
+
const options = commandLineArgs(OPTIONS, { argv });
|
|
26
|
+
if (options.log && options.file) {
|
|
27
|
+
throw new Error("Options --log and --file cannot both be enabled.");
|
|
28
|
+
}
|
|
29
|
+
const crateName = options.name || process.env['npm_package_name'];
|
|
30
|
+
if (!crateName) {
|
|
31
|
+
throw new Error("No crate name provided.");
|
|
32
|
+
}
|
|
33
|
+
const dir = options.dir || process.cwd();
|
|
34
|
+
const file = options.file ?? await findArtifact(options.log, crateName, dir);
|
|
35
|
+
if (!file) {
|
|
36
|
+
throw new Error(`No library found for crate ${crateName}`);
|
|
37
|
+
}
|
|
38
|
+
// FIXME: needs all the logic of cargo-cp-artifact (timestamp check, M1 workaround, async, errors)
|
|
39
|
+
await copyFile(file, options.out);
|
|
40
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { execa } from 'execa';
|
|
2
|
+
import commandLineArgs from 'command-line-args';
|
|
3
|
+
import * as fs from 'node:fs/promises';
|
|
4
|
+
import * as path from 'node:path';
|
|
5
|
+
const OPTIONS = [
|
|
6
|
+
{ name: 'bundle', alias: 'b', type: String, defaultValue: null },
|
|
7
|
+
{ name: 'no-bundle', alias: 'B', type: String, defaultValue: null }
|
|
8
|
+
];
|
|
9
|
+
export default async function main(argv) {
|
|
10
|
+
const options = commandLineArgs(OPTIONS, { argv });
|
|
11
|
+
if (options.bundle && options['no-bundle']) {
|
|
12
|
+
throw new Error("Options --bundle and --no-bundle cannot both be enabled.");
|
|
13
|
+
}
|
|
14
|
+
if (!options.bundle && !options['no-bundle']) {
|
|
15
|
+
options.bundle = '.targets';
|
|
16
|
+
}
|
|
17
|
+
const manifest = JSON.parse(await fs.readFile(path.join(process.cwd(), 'package.json'), { encoding: 'utf8' }));
|
|
18
|
+
const version = manifest.version;
|
|
19
|
+
const targets = Object.values(manifest.neon.targets);
|
|
20
|
+
const specs = targets.map(name => `${name}@${version}`);
|
|
21
|
+
const result = await execa('npm', ['install', '--save-exact', '-O', ...specs], { shell: true });
|
|
22
|
+
if (result.exitCode !== 0) {
|
|
23
|
+
console.error(result.stderr);
|
|
24
|
+
process.exit(result.exitCode);
|
|
25
|
+
}
|
|
26
|
+
if (!options.bundle) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const PREAMBLE = `// AUTOMATICALLY GENERATED FILE. DO NOT EDIT.
|
|
30
|
+
//
|
|
31
|
+
// This code is never executed but is detected by the static analysis of
|
|
32
|
+
// bundlers such as \`@vercel/ncc\`. The require() expression that selects
|
|
33
|
+
// the right binary module for the current platform is too dynamic to be
|
|
34
|
+
// analyzable by bundler analyses, so this module provides an exhaustive
|
|
35
|
+
// static list for those analyses.
|
|
36
|
+
|
|
37
|
+
return;
|
|
38
|
+
|
|
39
|
+
`;
|
|
40
|
+
const requires = targets.map(name => `require('${name}');`).join('\n');
|
|
41
|
+
await fs.writeFile(options.bundle, PREAMBLE + requires + '\n');
|
|
42
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import * as fs from 'node:fs/promises';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import { createRequire } from 'node:module';
|
|
4
|
+
import * as temp from 'temp';
|
|
5
|
+
import commandLineArgs from 'command-line-args';
|
|
6
|
+
import { execa } from 'execa';
|
|
7
|
+
const mktemp = temp.track().mkdir;
|
|
8
|
+
const OPTIONS = [
|
|
9
|
+
{ name: 'file', alias: 'f', type: String, defaultValue: 'index.node' },
|
|
10
|
+
{ name: 'out-dir', alias: 'd', type: String, defaultValue: null }
|
|
11
|
+
];
|
|
12
|
+
const require = createRequire(import.meta.url);
|
|
13
|
+
const LLVM = require('../../data/llvm.json');
|
|
14
|
+
const NODE = require('../../data/node.json');
|
|
15
|
+
function lookup(target) {
|
|
16
|
+
const path = LLVM[target];
|
|
17
|
+
if (!path) {
|
|
18
|
+
throw new Error(`Rust target ${target} not supported`);
|
|
19
|
+
}
|
|
20
|
+
const [platform, arch, abi] = path;
|
|
21
|
+
return NODE[platform][arch][abi];
|
|
22
|
+
}
|
|
23
|
+
export default async function main(argv) {
|
|
24
|
+
const options = commandLineArgs(OPTIONS, { argv, stopAtFirstUnknown: true });
|
|
25
|
+
argv = options._unknown || [];
|
|
26
|
+
if (argv.length === 0) {
|
|
27
|
+
throw new Error("Expected <target>.");
|
|
28
|
+
}
|
|
29
|
+
if (argv.length > 1) {
|
|
30
|
+
throw new Error(`Unexpected argument \`${argv[1]}\`.`);
|
|
31
|
+
}
|
|
32
|
+
const target = argv[0];
|
|
33
|
+
const addon = options.file;
|
|
34
|
+
const outDir = options['out-dir'] || path.join(process.cwd(), 'dist');
|
|
35
|
+
await fs.mkdir(outDir, { recursive: true });
|
|
36
|
+
const manifest = JSON.parse(await fs.readFile('package.json', { encoding: 'utf8' }));
|
|
37
|
+
const version = manifest.version;
|
|
38
|
+
const targets = manifest.neon.targets;
|
|
39
|
+
const name = targets[target];
|
|
40
|
+
if (!name) {
|
|
41
|
+
throw new Error(`Rust target ${target} not found in package.json.`);
|
|
42
|
+
}
|
|
43
|
+
const targetInfo = lookup(target);
|
|
44
|
+
const description = `Prebuilt binary package for \`${manifest.name}\` on \`${targetInfo.node}\`.`;
|
|
45
|
+
let prebuildManifest = {
|
|
46
|
+
name,
|
|
47
|
+
description,
|
|
48
|
+
version,
|
|
49
|
+
os: [targetInfo.platform],
|
|
50
|
+
cpu: [targetInfo.arch],
|
|
51
|
+
main: "index.node",
|
|
52
|
+
files: ["README.md", "index.node"]
|
|
53
|
+
};
|
|
54
|
+
const OPTIONAL_KEYS = [
|
|
55
|
+
'author', 'repository', 'keywords', 'bugs', 'homepage', 'license', 'engines'
|
|
56
|
+
];
|
|
57
|
+
for (const key of OPTIONAL_KEYS) {
|
|
58
|
+
if (manifest[key]) {
|
|
59
|
+
prebuildManifest[key] = manifest[key];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const tmpdir = await mktemp('neon-');
|
|
63
|
+
await fs.writeFile(path.join(tmpdir, "package.json"), JSON.stringify(prebuildManifest, null, 2));
|
|
64
|
+
await fs.copyFile(addon, path.join(tmpdir, "index.node"));
|
|
65
|
+
await fs.writeFile(path.join(tmpdir, "README.md"), `# \`${name}\`\n\n${description}\n`);
|
|
66
|
+
const result = await execa("npm", ["pack", "--json"], {
|
|
67
|
+
shell: true,
|
|
68
|
+
cwd: tmpdir,
|
|
69
|
+
stdio: ['pipe', 'pipe', 'inherit']
|
|
70
|
+
});
|
|
71
|
+
if (result.exitCode !== 0) {
|
|
72
|
+
process.exit(result.exitCode);
|
|
73
|
+
}
|
|
74
|
+
// FIXME: comment linking to the npm issue this fixes
|
|
75
|
+
const tarball = JSON.parse(result.stdout)[0].filename.replace('@', '').replace('/', '-');
|
|
76
|
+
const dest = path.join(outDir, tarball);
|
|
77
|
+
// Copy instead of move since e.g. GitHub Actions Windows runners host temp directories
|
|
78
|
+
// on a different device (which causes fs.renameSync to fail).
|
|
79
|
+
await fs.copyFile(path.join(tmpdir, tarball), dest);
|
|
80
|
+
console.log(dest);
|
|
81
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { copyFile } from 'node:fs/promises';
|
|
2
|
+
import commandLineArgs from 'command-line-args';
|
|
3
|
+
import { MessageStream, isCompilerArtifact } from '../cargo.js';
|
|
4
|
+
// FIXME: add options to infer crate name from manifests
|
|
5
|
+
// --package <path/to/package.json>
|
|
6
|
+
// --crate <path/to/Cargo.toml>
|
|
7
|
+
const OPTIONS = [
|
|
8
|
+
{ name: 'name', alias: 'n', type: String, defaultValue: null },
|
|
9
|
+
{ name: 'log', alias: 'l', type: String, defaultValue: null },
|
|
10
|
+
{ name: 'file', alias: 'f', type: String, defaultValue: null },
|
|
11
|
+
{ name: 'out', alias: 'o', type: String, defaultValue: 'index.node' }
|
|
12
|
+
];
|
|
13
|
+
async function findArtifact(log, crateName) {
|
|
14
|
+
const stream = new MessageStream(log);
|
|
15
|
+
return await stream.findPath((msg) => {
|
|
16
|
+
if (!isCompilerArtifact(msg) || (msg.target.name !== crateName)) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
const index = msg.target.crate_types.indexOf('cdylib');
|
|
20
|
+
return (index < 0) ? null : msg.filenames[index];
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
export default async function main(argv) {
|
|
24
|
+
const options = commandLineArgs(OPTIONS, { argv });
|
|
25
|
+
if (options.log && options.file) {
|
|
26
|
+
throw new Error("Options --log and --file cannot both be enabled.");
|
|
27
|
+
}
|
|
28
|
+
const crateName = options.name || process.env['npm_package_name'];
|
|
29
|
+
if (!crateName) {
|
|
30
|
+
throw new Error("No crate name provided.");
|
|
31
|
+
}
|
|
32
|
+
const file = options.file ?? await findArtifact(options.log, crateName);
|
|
33
|
+
if (!file) {
|
|
34
|
+
throw new Error(`No library found for crate ${crateName}`);
|
|
35
|
+
}
|
|
36
|
+
// FIXME: needs all the logic of cargo-cp-artifact (timestamp check, M1 workaround, async, errors)
|
|
37
|
+
await copyFile(file, options.out);
|
|
38
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import commandLineCommands from 'command-line-commands';
|
|
3
|
+
import { printUsage, die } from './usage.js';
|
|
4
|
+
import dist from './commands/dist.js';
|
|
5
|
+
import crossDist from './commands/cross-dist.js';
|
|
6
|
+
import crossPack from './commands/cross-pack.js';
|
|
7
|
+
import crossInstall from './commands/cross-install.js';
|
|
8
|
+
const VALID_COMMANDS = [null, 'help', 'dist', 'cross-dist', 'cross-pack', 'cross-install'];
|
|
9
|
+
export function expectCommandName(name) {
|
|
10
|
+
switch (name) {
|
|
11
|
+
case 'help':
|
|
12
|
+
case 'dist':
|
|
13
|
+
case 'cross-dist':
|
|
14
|
+
case 'cross-pack':
|
|
15
|
+
case 'cross-install':
|
|
16
|
+
return name;
|
|
17
|
+
default:
|
|
18
|
+
throw new RangeError(`Unrecognized command: ${name}`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
async function main() {
|
|
22
|
+
try {
|
|
23
|
+
const { command, argv } = commandLineCommands(VALID_COMMANDS);
|
|
24
|
+
switch (command) {
|
|
25
|
+
case 'dist':
|
|
26
|
+
await dist(argv);
|
|
27
|
+
break;
|
|
28
|
+
case 'cross-dist':
|
|
29
|
+
await crossDist(argv);
|
|
30
|
+
break;
|
|
31
|
+
case 'cross-pack':
|
|
32
|
+
await crossPack(argv);
|
|
33
|
+
break;
|
|
34
|
+
case 'cross-install':
|
|
35
|
+
await crossInstall(argv);
|
|
36
|
+
break;
|
|
37
|
+
case 'help':
|
|
38
|
+
if (argv.length > 0) {
|
|
39
|
+
printUsage(expectCommandName(argv[0]));
|
|
40
|
+
process.exit(0);
|
|
41
|
+
}
|
|
42
|
+
// FALL THROUGH
|
|
43
|
+
case null:
|
|
44
|
+
printUsage();
|
|
45
|
+
}
|
|
46
|
+
process.exit(0);
|
|
47
|
+
}
|
|
48
|
+
catch (e) {
|
|
49
|
+
die((e instanceof Error) ? e.message : null);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
main();
|
package/dist/usage.js
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
import commandLineUsage from 'command-line-usage';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
function pink(text) {
|
|
5
|
+
return chalk.bold.hex('#e75480')(text);
|
|
6
|
+
}
|
|
7
|
+
function blue(text) {
|
|
8
|
+
return chalk.bold.cyanBright(text);
|
|
9
|
+
}
|
|
10
|
+
function yellow(text) {
|
|
11
|
+
return chalk.bold.yellowBright(text);
|
|
12
|
+
}
|
|
13
|
+
function green(text) {
|
|
14
|
+
return chalk.bold.greenBright(text);
|
|
15
|
+
}
|
|
16
|
+
function commandUsage(name, command) {
|
|
17
|
+
const sections = [
|
|
18
|
+
{
|
|
19
|
+
content: `${pink('Neon:')} ${name} - ${COMMAND_SUMMARIES[name]}`,
|
|
20
|
+
raw: true
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
header: blue('Usage:'),
|
|
24
|
+
content: `${blue('$')} ${command.syntax}`
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
header: yellow('Options:'),
|
|
28
|
+
content: command.options
|
|
29
|
+
}
|
|
30
|
+
];
|
|
31
|
+
if (command.seeAlso) {
|
|
32
|
+
sections.push({
|
|
33
|
+
header: green('See Also:'),
|
|
34
|
+
content: command.seeAlso
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return commandLineUsage(sections);
|
|
38
|
+
}
|
|
39
|
+
function mainUsage() {
|
|
40
|
+
const require = createRequire(import.meta.url);
|
|
41
|
+
const version = require('../package.json').version;
|
|
42
|
+
const sections = [
|
|
43
|
+
{
|
|
44
|
+
content: `${pink('Neon:')} CLI v${version}`,
|
|
45
|
+
raw: true
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
header: blue('Usage:'),
|
|
49
|
+
content: `${blue('$')} neon <command> <options>`
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
header: yellow('Commands:'),
|
|
53
|
+
content: [
|
|
54
|
+
{ name: 'help', summary: COMMAND_SUMMARIES['help'] + '.' },
|
|
55
|
+
{ name: 'dist', summary: COMMAND_SUMMARIES['dist'] + '.' },
|
|
56
|
+
{ name: 'cross-dist', summary: COMMAND_SUMMARIES['cross-dist'] + '.' },
|
|
57
|
+
{ name: 'cross-pack', summary: COMMAND_SUMMARIES['cross-pack'] + '.' },
|
|
58
|
+
{ name: 'cross-install', summary: COMMAND_SUMMARIES['cross-install'] + '.' }
|
|
59
|
+
]
|
|
60
|
+
}
|
|
61
|
+
];
|
|
62
|
+
return commandLineUsage(sections);
|
|
63
|
+
}
|
|
64
|
+
const COMMAND_SUMMARIES = {
|
|
65
|
+
'help': 'Display help information about Neon',
|
|
66
|
+
'dist': 'Generate a .node file from a build',
|
|
67
|
+
'cross-dist': 'Generate a .node file from a cross-compiled prebuild',
|
|
68
|
+
'cross-pack': 'Create an npm tarball from a cross-compiled prebuild',
|
|
69
|
+
'cross-install': 'Install dependencies on cross-compiled prebuilds'
|
|
70
|
+
};
|
|
71
|
+
const COMMAND_USAGES = {
|
|
72
|
+
'help': {
|
|
73
|
+
syntax: 'neon help <command>',
|
|
74
|
+
options: [
|
|
75
|
+
{ name: '<command>', summary: 'Command to display help information about.' }
|
|
76
|
+
]
|
|
77
|
+
},
|
|
78
|
+
'dist': {
|
|
79
|
+
syntax: 'neon dist [-n <name>] [-l <log>|-f <dylib>] [-o <dist>]',
|
|
80
|
+
options: [
|
|
81
|
+
{ name: '-n, --name', summary: 'Crate name. (Default: $npm_package_name)' },
|
|
82
|
+
{ name: '-l, --log <log>', summary: 'Find dylib path from cargo messages <log>. (Default: stdin)' },
|
|
83
|
+
{ name: '-f, --file <dylib>', summary: 'Build .node from dylib file <dylib>.' },
|
|
84
|
+
{ name: '-o, --out <dist>', summary: 'Copy output to file <dist>. (Default: index.node)' }
|
|
85
|
+
],
|
|
86
|
+
seeAlso: [
|
|
87
|
+
{ name: 'cargo messages', summary: '<https://doc.rust-lang.org/cargo/reference/external-tools.html>' }
|
|
88
|
+
]
|
|
89
|
+
},
|
|
90
|
+
'cross-dist': {
|
|
91
|
+
syntax: 'neon cross-dist [-n <name>] [-l <log>|-f <dylib>] [-d <dir>] [-o <dist>]',
|
|
92
|
+
options: [
|
|
93
|
+
{ name: '-n, --name', summary: 'Crate name. (Default: $npm_package_name)' },
|
|
94
|
+
{ name: '-l, --log <log>', summary: 'Find dylib path from cargo messages <log>. (Default: stdin)' },
|
|
95
|
+
{ name: '-d, --dir <dir>', summary: 'Crate workspace root directory. (Default: .)' },
|
|
96
|
+
{
|
|
97
|
+
name: '',
|
|
98
|
+
summary: 'This is needed to normalize paths from the log data, which cross-rs provides from within the mounted Docker filesystem, back to the host filesystem.'
|
|
99
|
+
},
|
|
100
|
+
{ name: '-f, --file <dylib>', summary: 'Build .node from dylib file <dylib>.' },
|
|
101
|
+
{ name: '-o, --out <dist>', summary: 'Copy output to file <dist>. (Default: index.node)' }
|
|
102
|
+
],
|
|
103
|
+
seeAlso: [
|
|
104
|
+
{ name: 'cargo messages', summary: '<https://doc.rust-lang.org/cargo/reference/external-tools.html>' },
|
|
105
|
+
{ name: 'cross-rs', summary: '<https://github.com/cross-rs/cross>' }
|
|
106
|
+
]
|
|
107
|
+
},
|
|
108
|
+
'cross-pack': {
|
|
109
|
+
syntax: 'neon cross-pack [-f <addon>] <target>',
|
|
110
|
+
options: [
|
|
111
|
+
{ name: '-f, --file <addon>', summary: 'Prebuilt .node file to pack. (Default: index.node)' },
|
|
112
|
+
{ name: '<target>', summary: 'Rust target triple the addon was built for.' }
|
|
113
|
+
],
|
|
114
|
+
seeAlso: [
|
|
115
|
+
{ name: 'Rust platform support', summary: '<https://doc.rust-lang.org/rustc/platform-support.html>' },
|
|
116
|
+
{ name: 'npm pack', summary: '<https://docs.npmjs.com/cli/commands/npm-pack>' },
|
|
117
|
+
{ name: 'cross-rs', summary: '<https://github.com/cross-rs/cross>' }
|
|
118
|
+
]
|
|
119
|
+
},
|
|
120
|
+
'cross-install': {
|
|
121
|
+
syntax: 'neon cross-install [-b <file>|-B]',
|
|
122
|
+
options: [
|
|
123
|
+
{ name: '-b, --bundle <file>', summary: 'File to generate bundling metadata. (Default: .targets)' },
|
|
124
|
+
{
|
|
125
|
+
name: '',
|
|
126
|
+
summary: 'This generated file ensures support for bundlers (e.g. @vercel/ncc), which rely on static analysis to detect and enable any addons used by the library.'
|
|
127
|
+
},
|
|
128
|
+
{ name: '-B, --no-bundle', summary: 'Do not generate bundling metadata.' }
|
|
129
|
+
],
|
|
130
|
+
seeAlso: [
|
|
131
|
+
{ name: 'ncc', summary: '<https://github.com/vercel/ncc>' }
|
|
132
|
+
]
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
export function printUsage(command) {
|
|
136
|
+
if (command) {
|
|
137
|
+
console.error(commandUsage(command, COMMAND_USAGES[command]));
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
console.error(mainUsage());
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
export function die(msg) {
|
|
144
|
+
printUsage();
|
|
145
|
+
if (msg) {
|
|
146
|
+
console.error();
|
|
147
|
+
console.error(msg);
|
|
148
|
+
}
|
|
149
|
+
process.exit(1);
|
|
150
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@neon-rs/cli",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Command-line build tool for Neon modules.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": "./dist/index.js",
|
|
7
|
+
"types": "types/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"data/**/*",
|
|
10
|
+
"dist/**/*",
|
|
11
|
+
"types/**/*",
|
|
12
|
+
"LICENSE*"
|
|
13
|
+
],
|
|
14
|
+
"bin": {
|
|
15
|
+
"neon": "dist/index.js"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc",
|
|
19
|
+
"pretest": "npm run build",
|
|
20
|
+
"prepack": "npm run build",
|
|
21
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/dherman/neon-rs.git"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"Neon",
|
|
29
|
+
"Rust",
|
|
30
|
+
"Node"
|
|
31
|
+
],
|
|
32
|
+
"author": "Dave Herman <david.herman@gmail.com>",
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"bugs": {
|
|
35
|
+
"url": "https://github.com/dherman/neon-rs/issues"
|
|
36
|
+
},
|
|
37
|
+
"homepage": "https://github.com/dherman/neon-rs#readme",
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@tsconfig/node16": "^1.0.3",
|
|
40
|
+
"@types/command-line-args": "^5.2.0",
|
|
41
|
+
"@types/command-line-commands": "^2.0.1",
|
|
42
|
+
"@types/command-line-usage": "^5.0.2",
|
|
43
|
+
"@types/node": "^18.15.11",
|
|
44
|
+
"@types/temp": "^0.9.1",
|
|
45
|
+
"typescript": "^5.0.4"
|
|
46
|
+
},
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"chalk": "^5.2.0",
|
|
49
|
+
"command-line-args": "^5.2.1",
|
|
50
|
+
"command-line-commands": "^3.0.2",
|
|
51
|
+
"command-line-usage": "^7.0.1",
|
|
52
|
+
"execa": "^7.1.1",
|
|
53
|
+
"stream-to-string": "^1.2.1",
|
|
54
|
+
"temp": "^0.9.4"
|
|
55
|
+
}
|
|
56
|
+
}
|
package/types/cargo.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export type MessageReason = 'compiler-artifact' | 'compiler-message' | 'build-script-executed' | 'build-finished';
|
|
2
|
+
export type CompilerMessage = {
|
|
3
|
+
reason: 'compiler-message';
|
|
4
|
+
};
|
|
5
|
+
export type BuildScriptExecuted = {
|
|
6
|
+
reason: 'build-script-executed';
|
|
7
|
+
};
|
|
8
|
+
export type CompilerTarget = {
|
|
9
|
+
kind: string[];
|
|
10
|
+
crate_types: string[];
|
|
11
|
+
name: string;
|
|
12
|
+
};
|
|
13
|
+
export type CompilerArtifact = {
|
|
14
|
+
reason: 'compiler-artifact';
|
|
15
|
+
package_id: string;
|
|
16
|
+
manifest_path: string;
|
|
17
|
+
target: CompilerTarget;
|
|
18
|
+
filenames: string[];
|
|
19
|
+
};
|
|
20
|
+
export type BuildFinished = {
|
|
21
|
+
reason: 'build-finished';
|
|
22
|
+
success: boolean;
|
|
23
|
+
};
|
|
24
|
+
export type CargoMessage = CompilerMessage | BuildScriptExecuted | CompilerArtifact | BuildFinished;
|
|
25
|
+
export declare function messageReason(message: CargoMessage): MessageReason;
|
|
26
|
+
export declare function isCompilerMessage(json: unknown): json is CompilerMessage;
|
|
27
|
+
export declare function isBuildScriptExecuted(json: unknown): json is BuildScriptExecuted;
|
|
28
|
+
export declare function isCompilerTarget(json: unknown): json is CompilerTarget;
|
|
29
|
+
export declare function isCompilerArtifact(json: unknown): json is CompilerArtifact;
|
|
30
|
+
export declare function isBuildFinished(json: unknown): json is BuildFinished;
|
|
31
|
+
export declare function parseMessage(line: string): CargoMessage | null;
|
|
32
|
+
export type MessageFilter<T> = (msg: CargoMessage) => T | null;
|
|
33
|
+
export declare class MessageStream {
|
|
34
|
+
private _stream;
|
|
35
|
+
constructor(file?: string | null);
|
|
36
|
+
findPath(pred: MessageFilter<string>): Promise<string | null>;
|
|
37
|
+
}
|
|
38
|
+
export declare class CrossMessageStream extends MessageStream {
|
|
39
|
+
private _dir;
|
|
40
|
+
constructor(dir: string, file?: string | null);
|
|
41
|
+
findPath(pred: MessageFilter<string>): Promise<string | null>;
|
|
42
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function main(argv: string[]): Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function main(argv: string[]): Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function main(argv: string[]): Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function main(argv: string[]): Promise<void>;
|
package/types/index.d.ts
ADDED
package/types/usage.d.ts
ADDED