Skip to content
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

Configure build to not include local paths into wasm #455

Open
ilblackdragon opened this issue Jun 30, 2021 · 6 comments
Open

Configure build to not include local paths into wasm #455

ilblackdragon opened this issue Jun 30, 2021 · 6 comments

Comments

@ilblackdragon
Copy link
Member

ilblackdragon commented Jun 30, 2021

Currently when developers compile wasm file, the local paths are included into the wasm file in the asserts and other errors.

This is very suboptimal for reproducibility and also leaks private information about developer, which they are not always aware.

There should be a way to remove these absolute paths from the resulting file. If not, we need a tool that will clean this up after compilation and as default part of SDK.

@matklad
Copy link
Contributor

matklad commented Jul 6, 2021

There should be a way to remove these absolute paths from the resulting file.

See rust-lang/cargo#9506 (comment). There's --remap-path-prefix rustc option, which I think can only be set via env var at the moment.

@mikedotexe
Copy link
Contributor

mikedotexe commented Jul 16, 2021

I'm a fan of the .cargo/config file to keep the build command less scary and cross-platform. Just saw we can't do it for this.

thus it can't be done with a fixed .cargo/config.

Darn, so it does have to be an env var for now.
rust-lang/rust#64839

@ilblackdragon
Copy link
Member Author

ilblackdragon commented Jul 16, 2021 via email

@matklad
Copy link
Contributor

matklad commented Jul 16, 2021

I don't see a super-nice way to make this "just work" with cargo build. Short-term, I suggest including some kind of ./build-contract script to orchestrate cargo build (and document the pitfalls). I see the following ways to deliver the script

  1. custom cargo near build subcommand. This requires the user to run cargo install cargo-near, which itself breaks isolation. It gives a nice opaque mental model. It makes it hard to understand what's going on.
  2. a ./build-contract.sh script in the exapmle repo, which the user should copy-paste locally. This is simple to understand and transparent. It gives a duct tape and bubble gum vibe though, and .sh scripts are a maintainability hazard for larger projects
  3. an example xtask. This has complimentary properties to .sh -- good long-term maintenance, harder to understand initially.

I would suggest going for option 2 for the sdk itself, as it has the lowest entry barrier. I personally think we should nudge serious users towards 3 though (but might be biased on this one).

Note that any solution allows us to nicely centralize all the oddness about building contracts:

  • selection of wasm target
  • -ling-arg S
  • special profiling settings (opt-level, lto, strip)
  • remap-prefix

Long term, I'd guess we should work on design and implementation of hypothetical --hermetic flag for Cargo, but, realistically, that'll take at least a year to ship even if we start the work right now.

@mikedotexe
Copy link
Contributor

The problem with anything local to your machine - is that everyone else doesn't have that. Which means they will get different results. The build scripts should be hermetic IMO: you should be able to unpack a new computer, git clone and build and get exactly the same result.

Definitely agree with this. For our Rust examples, we're keeping (some) Windows compatible by having the .cargo/config file there in the project. This doesn't live in the home directory or something. For instance, the Rust counter example looks like this:

├── .cargo
│  └── config      ⟵ right here
├── build.sh
├── Cargo.lock
├── Cargo.toml
├── src
│  └── lib.rs
└── tests
   └── sim
      └── main.rs

@matklad
Copy link
Contributor

matklad commented Jan 5, 2022

Rust 1.59.0 should allow us to avoid -ling-arg S in RUSTFLAGS: rust-lang/rust#90058

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants