You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
var libName = pkgName.replaceAll('-', '_') + '.wasm';
75
-
if (!(libName in LDSO.loadedLibsByName)) {
76
-
// Always print to console, even if the error is suppressed.
77
-
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.`);
78
-
throw new Error(`Wasm module '${libName}' not found. Check the console for more information.`);
79
-
}
79
+
let script = format!(
80
+
r#"var pkgName = '{pkg_name}';
81
+
var wasmBinary = {wasm_binary};
82
+
if (wasmBinary === null) {{
83
+
var snakePkgName = pkgName.replaceAll('-', '_');
84
+
var normalLibName = snakePkgName + '.wasm';
85
+
var threadedLibName = snakePkgName + '.threads.wasm';
86
+
if (normalLibName in LDSO.loadedLibsByName) {{
87
+
var libName = normalLibName;
88
+
}} else if (threadedLibName in LDSO.loadedLibsByName) {{
89
+
var libName = threadedLibName;
90
+
}} else {{
91
+
// Always print to console, even if the error is suppressed.
92
+
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 by returning 'Some("newname.wasm")' from 'ExtensionLibrary::override_wasm_binary'.`);
93
+
throw new Error(`Wasm module '${{normalLibName}}' not found. Check the console for more information.`);
94
+
}}
95
+
}} else if (!wasmBinary.endsWith(".wasm")) {{
96
+
console.error(`godot-rust received an invalid Wasm binary name ('${{wasmBinary}}') from crate '${{pkgName}}', as the '.wasm' extension was missing.\n\nPlease ensure the 'ExtensionLibrary::override_wasm_binary' function for that GDExtension always returns a filename with the '.wasm' extension and try again.`);
97
+
throw new Error(`Invalid Wasm module '${{wasmBinary}}' (missing '.wasm' extension). Check the console for more information.`);
98
+
}} else if (wasmBinary in LDSO.loadedLibsByName) {{
99
+
var libName = wasmBinary;
100
+
}} else {{
101
+
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.`);
102
+
throw new Error(`Wasm module '${{wasmBinary}}' not found. Check the console for more information.`);
103
+
}}
80
104
var dso = LDSO.loadedLibsByName[libName];
81
105
// This property was renamed as of emscripten 3.1.34
82
106
var dso_exports = "module" in dso ? dso["module"] : dso["exports"];
83
107
var registrants = [];
84
-
for (sym in dso_exports) {
85
-
if (sym.startsWith("dynCall_")) {
86
-
if (!(sym in Module)) {
87
-
console.log(`Patching Module with ${sym}`);
108
+
for (sym in dso_exports) {{
109
+
if (sym.startsWith("dynCall_")) {{
110
+
if (!(sym in Module)) {{
111
+
console.log(`Patching Module with ${{sym}}`);
88
112
Module[sym] = dso_exports[sym];
89
-
}
90
-
} else if (sym.startsWith("__godot_rust_registrant_")) {
113
+
}}
114
+
}} else if (sym.startsWith("__godot_rust_registrant_")) {{
91
115
registrants.push(sym);
92
-
}
93
-
}
94
-
for (sym of registrants) {
95
-
console.log(`Running registrant ${sym}`);
116
+
}}
117
+
}}
118
+
for (sym of registrants) {{
119
+
console.log(`Running registrant ${{sym}}`);
96
120
dso_exports[sym]();
97
-
}
121
+
}}
98
122
console.log("Added", registrants.length, "plugins to registry!");
99
-
"#)).expect("Unable to create CString from script");
123
+
"#);
124
+
125
+
let script = std::ffi::CString::new(script).expect("Unable to create CString from script");
0 commit comments