When I compile the same code (Cargo.lock which guarantee the same dependencies) targeting
wasm32-unknown-unknown on different host OS (linux v.s. macOS), the output Wasm modules are different.
Is it possible to output the same Wasm?
Or this has never been a goal of rust compiler when compile to wasm?
You can use
--remap-path-prefix to prevent embedding the full source file paths in the compiled artifacts. (one for ~/.cargo/registry` and one of the project dir) Other than that builds should in principle be reproducible across OSes I think.
I've already been using
--remap-path-prefix. But the Wasm modules still differ.
FYI, the script I'm using is here.
I checked the text format of the two Wasm modules (via
wasm2wat). The diff showed that the function names were mangled differently.
Could you come up with any other factors that may influence the name mangling?
One thing I could think of is that the -Cmetadata hash for the wasm artifact contains those of proc macros and build script fron dependencies, which have a different metadata hash as the host target is hashed into it.
In the rustc book, I read:
This takes a space-separated list of strings.
Could you shine some light on what are the possible arguments here? Or where can I find some document?
Any string is valid. Rustc simply hashes all
-Cmetadata arguments together with the crate name to form a "stable crate id" which is used to disambiguate between different crates even if they have the same name. One of the way it does this is by being hashed into the symbol names to ensure there are no conflicts. Cargo uses a hash of several different things as