Skip to content

Commit 09dc8b8

Browse files
committed
allow '.threads.wasm' binary by default
1 parent e3ea1c8 commit 09dc8b8

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

godot-macros/src/gdextension.rs

+20-7
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub fn attribute_gdextension(item: venial::Item) -> ParseResult<TokenStream> {
5959
}
6060
}
6161
}
62-
None => quote! { "snakePkgName + '.wasm'" },
62+
None => quote! { "null" },
6363
};
6464

6565
let impl_ty = &impl_decl.self_ty;
@@ -88,12 +88,25 @@ pub fn attribute_gdextension(item: venial::Item) -> ParseResult<TokenStream> {
8888
// We should keep an eye out for these sorts of failures!
8989
let script = format!(
9090
r#"var pkgName = '{pkg_name}';
91-
var snakePkgName = pkgName.replaceAll('-', '_');
92-
var libName = {wasm_binary};
93-
if (!(libName in LDSO.loadedLibsByName)) {{
94-
// Always print to console, even if the error is suppressed.
95-
console.error(`godot-rust could not find the Wasm module '${{libName}}', needed to load the '${{pkgName}}' crate. Please ensure a file named '${{libName}}' exists in the game's web export files. This may require updating Wasm paths in the crate's corresponding '.gdextension' file, or just renaming the Wasm file to the correct name otherwise.`);
96-
throw new Error(`Wasm module '${{libName}}' not found. Check the console for more information.`);
91+
var wasmBinary = {wasm_binary};
92+
if (wasmBinary === null) {{
93+
var snakePkgName = pkgName.replaceAll('-', '_');
94+
var normalLibName = snakePkgName + '.wasm';
95+
var threadedLibName = snakePkgName + '.threads.wasm';
96+
if (normalLibName in LDSO.loadedLibsByName) {{
97+
var libName = normalLibName;
98+
}} else if (threadedLibName in LDSO.loadedLibsByName) {{
99+
var libName = threadedLibName;
100+
}} else {{
101+
// Always print to console, even if the error is suppressed.
102+
console.error(`godot-rust could not find the Wasm module '${{normalLibName}}' nor '${{threadedLibName}}', one of which is needed by default to load the '${{pkgName}}' crate. This indicates its '.wasm' binary file was renamed to an unexpected name.\n\nPlease ensure its Wasm binary file has one of those names in the game's web export files. This may require updating Wasm paths in the crate's corresponding '.gdextension' file, or just renaming the Wasm file to one of the expected names otherwise.\n\nIf that GDExtension uses a different Wasm filename, please ensure it informs this new name to godot-rust with the following option: '#[gdextension(wasm_binary = "newname.wasm")]'`);
103+
throw new Error(`Wasm module '${{normalLibName}}' not found. Check the console for more information.`);
104+
}}
105+
}} else if (wasmBinary in LDSO.loadedLibsByName) {{
106+
var libName = wasmBinary;
107+
}} else {{
108+
console.error(`godot-rust could not find the Wasm module '${{wasmBinary}}', needed to load the '${{pkgName}}' crate. This indicates its '.wasm' binary file was renamed to an unexpected name.\n\nPlease ensure its Wasm binary file is named '${{wasmBinary}}' in the game's web export files. This may require updating Wasm paths in the crate's corresponding '.gdextension' file, or just renaming the Wasm file to the expected name otherwise.`);
109+
throw new Error(`Wasm module '${{wasmBinary}}' not found. Check the console for more information.`);
97110
}}
98111
var dso = LDSO.loadedLibsByName[libName];
99112
// This property was renamed as of emscripten 3.1.34

0 commit comments

Comments
 (0)