@napi-rs/cli 3.0.0-alpha.1 → 3.0.0-alpha.2

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 CHANGED
@@ -207,6 +207,10 @@ class Builder {
207
207
  setEnvs() {
208
208
  // type definition intermediate file
209
209
  this.envs.TYPE_DEF_TMP_PATH = this.getIntermediateTypeFile();
210
+ // WASI register intermediate file
211
+ this.envs.WASI_REGISTER_TMP_PATH = this.getIntermediateWasiRegisterFile();
212
+ // TODO:
213
+ // remove after napi-derive@v3 release
210
214
  this.envs.CARGO_CFG_NAPI_RS_CLI_VERSION = CLI_VERSION;
211
215
  // RUSTFLAGS
212
216
  let rustflags = process.env.RUSTFLAGS ?? process.env.CARGO_BUILD_RUSTFLAGS ?? '';
@@ -222,11 +226,16 @@ class Builder {
222
226
  }
223
227
  // END RUSTFLAGS
224
228
  // LINKER
225
- const linker = getTargetLinker(this.target.triple);
226
- if (linker &&
227
- !process.env.RUSTC_LINKER &&
228
- !process.env[`CARGET_TARGET_${targetToEnvVar(this.target.triple)}_LINKER`]) {
229
- this.envs.RUSTC_LINKER = linker;
229
+ const linker = this.options.crossCompile
230
+ ? void 0
231
+ : getTargetLinker(this.target.triple);
232
+ // TODO:
233
+ // directly set CARGO_TARGET_<target>_LINKER will cover .cargo/config.toml
234
+ // will detect by cargo config when it becomes stable
235
+ // see: https://github.com/rust-lang/cargo/issues/9301
236
+ const linkerEnv = `CARGO_TARGET_${targetToEnvVar(this.target.triple)}_LINKER`;
237
+ if (linker && !process.env[linkerEnv]) {
238
+ this.envs[linkerEnv] = linker;
230
239
  }
231
240
  if (this.target.platform === 'android') {
232
241
  const { ANDROID_NDK_LATEST_HOME } = process.env;
@@ -290,6 +299,13 @@ class Builder {
290
299
  .digest('hex')
291
300
  .substring(0, 8)}.napi_type_def.tmp`);
292
301
  }
302
+ getIntermediateWasiRegisterFile() {
303
+ return join(tmpdir(), `${this.crate.name}-${createHash('sha256')
304
+ .update(this.crate.manifest_path)
305
+ .update(CLI_VERSION)
306
+ .digest('hex')
307
+ .substring(0, 8)}.napi_wasi_register.tmp`);
308
+ }
293
309
  async postBuild() {
294
310
  try {
295
311
  debug(`Try to create output directory:`);
@@ -9,7 +9,7 @@ export const createPackageJson = ({ name, binaryName, targets, license, engineRe
9
9
  "node": "${engineRequirement}"
10
10
  },
11
11
  "napi": {
12
- "name": "${binaryName}",
12
+ "binaryName": "${binaryName}",
13
13
  "targets": [
14
14
  ${targets.map((t) => `"${t}"`).join(',\n ')}
15
15
  ]
package/dist/index.cjs CHANGED
@@ -12997,7 +12997,7 @@ var import_fs = require("fs");
12997
12997
  var import_module = require("module");
12998
12998
  var import_util = require("util");
12999
12999
  var require2 = (0, import_module.createRequire)(__filename);
13000
- var pkgJson = require2("../../package.json");
13000
+ var pkgJson = require2("@napi-rs/cli/package.json");
13001
13001
  var readFileAsync = (0, import_util.promisify)(import_fs.readFile);
13002
13002
  var writeFileAsync = (0, import_util.promisify)(import_fs.writeFile);
13003
13003
  var unlinkAsync = (0, import_util.promisify)(import_fs.unlink);
@@ -13050,8 +13050,6 @@ var DEFAULT_TARGETS = [
13050
13050
  "x86_64-unknown-linux-gnu"
13051
13051
  ];
13052
13052
  var TARGET_LINKER = {
13053
- "aarch64-unknown-linux-gnu": "aarch64-linux-gnu-gcc",
13054
- "armv7-unknown-linux-gnueabihf": "arm-linux-gnueabihf-gcc",
13055
13053
  "aarch64-unknown-linux-musl": "aarch64-linux-musl-gcc"
13056
13054
  };
13057
13055
  var CpuToNodeArch = {
@@ -19411,7 +19409,7 @@ var createPackageJson = ({ name, binaryName, targets, license, engineRequirement
19411
19409
  "node": "${engineRequirement}"
19412
19410
  },
19413
19411
  "napi": {
19414
- "name": "${binaryName}",
19412
+ "binaryName": "${binaryName}",
19415
19413
  "targets": [
19416
19414
  ${targets.map((t) => `"${t}"`).join(",\n ")}
19417
19415
  ]
@@ -19713,6 +19711,7 @@ var Builder = class {
19713
19711
  }
19714
19712
  setEnvs() {
19715
19713
  this.envs.TYPE_DEF_TMP_PATH = this.getIntermediateTypeFile();
19714
+ this.envs.WASI_REGISTER_TMP_PATH = this.getIntermediateWasiRegisterFile();
19716
19715
  this.envs.CARGO_CFG_NAPI_RS_CLI_VERSION = CLI_VERSION;
19717
19716
  let rustflags = process.env.RUSTFLAGS ?? process.env.CARGO_BUILD_RUSTFLAGS ?? "";
19718
19717
  if (this.target.abi?.includes("musl") && !rustflags.includes("target-feature=-crt-static")) {
@@ -19724,9 +19723,10 @@ var Builder = class {
19724
19723
  if (rustflags.length) {
19725
19724
  this.envs.RUSTFLAGS = rustflags;
19726
19725
  }
19727
- const linker = getTargetLinker(this.target.triple);
19728
- if (linker && !process.env.RUSTC_LINKER && !process.env[`CARGET_TARGET_${targetToEnvVar(this.target.triple)}_LINKER`]) {
19729
- this.envs.RUSTC_LINKER = linker;
19726
+ const linker = this.options.crossCompile ? void 0 : getTargetLinker(this.target.triple);
19727
+ const linkerEnv = `CARGO_TARGET_${targetToEnvVar(this.target.triple)}_LINKER`;
19728
+ if (linker && !process.env[linkerEnv]) {
19729
+ this.envs[linkerEnv] = linker;
19730
19730
  }
19731
19731
  if (this.target.platform === "android") {
19732
19732
  const { ANDROID_NDK_LATEST_HOME } = process.env;
@@ -19783,6 +19783,9 @@ var Builder = class {
19783
19783
  getIntermediateTypeFile() {
19784
19784
  return (0, import_path2.join)((0, import_os.tmpdir)(), `${this.crate.name}-${(0, import_crypto.createHash)("sha256").update(this.crate.manifest_path).update(CLI_VERSION).digest("hex").substring(0, 8)}.napi_type_def.tmp`);
19785
19785
  }
19786
+ getIntermediateWasiRegisterFile() {
19787
+ return (0, import_path2.join)((0, import_os.tmpdir)(), `${this.crate.name}-${(0, import_crypto.createHash)("sha256").update(this.crate.manifest_path).update(CLI_VERSION).digest("hex").substring(0, 8)}.napi_wasi_register.tmp`);
19788
+ }
19786
19789
  async postBuild() {
19787
19790
  try {
19788
19791
  debug3(`Try to create output directory:`);
@@ -3,7 +3,12 @@ import { createRequire } from 'module';
3
3
  import { promisify } from 'util';
4
4
  import { debug } from './log.js';
5
5
  const require = createRequire(import.meta.url);
6
- const pkgJson = require('../../package.json');
6
+ // NOTE:
7
+ // import pkgJson from '@napi-rs/cli/package.json' assert { type: 'json' }
8
+ // is experimental feature now, avoid using it.
9
+ // see: https://nodejs.org/api/esm.html#import-assertions
10
+ // eslint-disable-next-line import/no-extraneous-dependencies
11
+ const pkgJson = require('@napi-rs/cli/package.json');
7
12
  export const readFileAsync = promisify(readFile);
8
13
  export const writeFileAsync = promisify(writeFile);
9
14
  export const unlinkAsync = promisify(unlink);
@@ -21,8 +21,6 @@ export const DEFAULT_TARGETS = [
21
21
  'x86_64-unknown-linux-gnu',
22
22
  ];
23
23
  export const TARGET_LINKER = {
24
- 'aarch64-unknown-linux-gnu': 'aarch64-linux-gnu-gcc',
25
- 'armv7-unknown-linux-gnueabihf': 'arm-linux-gnueabihf-gcc',
26
24
  'aarch64-unknown-linux-musl': 'aarch64-linux-musl-gcc',
27
25
  };
28
26
  const CpuToNodeArch = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@napi-rs/cli",
3
- "version": "3.0.0-alpha.1",
3
+ "version": "3.0.0-alpha.2",
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",
@@ -96,5 +96,5 @@
96
96
  "build:cjs": "node ./esbuild.mjs",
97
97
  "test": "ava"
98
98
  },
99
- "gitHead": "5daf558ead65b27ffd6b1da318ba91467d7445c3"
99
+ "gitHead": "c3b49f0ca6a199029c4a8a893594d0b76c2a6d01"
100
100
  }
package/src/api/build.ts CHANGED
@@ -297,6 +297,10 @@ class Builder {
297
297
  private setEnvs() {
298
298
  // type definition intermediate file
299
299
  this.envs.TYPE_DEF_TMP_PATH = this.getIntermediateTypeFile()
300
+ // WASI register intermediate file
301
+ this.envs.WASI_REGISTER_TMP_PATH = this.getIntermediateWasiRegisterFile()
302
+ // TODO:
303
+ // remove after napi-derive@v3 release
300
304
  this.envs.CARGO_CFG_NAPI_RS_CLI_VERSION = CLI_VERSION
301
305
 
302
306
  // RUSTFLAGS
@@ -320,13 +324,18 @@ class Builder {
320
324
  // END RUSTFLAGS
321
325
 
322
326
  // LINKER
323
- const linker = getTargetLinker(this.target.triple)
324
- if (
325
- linker &&
326
- !process.env.RUSTC_LINKER &&
327
- !process.env[`CARGET_TARGET_${targetToEnvVar(this.target.triple)}_LINKER`]
328
- ) {
329
- this.envs.RUSTC_LINKER = linker
327
+ const linker = this.options.crossCompile
328
+ ? void 0
329
+ : getTargetLinker(this.target.triple)
330
+ // TODO:
331
+ // directly set CARGO_TARGET_<target>_LINKER will cover .cargo/config.toml
332
+ // will detect by cargo config when it becomes stable
333
+ // see: https://github.com/rust-lang/cargo/issues/9301
334
+ const linkerEnv = `CARGO_TARGET_${targetToEnvVar(
335
+ this.target.triple,
336
+ )}_LINKER`
337
+ if (linker && !process.env[linkerEnv]) {
338
+ this.envs[linkerEnv] = linker
330
339
  }
331
340
 
332
341
  if (this.target.platform === 'android') {
@@ -410,6 +419,17 @@ class Builder {
410
419
  )
411
420
  }
412
421
 
422
+ private getIntermediateWasiRegisterFile() {
423
+ return join(
424
+ tmpdir(),
425
+ `${this.crate.name}-${createHash('sha256')
426
+ .update(this.crate.manifest_path)
427
+ .update(CLI_VERSION)
428
+ .digest('hex')
429
+ .substring(0, 8)}.napi_wasi_register.tmp`,
430
+ )
431
+ }
432
+
413
433
  private async postBuild() {
414
434
  try {
415
435
  debug(`Try to create output directory:`)
@@ -23,7 +23,7 @@ export const createPackageJson = ({
23
23
  "node": "${engineRequirement}"
24
24
  },
25
25
  "napi": {
26
- "name": "${binaryName}",
26
+ "binaryName": "${binaryName}",
27
27
  "targets": [
28
28
  ${targets.map((t) => `"${t}"`).join(',\n ')}
29
29
  ]
package/src/utils/misc.ts CHANGED
@@ -5,7 +5,12 @@ import { promisify } from 'util'
5
5
  import { debug } from './log.js'
6
6
 
7
7
  const require = createRequire(import.meta.url)
8
- const pkgJson = require('../../package.json')
8
+ // NOTE:
9
+ // import pkgJson from '@napi-rs/cli/package.json' assert { type: 'json' }
10
+ // is experimental feature now, avoid using it.
11
+ // see: https://nodejs.org/api/esm.html#import-assertions
12
+ // eslint-disable-next-line import/no-extraneous-dependencies
13
+ const pkgJson = require('@napi-rs/cli/package.json')
9
14
 
10
15
  export const readFileAsync = promisify(readFile)
11
16
  export const writeFileAsync = promisify(writeFile)
@@ -26,8 +26,6 @@ export const DEFAULT_TARGETS = [
26
26
  ] as const
27
27
 
28
28
  export const TARGET_LINKER: Record<string, string> = {
29
- 'aarch64-unknown-linux-gnu': 'aarch64-linux-gnu-gcc',
30
- 'armv7-unknown-linux-gnueabihf': 'arm-linux-gnueabihf-gcc',
31
29
  'aarch64-unknown-linux-musl': 'aarch64-linux-musl-gcc',
32
30
  }
33
31