mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-16 14:31:22 +00:00
Add an example of wasm2asm
and wasm-bindgen
This commit adds an example of executing the `wasm2asm` tool to generate asm.js output instead of WebAssembly. This is often useful when supporting older browsers, such as IE 11, that doesn't have native support for WebAssembly.
This commit is contained in:
@ -27,6 +27,7 @@ Options:
|
||||
--typescript Output a `*.d.ts` file next to the JS output
|
||||
--base64 Inline the wasm module using base64 encoding
|
||||
--fetch PATH Load module by passing the PATH argument to `fetch()`
|
||||
--wasm2asm Convert wasm to asm.js and don't use `WebAssembly`
|
||||
|
||||
Note that this is not intended to produce a production-ready output module
|
||||
but rather is intended purely as a temporary \"hack\" until it's standard in
|
||||
@ -38,6 +39,7 @@ struct Args {
|
||||
flag_output: Option<PathBuf>,
|
||||
flag_typescript: bool,
|
||||
flag_base64: bool,
|
||||
flag_wasm2asm: bool,
|
||||
flag_fetch: Option<String>,
|
||||
arg_input: PathBuf,
|
||||
}
|
||||
@ -58,10 +60,6 @@ fn main() {
|
||||
}
|
||||
|
||||
fn rmain(args: &Args) -> Result<(), Error> {
|
||||
if !args.flag_base64 && !args.flag_fetch.is_some() {
|
||||
bail!("unfortunately only works right now with base64 or fetch");
|
||||
}
|
||||
|
||||
let mut wasm = Vec::new();
|
||||
File::open(&args.arg_input)
|
||||
.and_then(|mut f| f.read_to_end(&mut wasm))
|
||||
@ -69,6 +67,7 @@ fn rmain(args: &Args) -> Result<(), Error> {
|
||||
|
||||
let object = wasm_bindgen_cli_support::wasm2es6js::Config::new()
|
||||
.base64(args.flag_base64)
|
||||
.wasm2asm(args.flag_wasm2asm)
|
||||
.fetch(args.flag_fetch.clone())
|
||||
.generate(&wasm)?;
|
||||
|
||||
|
Reference in New Issue
Block a user