disable shorthash function name #3738
-
I want use wasm3 runtime to load wasm binary file which is generated by wasm-bindgen and wasm-pack. But I found that wasm-bindgen regenerate function for export, when I load wasm binary file, I must link a export function, but it was rename with shorthash.
wasm binary file name is: Can you provide a configuration to turn this shorthash off and keep the original name? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I'm not entirely sure what the problem here is, but maybe the guide can help you: https://rustwasm.github.io/docs/wasm-bindgen/examples/import-js.html. |
Beta Was this translation helpful? Give feedback.
-
I don't think This is how you can write Wasm imports/exports directly without #[link(wasm_import_module = "foo")]
extern "C" {
// These will compile down to `(import "foo" "alert" ...)` and
// `(import "foo" "printf" ...)`.
// The "foo" comes from `#[link(wasm_import_module)]`; if you don't specify
// that, it defaults to "env".
fn alert();
fn printf();
}
// Unlike with `alert` and `printf`, the `extern "C"` isn't the bit of this
// which causes the function to be exported: it's `#[no_mangle]` that's doing
// it. The `pub` does nothing.
//
// `extern "C"`, on the other hand, tells the compiler to use C's rules for
// picking Wasm parameters/return types, instead of Rust's default rules. This
// is because Rust's rules for this aren't stable, so you shouldn't rely on them
// (even though in this case they'll probably generate the same thing).
#[no_mangle]
pub extern "C" fn greet() -> u32 {
// This is normal FFI now, which is unsafe.
unsafe { alert() }
unsafe { printf() }
// This won't actually do anything unless you use WASI (it wouldn't have done
// anything with wasm-bindgen either).
println!("wasm exec for greet");
return 9527;
} Note though that the only argument/return types you can use like this are numbers ( |
Beta Was this translation helpful? Give feedback.
I don't think
wasm-bindgen
is really the tool for the job here: it's specifically for interoperating with JavaScript, not standalone Wasm runtimes like wasm3.This is how you can write Wasm imports/exports directly without
wasm-bindgen
: