Skip to content

Non-determinsitic output while targetting wasm32 on different OS #117597

@BlackAsLight

Description

@BlackAsLight

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.

> rustc --version
rustc 1.75.0-nightly (4b85902b4 2023-11-04)
info: syncing channel updates for 'nightly-x86_64-unknown-linux-gnu'
info: latest update on 2023-11-05, rust version 1.75.0-nightly (4b85902b4 2023-11-04)

The program I am testing with is a simple app that prints 'Hello, world!'.

fn main() {
    println!("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 Ubuntu

rustc --target=wasm32-unknown-unknown main.rs

The 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.

cargo build --release --target=wasm32-unknown-unknown

I don't know why its not being deterministic when I used cargo over rustc as the flags I passed to either on both OS' are identical with the same versions of rustc. You can see the entire repo here. Any help would be appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-reproducibilityArea: Reproducible / deterministic buildsO-wasmTarget: WASM (WebAssembly), http://webassembly.org/

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions