Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5d360e8

Browse filesBrowse files
authored
chore(cli): remove outdated WASI_REGISTER_TMP_PATH (#2633)
1 parent ce99054 commit 5d360e8
Copy full SHA for 5d360e8

File tree

Expand file treeCollapse file tree

3 files changed

+4
-82
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+4
-82
lines changed

‎cli/src/api/build.ts

Copy file name to clipboardExpand all lines: cli/src/api/build.ts
+1-43Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,6 @@ class Builder {
463463
private setEnvs() {
464464
// type definition intermediate file
465465
this.envs.TYPE_DEF_TMP_PATH = this.getIntermediateTypeFile()
466-
// WASI register intermediate file
467-
this.envs.WASI_REGISTER_TMP_PATH = this.getIntermediateWasiRegisterFile()
468466
// TODO:
469467
// remove after napi-derive@v3 release
470468
this.envs.CARGO_CFG_NAPI_RS_CLI_VERSION = CLI_VERSION
@@ -664,17 +662,6 @@ class Builder {
664662
return `${dtsPath}.tmp`
665663
}
666664

667-
private getIntermediateWasiRegisterFile() {
668-
return join(
669-
tmpdir(),
670-
`${this.crate.name}-${createHash('sha256')
671-
.update(this.crate.manifest_path)
672-
.update(CLI_VERSION)
673-
.digest('hex')
674-
.substring(0, 8)}.napi_wasi_register.tmp`,
675-
)
676-
}
677-
678665
private async postBuild() {
679666
try {
680667
debug(`Try to create output directory:`)
@@ -692,36 +679,8 @@ class Builder {
692679
// only for cdylib
693680
if (this.cdyLibName) {
694681
const idents = await this.generateTypeDef()
695-
const intermediateWasiRegisterFile = this.envs.WASI_REGISTER_TMP_PATH
696-
const wasiRegisterFunctions = this.config.targets.some(
697-
(t) => t.platform === 'wasi',
698-
)
699-
? await (async function readIntermediateWasiRegisterFile() {
700-
const fileContent = await readFileAsync(
701-
intermediateWasiRegisterFile,
702-
'utf8',
703-
).catch((err) => {
704-
console.warn(
705-
`Read ${colors.yellowBright(
706-
intermediateWasiRegisterFile,
707-
)} failed, reason: ${err.message}`,
708-
)
709-
return ``
710-
})
711-
return fileContent
712-
.split('\n')
713-
.map((l) => l.trim())
714-
.filter((l) => l.length)
715-
.map((line) => {
716-
const [_, fn] = line.split(':')
717-
return fn?.trim()
718-
})
719-
.filter((fn) => !!fn)
720-
})()
721-
: []
722682
const jsOutput = await this.writeJsBinding(idents)
723683
const wasmBindingsOutput = await this.writeWasiBinding(
724-
wasiRegisterFunctions,
725684
wasmBinaryName ?? 'index.wasm',
726685
idents,
727686
)
@@ -926,11 +885,10 @@ class Builder {
926885
}
927886

928887
private async writeWasiBinding(
929-
wasiRegisterFunctions: string[],
930888
distFileName: string | undefined,
931889
idents: string[],
932890
) {
933-
if (distFileName && wasiRegisterFunctions.length) {
891+
if (distFileName) {
934892
const { name, dir } = parse(distFileName)
935893
const bindingPath = join(dir, `${this.config.binaryName}.wasi.cjs`)
936894
const browserBindingPath = join(

‎crates/backend/src/typegen.rs

Copy file name to clipboardExpand all lines: crates/backend/src/typegen.rs
+2-11Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ pub static NAPI_RS_CLI_VERSION: LazyLock<semver::Version> = LazyLock::new(|| {
1919
semver::Version::parse(&version).unwrap_or_else(|_| semver::Version::new(0, 0, 0))
2020
});
2121

22-
pub static NAPI_RS_CLI_VERSION_WITH_SHARED_CRATES_FIX: LazyLock<semver::Version> =
23-
LazyLock::new(|| semver::Version::new(2, 15, 1));
24-
2522
#[derive(Default, Debug)]
2623
pub struct TypeDef {
2724
pub kind: String,
@@ -117,14 +114,8 @@ impl Display for TypeDef {
117114
} else {
118115
"".to_string()
119116
};
120-
// TODO: remove this in v3
121-
// This is a workaround for lower version of @napi-rs/cli
122-
// See https://github.com/napi-rs/napi-rs/pull/1531
123-
let prefix = if *NAPI_RS_CLI_VERSION >= *NAPI_RS_CLI_VERSION_WITH_SHARED_CRATES_FIX {
124-
format!("{}:", pkg_name)
125-
} else {
126-
"".to_string()
127-
};
117+
118+
let prefix = format!("{}:", pkg_name);
128119
write!(
129120
f,
130121
r#"{}{{"kind": "{}", "name": "{}", "js_doc": "{}", "def": "{}"{}{}}}"#,

‎crates/macro/src/expand/napi.rs

Copy file name to clipboardExpand all lines: crates/macro/src/expand/napi.rs
+1-28Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ pub fn expand(attr: TokenStream, input: TokenStream) -> BindgenResult<TokenStrea
8989
#[cfg(feature = "type-def")]
9090
{
9191
output_type_def(&napi);
92-
output_wasi_register_def(&napi);
9392
}
9493
} else {
9594
item.to_tokens(&mut tokens);
@@ -116,32 +115,11 @@ pub fn expand(attr: TokenStream, input: TokenStream) -> BindgenResult<TokenStrea
116115
#[cfg(feature = "type-def")]
117116
{
118117
output_type_def(&napi);
119-
output_wasi_register_def(&napi);
120118
}
121119
Ok(tokens)
122120
}
123121
}
124122

125-
#[cfg(feature = "type-def")]
126-
fn output_wasi_register_def(napi: &Napi) {
127-
if let Ok(wasi_register_file) = env::var("WASI_REGISTER_TMP_PATH") {
128-
fs::OpenOptions::new()
129-
.append(true)
130-
.create(true)
131-
.open(wasi_register_file)
132-
.and_then(|file| {
133-
let mut writer = BufWriter::<fs::File>::new(file);
134-
let pkg_name: String = std::env::var("CARGO_PKG_NAME").expect("CARGO_PKG_NAME is not set");
135-
writer.write_all(format!("{pkg_name}: {}", napi.register_name()).as_bytes())?;
136-
writer.write_all("\n".as_bytes())?;
137-
writer.flush()
138-
})
139-
.unwrap_or_else(|e| {
140-
println!("Failed to write wasi register file: {:?}", e);
141-
});
142-
}
143-
}
144-
145123
#[cfg(feature = "type-def")]
146124
fn output_type_def(napi: &Napi) {
147125
if let Ok(type_def_file) = env::var("TYPE_DEF_TMP_PATH") {
@@ -199,12 +177,7 @@ fn replace_napi_attr_in_mod(
199177
#[cfg(feature = "type-def")]
200178
fn prepare_type_def_file() {
201179
if let Ok(ref type_def_file) = env::var("TYPE_DEF_TMP_PATH") {
202-
use napi_derive_backend::{NAPI_RS_CLI_VERSION, NAPI_RS_CLI_VERSION_WITH_SHARED_CRATES_FIX};
203-
if let Err(_e) = if *NAPI_RS_CLI_VERSION >= *NAPI_RS_CLI_VERSION_WITH_SHARED_CRATES_FIX {
204-
remove_existed_def_file(type_def_file)
205-
} else {
206-
fs::remove_file(type_def_file)
207-
} {
180+
if let Err(_e) = remove_existed_def_file(type_def_file) {
208181
#[cfg(debug_assertions)]
209182
{
210183
println!("Failed to manipulate type def file: {:?}", _e);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.