Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Make a deterministic build system #136

Open
ethanfrey opened this issue Sep 8, 2020 · 11 comments
Open

Make a deterministic build system #136

ethanfrey opened this issue Sep 8, 2020 · 11 comments

Comments

@ethanfrey
Copy link
Member

See CosmWasm/wasmd#268

Multiple compiles of the same code should give us the same dlls.

I think this requires removing all concurrency from compilation and a few other tricks... definitely increasing build times a lot, so it should be an option, not default. But we should do this for tagged releases, so we can get deterministic (and signable) go binaries

@webmaster128
Copy link
Member

We have build containers now for the .dylib, .so and .a builds. Rust strives towards reproducible builds in general and is doing pretty good. I think the only thing that is really missing here is that we should not mount the host's target folder into the guest, which happens as part of -v $(shell pwd):/code. Instead we should have a guest-only target folder, as in

docker run --rm -v "$(pwd)":/code \
  --mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \
  --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
  cosmwasm/rust-optimizer:0.10.5

@yihuang
Copy link
Contributor

yihuang commented Apr 30, 2021

https://github.com/yihuang/cosmwasm-plus-plus/blob/integration-tests/nix/default.nix
How about nix? I managed to build wasmd and wasmvm together with nix.

@ethanfrey
Copy link
Member Author

I think the main issue is the compilation step of wasmvm returns a different dll each time. Maybe if we limit it to one compiler thread (and 4-8x slower), it will produce deterministic output, as with the smart contracts.

Nix is a good idea if we have dependency issues (like linking native C libs causing issues). It may also be a more efficient solution to the Docker files we use now.

@maurolacy
Copy link
Contributor

maurolacy commented Apr 30, 2021

I think the main issue is the compilation step of wasmvm returns a different dll each time.

Interesting. My take is that it should be possible to instruct the compiler / linker to produce deterministic output. Maybe with some compiler flags, disabling some optimizations, or something like that.

I can take a look at this at some point if you want.

@yihuang
Copy link
Contributor

yihuang commented Apr 30, 2021

Is there an issue in the rust side? I was only aware of un-deterministic caused by working path, which should be fixed with option --remap-path-prefix.

@webmaster128
Copy link
Member

My take is that it should be possible to instruct the compiler / linker to produce deterministic output.

I second that. For Rust, deterministic builds are considered standard and when builds are not deterministic, we can file this as a bug. It is well possible that this does not work here for the shared libs that are a bit exotic for Rust, but we should have all the community support to get this fixed.

@ethanfrey
Copy link
Member Author

I believe it is due to multiple compiler threads and varying linking order.

I know I set codegen-units = 1 to get deterministic builds for the CosmWasm contracts (over a year ago)
https://github.com/CosmWasm/cosmwasm/blob/main/contracts/hackatom/Cargo.toml#L19

I have not tried building the wasmvm with that option and checking the sha256sum of the resultant DLLs. I would be interested in the results if anyone wants to try.

@maurolacy
Copy link
Contributor

maurolacy commented Apr 30, 2021

Some relevant links, after a quick search for "rustc deterministic":

Some info may be outdated. According to the last link, and particularly if we keep the same build system, deterministic builds are very likely.

faddat pushed a commit to faddat/go-cosmwasm that referenced this issue Dec 10, 2021
faddat pushed a commit to faddat/go-cosmwasm that referenced this issue Dec 10, 2021
@beatriz-web3

This comment was marked as off-topic.

@webmaster128

This comment was marked as off-topic.

@webmaster128
Copy link
Member

This seems to work well for the .so and .dylib builds. But the .dll on Windows changes even without changes to the libwasmvm source code (ba3ecc0).

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants