diff --git a/DESIGN.md b/DESIGN.md index 87d43c86e..2f687c7a6 100644 --- a/DESIGN.md +++ b/DESIGN.md @@ -23,9 +23,9 @@ strings, etc. Keep in mind, though, that everything is based on ES Modules! This means that the compiler is actually producing a "broken" wasm file of sorts. The wasm file emitted by rustc, for example, does not have the interface we would like to have. Instead it requires the `wasm-bindgen` tool to postprocess the -file, generating a `foo.js` and `foo_wasm.wasm` file. The `foo.js` file is the +file, generating a `foo.js` and `foo_bg.wasm` file. The `foo.js` file is the desired interface expressed in JS (classes, types, strings, etc) and the -`foo_wasm.wasm` module is simply used as an implementation detail (it was +`foo_bg.wasm` module is simply used as an implementation detail (it was lightly modified from the original `foo.wasm` file). ## Foundation #2: Unintrusive in Rust @@ -111,7 +111,7 @@ and what we actually generate looks something like: ```js // foo.js -import * as wasm from './foo_wasm'; +import * as wasm from './foo_bg'; let stack = []; @@ -132,7 +132,7 @@ export function foo(arg0) { Here we can see a few notable points of action: -* The wasm file was renamed to `foo_wasm.wasm`, and we can see how the JS module +* The wasm file was renamed to `foo_bg.wasm`, and we can see how the JS module generated here is importing from the wasm file. * Next we can see our `stack` module variable which is used to push/pop items from the stack. @@ -199,7 +199,7 @@ module interface is the same as before, but the ownership mechanics are slightly different. Let's see the generated JS's slab in action: ```js -import * as wasm from './foo_wasm'; // imports from wasm file +import * as wasm from './foo_bg'; // imports from wasm file let slab = []; let slab_next = 0; @@ -334,7 +334,7 @@ export function greet(a: string): string; To see what's going on, let's take a look at the generated shim ```js -import * as wasm from './foo_wasm'; +import * as wasm from './foo_bg'; function passStringToWasm(arg) { const buf = new TextEncoder('utf-8').encode(arg); @@ -449,7 +449,7 @@ both JS and Rust doing the necessary translation. Let's first see the JS shim in action: ```js -import * as wasm from './foo_wasm'; +import * as wasm from './foo_bg'; import { greet } from './greet'; @@ -539,7 +539,7 @@ available to JS through generated shims. If we take a look at the generated JS code for this we'll see: ```js -import * as wasm from './foo_wasm'; +import * as wasm from './foo_bg'; export class Foo { constructor(ptr) { @@ -710,7 +710,7 @@ let's go through one-by-one: With all that in mind, let's take a look at the JS generated. ```js -import * as wasm from './foo_wasm'; +import * as wasm from './foo_bg'; import { Bar } from './bar'; diff --git a/README.md b/README.md index 4466bfab0..71e01f25c 100644 --- a/README.md +++ b/README.md @@ -138,8 +138,8 @@ intended interface of the wasm file, notably with rich types like strings, classes, etc. The `wasm-bindgen` tool also emits a few other files needed to implement this -module. For example `js_hello_world_wasm.wasm` is the original wasm file but -postprocessed a bit. It's intended that the `js_hello_world_wasm.wasm` file, +module. For example `js_hello_world_bg.wasm` is the original wasm file but +postprocessed a bit. It's intended that the `js_hello_world_bg.wasm` file, like before, acts like an ES6 module. The `js_hello_world.wasm` file, for example, uses `import` to import functionality from the other `*_shims` file generated (an internal implementation detail here). diff --git a/crates/test-support/src/lib.rs b/crates/test-support/src/lib.rs index a93b59504..ef0cab0e7 100644 --- a/crates/test-support/src/lib.rs +++ b/crates/test-support/src/lib.rs @@ -177,13 +177,13 @@ impl Project { .expect("failed to run bindgen"); let mut wasm = Vec::new(); - File::open(root.join("out_wasm.wasm")).unwrap() + File::open(root.join("out_bg.wasm")).unwrap() .read_to_end(&mut wasm).unwrap(); let obj = cli::wasm2es6js::Config::new() .base64(true) .generate(&wasm) .expect("failed to convert wasm to js"); - File::create(root.join("out_wasm.d.ts")).unwrap() + File::create(root.join("out_bg.d.ts")).unwrap() .write_all(obj.typescript().as_bytes()).unwrap(); diff --git a/crates/wasm-bindgen-cli-support/src/js.rs b/crates/wasm-bindgen-cli-support/src/js.rs index db0e3f8db..0ddf19142 100644 --- a/crates/wasm-bindgen-cli-support/src/js.rs +++ b/crates/wasm-bindgen-cli-support/src/js.rs @@ -214,7 +214,7 @@ impl<'a> Context<'a> { let js = format!(" /* tslint:disable */ - import * as wasm from './{module_name}_wasm'; // imports from wasm file + import * as wasm from './{module_name}_bg'; // imports from wasm file {imports} {globals} diff --git a/crates/wasm-bindgen-cli-support/src/lib.rs b/crates/wasm-bindgen-cli-support/src/lib.rs index 11dcf604d..24a4f0855 100644 --- a/crates/wasm-bindgen-cli-support/src/lib.rs +++ b/crates/wasm-bindgen-cli-support/src/lib.rs @@ -105,7 +105,7 @@ impl Bindgen { .write_all(ts.as_bytes()).unwrap(); } - let wasm_path = out_dir.join(format!("{}_wasm", stem)).with_extension("wasm"); + let wasm_path = out_dir.join(format!("{}_bg", stem)).with_extension("wasm"); let wasm_bytes = parity_wasm::serialize(module).map_err(|e| { format_err!("{:?}", e) })?; diff --git a/examples/hello_world/.gitignore b/examples/hello_world/.gitignore index f786218f5..f5974ab0b 100644 --- a/examples/hello_world/.gitignore +++ b/examples/hello_world/.gitignore @@ -1,4 +1,4 @@ package-lock.json hello_world.js -hello_world_wasm.js -hello_world_wasm.wasm +hello_world_bg.js +hello_world_bg.wasm diff --git a/examples/hello_world/chrome/build.sh b/examples/hello_world/chrome/build.sh index 1190f9739..116250857 100755 --- a/examples/hello_world/chrome/build.sh +++ b/examples/hello_world/chrome/build.sh @@ -9,13 +9,13 @@ cargo +nightly run -p wasm-bindgen-cli --bin wasm-bindgen -- \ # To avoid a bug occurring when webpack, wasm, and Chrome are used together, we # convert the .wasm module to a .js module that embeds the wasm bytecode. To -# enable this, delete hello_world_wasm.wasm after building or change -# hello_world.js to import from hello_world_wasm.js explicitly and uncomment +# enable this, delete hello_world_bg.wasm after building or change +# hello_world.js to import from hello_world_bg.js explicitly and uncomment # the relevant line in index.js. cargo +nightly run -p wasm-bindgen-cli --bin wasm2es6js -- \ - --base64 -o hello_world_wasm.js hello_world_wasm.wasm -# wasm2es6js --base64 -o hello_world_wasm.js hello_world_wasm.wasm -rm hello_world_wasm.wasm + --base64 -o hello_world_bg.js hello_world_bg.wasm +# wasm2es6js --base64 -o hello_world_bg.js hello_world_bg.wasm +rm hello_world_bg.wasm # And like the directory above this, from here it's the same. npm install diff --git a/examples/hello_world/chrome/index.js b/examples/hello_world/chrome/index.js index a5291a920..65549d15e 100644 --- a/examples/hello_world/chrome/index.js +++ b/examples/hello_world/chrome/index.js @@ -6,6 +6,6 @@ // wasm (generated by wasm2es6js) which has a `booted` promise to let us know // when it's ready to go. import { greet } from './hello_world'; -import { booted } from './hello_world_wasm'; +import { booted } from './hello_world_bg'; booted.then(() => greet("World!")); diff --git a/examples/hello_world/index.js b/examples/hello_world/index.js index 7f0e3e972..c83e118e0 100644 --- a/examples/hello_world/index.js +++ b/examples/hello_world/index.js @@ -11,7 +11,7 @@ Promise.all([ // hack around this and need to defer our call until the converted wasm // module is asynchronously loaded. Uncomment this line to enable. // This hack is not necessary in Firefox. - // import("./hello_world_wasm.js").then(wasm => wasm.booted), + // import("./hello_world_bg.js").then(wasm => wasm.booted), ]).then(([js]) => { js.greet("World!"); }); diff --git a/examples/smorgasboard/.gitignore b/examples/smorgasboard/.gitignore index 8ac1e8487..1716d5f04 100644 --- a/examples/smorgasboard/.gitignore +++ b/examples/smorgasboard/.gitignore @@ -1,3 +1,3 @@ package-lock.json smorgasboard.js -smorgasboard_wasm.wasm +smorgasboard_bg.wasm diff --git a/tests/simple.rs b/tests/simple.rs index e603b7f38..2b99fbd86 100644 --- a/tests/simple.rs +++ b/tests/simple.rs @@ -204,7 +204,7 @@ fn other_exports() { } "#) .file("test.ts", r#" - import * as wasm from "./out_wasm"; + import * as wasm from "./out_bg"; export function test() { wasm.foo(2);