diff --git a/cli/src/api/build.ts b/cli/src/api/build.ts index f149cbbf..6fe7fbfd 100644 --- a/cli/src/api/build.ts +++ b/cli/src/api/build.ts @@ -297,6 +297,10 @@ class Builder { private setEnvs() { // type definition intermediate file this.envs.TYPE_DEF_TMP_PATH = this.getIntermediateTypeFile() + // WASI register intermediate file + this.envs.WASI_REGISTER_TMP_PATH = this.getIntermediateWasiRegisterFile() + // TODO: + // remove after napi-derive@v3 release this.envs.CARGO_CFG_NAPI_RS_CLI_VERSION = CLI_VERSION // RUSTFLAGS @@ -320,13 +324,18 @@ class Builder { // END RUSTFLAGS // LINKER - const linker = getTargetLinker(this.target.triple) - if ( - linker && - !process.env.RUSTC_LINKER && - !process.env[`CARGET_TARGET_${targetToEnvVar(this.target.triple)}_LINKER`] - ) { - this.envs.RUSTC_LINKER = linker + const linker = this.options.crossCompile + ? void 0 + : getTargetLinker(this.target.triple) + // TODO: + // directly set CARGO_TARGET__LINKER will cover .cargo/config.toml + // will detect by cargo config when it becomes stable + // see: https://github.com/rust-lang/cargo/issues/9301 + const linkerEnv = `CARGO_TARGET_${targetToEnvVar( + this.target.triple, + )}_LINKER` + if (linker && !process.env[linkerEnv]) { + this.envs[linkerEnv] = linker } if (this.target.platform === 'android') { @@ -410,6 +419,17 @@ class Builder { ) } + private getIntermediateWasiRegisterFile() { + return join( + tmpdir(), + `${this.crate.name}-${createHash('sha256') + .update(this.crate.manifest_path) + .update(CLI_VERSION) + .digest('hex') + .substring(0, 8)}.napi_wasi_register.tmp`, + ) + } + private async postBuild() { try { debug(`Try to create output directory:`) diff --git a/cli/src/api/templates/package.json.ts b/cli/src/api/templates/package.json.ts index 67e95709..0d46df4b 100644 --- a/cli/src/api/templates/package.json.ts +++ b/cli/src/api/templates/package.json.ts @@ -23,7 +23,7 @@ export const createPackageJson = ({ "node": "${engineRequirement}" }, "napi": { - "name": "${binaryName}", + "binaryName": "${binaryName}", "targets": [ ${targets.map((t) => `"${t}"`).join(',\n ')} ] diff --git a/cli/src/utils/misc.ts b/cli/src/utils/misc.ts index 885224e1..4a42dd91 100644 --- a/cli/src/utils/misc.ts +++ b/cli/src/utils/misc.ts @@ -5,7 +5,12 @@ import { promisify } from 'util' import { debug } from './log.js' const require = createRequire(import.meta.url) -const pkgJson = require('../../package.json') +// NOTE: +// import pkgJson from '@napi-rs/cli/package.json' assert { type: 'json' } +// is experimental feature now, avoid using it. +// see: https://nodejs.org/api/esm.html#import-assertions +// eslint-disable-next-line import/no-extraneous-dependencies +const pkgJson = require('@napi-rs/cli/package.json') export const readFileAsync = promisify(readFile) export const writeFileAsync = promisify(writeFile) diff --git a/cli/src/utils/target.ts b/cli/src/utils/target.ts index 16aa18e5..69c0f32e 100644 --- a/cli/src/utils/target.ts +++ b/cli/src/utils/target.ts @@ -26,8 +26,6 @@ export const DEFAULT_TARGETS = [ ] as const export const TARGET_LINKER: Record = { - 'aarch64-unknown-linux-gnu': 'aarch64-linux-gnu-gcc', - 'armv7-unknown-linux-gnueabihf': 'arm-linux-gnueabihf-gcc', 'aarch64-unknown-linux-musl': 'aarch64-linux-musl-gcc', }