-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wasm-pack
's browser
and nodejs
targets generate different .wasm
files (in my project)
#1627
Comments
Thanks for the report! This is actually currently intentional behavior in that the target generation can tweak the intrinsics used in the wasm and such, causing different wasms to get produced. For example this is because Could you expand on why this is a bug for you? It's not currently been intended that we always produce the exact same wasm file, but rather the targets have always been able to tweak the wasm file here and there as necessary for each target. |
From my understanding, a key goal of WebAssembly is portability - a single bytecode format for execution on arbitrary platforms. While the spec does explicitly state that "WebAssembly does not specify any APIs or syscalls, only an import mechanism where the set of available imports is defined by the host environment," I expected Node & Browser Wasm targets to be similar enough that any differences were in the generated JS bindings. |
@arilotter Our plan is to add a new wasm-pack Then all you have to do is specify This is a common practice even when writing pure JavaScript packages: developers will often create two versions, one for Node and one for the browser. For example, see canvg. It's also very common for npm packages to ship both an ES6 module version and a CommonJS module version. This is essentially the npm equivalent of a fat binary. So since that's the way the npm ecosystem has evolved (multiple versions contained in the same package), that's what we're focusing on. It also gives us a lot more flexibility, since it's possible to tailor the
Although Node is based on V8, it often lags far behind the browsers. For example, ES6 modules are already supported by all major browsers, but not in Node. And I would bet a lot of money that
WebAssembly's goal of portability only applies to WebAssembly itself, it does not apply to WebAssembly programs (which must import functions from the host, so if the host doesn't have that function then you're out of luck). Of course having WebAssembly programs which are portable is certainly good, but it's a very difficult goal.
That's a lot harder than it sounds at first, since it isn't as simple as just creating some bindings and calling it a day: there are a lot of quirks with how JS works, so any runtime would have to emulate those quirks as well. For example, the way the event loop works. It's doable, but definitely not easy. You're almost certainly better off creating separate Multiple compilation isn't unusual at all: binaries are often compiled only for 64-bit Windows, or only for a specific Linux distro, or only for a specific version of Mac OS, etc. Even though all those platforms use the x86-64 instruction set, they still need separate versions because of the host APIs and OS quirks. WebAssembly is the equivalent of a CPU instruction set (like x86-64). It doesn't try to smooth over APIs. Perhaps one day we'll have a truly portable programming API which can be used across all platforms and systems (maybe WASI will be that API), but for now multiple compilation will still be necessary. |
@Pauan Thanks for your detailed comments! I'm doing the "fat binary" equivalent in my code. |
Describe the Bug
wasm-pack
'sbrowser
andnodejs
targets generate different.wasm
files in my project (but not in a minimal wasm-pack project)Steps to Reproduce
cd
to my repositoryExpected Behavior
I expect the generated
.wasm
files (and wat files) to be bit-for-bit identical, and the output ofwasm-pack
to only differ in Javascript bindings.Actual Behavior
It appears the browser
.wasm
includes$__wbindgen_realloc
and(export "__wbindgen_realloc" (func $__wbindgen_realloc))
, while the nodejs.wasm
doesn't include either of those.The
diff
command outputsThe text was updated successfully, but these errors were encountered: