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

Switching between WASM and host target forces rebuild #8662

Closed
kaimast opened this issue Aug 29, 2020 · 9 comments
Closed

Switching between WASM and host target forces rebuild #8662

kaimast opened this issue Aug 29, 2020 · 9 comments
Labels
C-bug Category: bug

Comments

@kaimast
Copy link

kaimast commented Aug 29, 2020

Problem
I have a workspace that contains both a wasm crate and a "regular" crate. The latter includes and runs the wasm binary.

Steps

  1. I have two crates in workspace; let's say wasm-bin and wasm-runner
  2. There's a Makefile at the root of the workspace that looks something like this. (I use a Makefile because of Per crate build target in workspace #7004)
wasm-bin:
   cd wasm-bin && cargo build

wasm-runner: wasm-bin
   cd wasm-runner && cargo build

Additionally there's a .cargo/config file in the wasm-bin folder with

[build]
target = "wasm32-unknown-unknown"
  1. I run make wasm-runner the first time. Both crates build.

  2. I run make wasm-runner a second time. Both crates rebuild even though no code has changed.

Notes

  • Output of cargo version: cargo 1.47.0-beta (51b66125b 2020-08-19)
  • OS is Ubuntu 20.04 on x86_64.
@kaimast kaimast added the C-bug Category: bug label Aug 29, 2020
@d-e-s-o
Copy link
Contributor

d-e-s-o commented Aug 29, 2020

I was just about to file an issue for the same problem :-) It seems that we share the same "target" directory or something like that. I build with WASM and then without and compared the contents and there is a host of differences. I suppose in the past the assumption was that switching compilations targets is a rare thing (I can mostly think of cross compilation), but with WASM that changes, I'd say.

Also, this is REALLY annoying if you have rust-analyzer running on your project. From what it looks like it will build whatever is "the default" (invalidating the other in the process) and if that is the non-wasm build (i.e., if you don't have the target line in .cargo/config) then you'll run into rebuilds literally every time you build for WASM.

@alexcrichton
Copy link
Member

Can you set RUST_LOG=cargo::core::compiler::fingerprint and gist the output? That should help explain what's being rebuilt and why.

@d-e-s-o
Copy link
Contributor

d-e-s-o commented Aug 29, 2020

I think CARGO_LOG is the way to go now. Anyway, here is the gist: https://gist.github.com/d-e-s-o/1a143ff40e48f68ba5482ad9f770192a

(created on not exactly the smallest crate, let me know if you need a more isolated trace on a minimal example)

@d-e-s-o
Copy link
Contributor

d-e-s-o commented Aug 29, 2020

I think CARGO_LOG is the way to go now. Anyway, here is the gist: https://gist.github.com/d-e-s-o/1a143ff40e48f68ba5482ad9f770192a

So I looked at this output and it seems as if the change in Rust flags is the issue (at least for me). I removed rustflags = ["-C", "target-cpu=native"] from my ~/.cargo/config and now it's just fine. I guess I could just make it go into effect for release builds and that would be sufficient. Thanks for the tip on how to investigate!

@kaimast
Copy link
Author

kaimast commented Aug 29, 2020

Seems to be a similar issue for me. I compile with -Ctarget-feature=+aes,+ssse3.

Guess there's no easy way to fix this except for removing the flag?

@d-e-s-o
Copy link
Contributor

d-e-s-o commented Aug 30, 2020

Seems to be a similar issue for me. I compile with -Ctarget-feature=+aes,+ssse3.

Guess there's no easy way to fix this except for removing the flag?

Mine now looks like:

[target.'cfg(all(not(target_arch = "wasm32")), not(debug_assertions))']
rustflags = ["-C", "target-cpu=native"]

For me it's sufficient because 1) so far debug build performance has been sufficient and 2) all my release builds have

incremental = false

anyway, so they rebuild fully regardless. But yeah, ideally having such a setting wouldn't have such a unintended consequences :-|

@kaimast
Copy link
Author

kaimast commented Aug 30, 2020

Maybe Cargo could at least emit a message if such a rebuild occurs?

@alexcrichton
Copy link
Member

Diagnosing rebuilds is the subject of #2904

@ehuss
Copy link
Contributor

ehuss commented Sep 19, 2020

I'm going to close this in favor of #8716, where I've summarized the state of rebuild handling of rustflags.

@ehuss ehuss closed this as completed Sep 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

4 participants