fast patches for napi/cli 3.0-alpha (#1553)
* fix(cli): use new napi config field * fix(cli): avoid using node experimental feature to read self version * fix(cli): correct linker environment * fix(cli): missing wasi register env * fix(cli): remove useless linker preset
This commit is contained in:
parent
5daf558ead
commit
c9f5ee14b7
4 changed files with 34 additions and 11 deletions
|
@ -297,6 +297,10 @@ class Builder {
|
||||||
private setEnvs() {
|
private setEnvs() {
|
||||||
// type definition intermediate file
|
// type definition intermediate file
|
||||||
this.envs.TYPE_DEF_TMP_PATH = this.getIntermediateTypeFile()
|
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
|
this.envs.CARGO_CFG_NAPI_RS_CLI_VERSION = CLI_VERSION
|
||||||
|
|
||||||
// RUSTFLAGS
|
// RUSTFLAGS
|
||||||
|
@ -320,13 +324,18 @@ class Builder {
|
||||||
// END RUSTFLAGS
|
// END RUSTFLAGS
|
||||||
|
|
||||||
// LINKER
|
// LINKER
|
||||||
const linker = getTargetLinker(this.target.triple)
|
const linker = this.options.crossCompile
|
||||||
if (
|
? void 0
|
||||||
linker &&
|
: getTargetLinker(this.target.triple)
|
||||||
!process.env.RUSTC_LINKER &&
|
// TODO:
|
||||||
!process.env[`CARGET_TARGET_${targetToEnvVar(this.target.triple)}_LINKER`]
|
// directly set CARGO_TARGET_<target>_LINKER will cover .cargo/config.toml
|
||||||
) {
|
// will detect by cargo config when it becomes stable
|
||||||
this.envs.RUSTC_LINKER = linker
|
// 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') {
|
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() {
|
private async postBuild() {
|
||||||
try {
|
try {
|
||||||
debug(`Try to create output directory:`)
|
debug(`Try to create output directory:`)
|
||||||
|
|
|
@ -23,7 +23,7 @@ export const createPackageJson = ({
|
||||||
"node": "${engineRequirement}"
|
"node": "${engineRequirement}"
|
||||||
},
|
},
|
||||||
"napi": {
|
"napi": {
|
||||||
"name": "${binaryName}",
|
"binaryName": "${binaryName}",
|
||||||
"targets": [
|
"targets": [
|
||||||
${targets.map((t) => `"${t}"`).join(',\n ')}
|
${targets.map((t) => `"${t}"`).join(',\n ')}
|
||||||
]
|
]
|
||||||
|
|
|
@ -5,7 +5,12 @@ import { promisify } from 'util'
|
||||||
import { debug } from './log.js'
|
import { debug } from './log.js'
|
||||||
|
|
||||||
const require = createRequire(import.meta.url)
|
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 readFileAsync = promisify(readFile)
|
||||||
export const writeFileAsync = promisify(writeFile)
|
export const writeFileAsync = promisify(writeFile)
|
||||||
|
|
|
@ -26,8 +26,6 @@ export const DEFAULT_TARGETS = [
|
||||||
] as const
|
] as const
|
||||||
|
|
||||||
export const TARGET_LINKER: Record<string, string> = {
|
export const TARGET_LINKER: Record<string, string> = {
|
||||||
'aarch64-unknown-linux-gnu': 'aarch64-linux-gnu-gcc',
|
|
||||||
'armv7-unknown-linux-gnueabihf': 'arm-linux-gnueabihf-gcc',
|
|
||||||
'aarch64-unknown-linux-musl': 'aarch64-linux-musl-gcc',
|
'aarch64-unknown-linux-musl': 'aarch64-linux-musl-gcc',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue