@neon-rs/cli 0.0.2 → 0.0.3
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.
|
@@ -22,11 +22,11 @@ function lookup(target) {
|
|
|
22
22
|
}
|
|
23
23
|
export default class PackBuild {
|
|
24
24
|
static summary() { return 'Create an npm tarball from a prebuild.'; }
|
|
25
|
-
static syntax() { return 'neon pack-build [-f <addon>] <target>'; }
|
|
25
|
+
static syntax() { return 'neon pack-build [-f <addon>] [-t <target>]'; }
|
|
26
26
|
static options() {
|
|
27
27
|
return [
|
|
28
28
|
{ name: '-f, --file <addon>', summary: 'Prebuilt .node file to pack. (Default: index.node)' },
|
|
29
|
-
{ name: '<target>', summary: 'Rust target triple the addon was built for.' }
|
|
29
|
+
{ name: '-t, --target <target>', summary: 'Rust target triple the addon was built for. (Default: rustc default host)' }
|
|
30
30
|
];
|
|
31
31
|
}
|
|
32
32
|
static seeAlso() {
|
|
@@ -37,28 +37,33 @@ export default class PackBuild {
|
|
|
37
37
|
];
|
|
38
38
|
}
|
|
39
39
|
constructor(argv) {
|
|
40
|
-
const options = commandLineArgs(OPTIONS, { argv
|
|
41
|
-
|
|
42
|
-
if (argv.length === 0) {
|
|
43
|
-
throw new Error("Expected <target>.");
|
|
44
|
-
}
|
|
45
|
-
if (argv.length > 1) {
|
|
46
|
-
throw new Error(`Unexpected argument \`${argv[1]}\`.`);
|
|
47
|
-
}
|
|
48
|
-
this._target = argv[0];
|
|
40
|
+
const options = commandLineArgs(OPTIONS, { argv });
|
|
41
|
+
this._target = options.target || null;
|
|
49
42
|
this._addon = options.file;
|
|
50
43
|
this._outDir = options['out-dir'] || path.join(process.cwd(), 'dist');
|
|
51
44
|
}
|
|
45
|
+
async currentTarget() {
|
|
46
|
+
const result = await execa("rustc", ["-vV"], { shell: true });
|
|
47
|
+
if (result.exitCode !== 0) {
|
|
48
|
+
throw new Error(`Could not determine current Rust target: ${result.stderr}`);
|
|
49
|
+
}
|
|
50
|
+
const hostLine = result.stdout.split(/\n/).find(line => line.startsWith('host:'));
|
|
51
|
+
if (!hostLine) {
|
|
52
|
+
throw new Error("Could not determine current Rust target (unexpected rustc output)");
|
|
53
|
+
}
|
|
54
|
+
return hostLine.replace(/^host:\s+/, '');
|
|
55
|
+
}
|
|
52
56
|
async run() {
|
|
53
57
|
await fs.mkdir(this._outDir, { recursive: true });
|
|
54
58
|
const manifest = JSON.parse(await fs.readFile('package.json', { encoding: 'utf8' }));
|
|
55
59
|
const version = manifest.version;
|
|
56
60
|
const targets = manifest.neon.targets;
|
|
57
|
-
const
|
|
61
|
+
const target = this._target || await this.currentTarget();
|
|
62
|
+
const name = targets[target];
|
|
58
63
|
if (!name) {
|
|
59
|
-
throw new Error(`Rust target ${
|
|
64
|
+
throw new Error(`Rust target ${target} not found in package.json.`);
|
|
60
65
|
}
|
|
61
|
-
const targetInfo = lookup(
|
|
66
|
+
const targetInfo = lookup(target);
|
|
62
67
|
const description = `Prebuilt binary package for \`${manifest.name}\` on \`${targetInfo.node}\`.`;
|
|
63
68
|
let prebuildManifest = {
|
|
64
69
|
name,
|
package/package.json
CHANGED