-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Non-determinsitic output while targetting wasm32 on different OS #117597
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
Comments
Can you do |
I made those changes and got this. The only differences that I can see is that the MacOS one has this extra argument MacOS
Ubuntu
|
Different |
After much investigation I can't seem to figure out how to manipulate the Was Doing
Now Doing
|
The reason that If you're shooting for deterministic builds across platforms it's probably best to strip the |
|
Ah excellent point, in that case yeah I think it might be reasonable to strip that out of Cargo's hashing of the rustc version. |
This commit updates how `-Cmetadata` is calculated for each unit to optionally exclude the `host: ...` line that rustc prints for cross-compiled builds. Previously the full `verbose_version` was hashed for stable builds and the `host` was explicitly hashed for non-stable builds. For a build using `--target`, however, that means that the `-Cmetadata` will be different when producing the same target on different hosts (e.g. producing the binary once on Linux and once on macOS). This can hinder reproduction of a binary across different platforms even when the `--target` flag is used. For example in rust-lang/rust#117597 it was seen that a WebAssembly binary produced on different platforms was slightly different and this appears due to the differing `-Cmetadata` flags. After this commit the `-Cmetadata` flag is the same for two different platforms meaning that different platforms produce the same binary. I've tested locally and a simple project produces a different binary before this change but produces the same binary on two platforms after this change. Unfortunately automated testing of this change will be difficult since it requires two different host compilers, though.
I've opened rust-lang/cargo#14107 for this in Cargo |
Make `-Cmetadata` consistent across platforms This commit updates how `-Cmetadata` is calculated for each unit to optionally exclude the `host: ...` line that rustc prints for cross-compiled builds. Previously the full `verbose_version` was hashed for stable builds and the `host` was explicitly hashed for non-stable builds. For a build using `--target`, however, that means that the `-Cmetadata` will be different when producing the same target on different hosts (e.g. producing the binary once on Linux and once on macOS). This can hinder reproduction of a binary across different platforms even when the `--target` flag is used. For example in rust-lang/rust#117597 it was seen that a WebAssembly binary produced on different platforms was slightly different and this appears due to the differing `-Cmetadata` flags. After this commit the `-Cmetadata` flag is the same for two different platforms meaning that different platforms produce the same binary. I've tested locally and a simple project produces a different binary before this change but produces the same binary on two platforms after this change. Unfortunately automated testing of this change will be difficult since it requires two different host compilers, though.
So with that merge, rust-lang/cargo#14107, it now seems to produce consistent output. repo testing deterministic output |
So I create some UserScripts as a hobby for a game and have been looking to write some of them in Rust and compile them down to wasm, but I have noticed that what outputted
.wasm
binary file is different based off the OS that is building it.I created a little repo to try and test exactly where it is, using my MacOS builds and GitHub actions for a Ubuntu build. Both running the same version of
rustc
.The program I am testing with is a simple app that prints 'Hello, world!'.
The first test I did was using
rustc
itself to build the.wasm
binaries and did manage to get identical outputs across MacOS and UbuntuThe second test I did was switching to using Cargo instead and found that it was now producing different outputs across MacOS and Ubuntu for the same code.
I don't know why its not being deterministic when I used
cargo
overrustc
as the flags I passed to either on both OS' are identical with the same versions ofrustc
. You can see the entire repo here. Any help would be appreciated.The text was updated successfully, but these errors were encountered: