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

Failure on subsequent builds when --emit asm used without -C save-temps. #89149

Closed
hydra opened this issue Sep 21, 2021 · 6 comments · Fixed by #123221
Closed

Failure on subsequent builds when --emit asm used without -C save-temps. #89149

hydra opened this issue Sep 21, 2021 · 6 comments · Fixed by #123221
Labels
C-bug Category: This is a bug.

Comments

@hydra
Copy link

hydra commented Sep 21, 2021

I tried this code:

(see attached project)
buildfailure-1.zip

cargo build --bin=nucleof446re --target=thumbv7m-none-eabi --features="dep-stm32f446" -vv
...
cargo build --bin=nucleof446re --target=thumbv7m-none-eabi --features="dep-stm32f446" -vv

I expected to see this happen:

build the first time, build the second time.

Instead, this happened: explanation

On the first build, success.
On the second build

error: could not copy "D:\\Users\\Hydra\\Documents\\dev\\playground\\rust\\buildfailure-1\\crates\\boards\\target\\thumbv7m-none-eabi\\debug\\deps\\boards-381a71c28462db46.19nwjvde6m7mbrbk.rcgu.s" to "D:\\Users\\Hydra\\Documents\\dev\\playground\\rust\\buildfailure-1\\crates\\boards\\target\\thumbv7m-none-eabi\\debug\\deps\\boards-381a71c28462db46.s": The system cannot find the file specified. (os error 2)

See log (attached)

log.txt

Upon investigation it appears that the rustflags (in the cargo configuration) --emit asm cause the subsequent build failure, but only when -C save-temps is NOT used.

i.e:

savetemps emit asm result
disabled disabled success
enabled disabled success
disabled enabled failure
enabled enabled success

Meta

rustc --version --verbose:

rustc 1.57.0-nightly (5ecc8ad84 2021-09-19)
binary: rustc
commit-hash: 5ecc8ad8462574354a55162a0c16b10eb95e3e70
commit-date: 2021-09-19
host: x86_64-pc-windows-gnu
release: 1.57.0-nightly
LLVM version: 13.0.0
@hydra hydra added the C-bug Category: This is a bug. label Sep 21, 2021
@bjorn3
Copy link
Member

bjorn3 commented Sep 21, 2021

Does the same thing happen with CARGO_INCREMENTAL=0? It is possible that this is caused by the assembly file not being stored in the incremental cache, yet not regenerated due to the codegen unit dependencies still being fresh.

@hydra
Copy link
Author

hydra commented Feb 15, 2023

Just following up on this.

The problem still exists with the nightly I'm currently using:

rustc 1.64.0-nightly (1c7b36d4d 2022-07-12)
binary: rustc
commit-hash: 1c7b36d4db582cb47513a6c7176baaec1c3346ab
commit-date: 2022-07-12
host: x86_64-pc-windows-gnu
release: 1.64.0-nightly
LLVM version: 14.0.6

To replicate, extract the example project, comment out Line 22 in the crates/boards/cargo/config.toml as follows:

Original:

  "-C", "save-temps", # <-- when this is disabled, the subsequent build fails, but only when `--emit asm` is also enabled.

Commented out:

  #"-C", "save-temps", # <-- when this is disabled, the subsequent build fails, but only when `--emit asm` is also enabled.

Then run this command sequence:

cd crates/boards
cargo build --bin=nucleof446re --target=thumbv7em-none-eabihf --features="dep-stm32f446" -vv
cargo build --bin=nucleof446re --target=thumbv7em-none-eabihf --features="dep-stm32f446" -vv

Then observe the errors:

error: could not copy "D:\\Users\\Hydra\\Documents\\dev\\playground\\rust\\buildfailure-1\\crates\\boards\\target\\thumbv7em-none-eabihf\\debug\\deps\\boards-b22cf056f2c46d98.3dm2sxxyyyvowhj0.rcgu.s" to "D:\\Users\\Hydra\\Documents\\dev\\playground\\rust\\buildfailure-1\\crates\\boards\\target\\thumbv7em-none-eabihf\\debug\\deps\\boards-b22cf056f2c46d98.s": The system cannot find the file specified. (os error 2)

error: could not compile `boards` due to previous error

Running this command sequence, with the same cargo.toml with line 22 commented out results in success.

cd crates/boards
CARGO_INCREMENTAL=0 cargo build --bin=nucleof446re --target=thumbv7em-none-eabihf --features="dep-stm32f446" -vv
CARGO_INCREMENTAL=0 cargo build --bin=nucleof446re --target=thumbv7em-none-eabihf --features="dep-stm32f446" -vv

This indicates that there is an issue with cargo incremental builds right?

What happens next?

@hydra
Copy link
Author

hydra commented Feb 15, 2023

The problem still exists on a nightly from yesterday:

$ rustup default nightly-2023-02-14
...
$ rustup target add thumbv7m-none-eabi
$ rustup target add thumbv7em-none-eabihf
$ rustc --version --verbose
rustc 1.69.0-nightly (065852def 2023-02-13)
binary: rustc
commit-hash: 065852def0903296da33a9eaf557f230bcf3a61a
commit-date: 2023-02-13
host: x86_64-pc-windows-gnu
release: 1.69.0-nightly
LLVM version: 15.0.7

@pacak
Copy link
Contributor

pacak commented Mar 27, 2024

FWIW it's still broken in current nightly, I have a reproduction case with no external dependencies: a crate with this source

pub fn main() -> u32 {
    1
}

And this command: export RUSTC_OPTIONS=--emit=asm; rm -rf target ; cargo build ; touch src/lib.rs ; cargo build

Does the same thing happen with CARGO_INCREMENTAL=0?

No, disabling incremental compilation seem to fix the problem.

It is possible that this is caused by the assembly file not being stored in the incremental cache, yet not regenerated due to the codegen unit dependencies still being fresh.

As far as I can see there's no assembly files in the incremental cache. They should probably be saved if --emit is present so #122597 can produce the right values. Regenerating means codegen must run either way which defeats the purpose of the incremental cache. Reading though incremental compilation docs, trying to understand how it supposed to work.

@pacak
Copy link
Contributor

pacak commented Mar 28, 2024

bors added a commit to rust-lang-ci/rust that referenced this issue Apr 6, 2024
Save/restore more items in cache with incremental compilation

Right now they don't play very well together, consider a simple example:

```
$ export RUSTFLAGS="--emit asm"
$ cargo new --lib foo
     Created library `foo` package
$ cargo build -q
$ touch src/lib.rs
$ cargo build
error: could not copy
  "/path/to/foo/target/debug/deps/foo-e307cc7fa7b6d64f.4qbzn9k8mosu50a5.rcgu.s"
  to "/path/to/foo/target/debug/deps/foo-e307cc7fa7b6d64f.s":
  No such file or directory (os error 2)
```

Touch triggers the rebuild, incremental compilation detects no changes (yay) and everything explodes while trying to copy files were they should go.

This pull request fixes it by copying and restoring more files in the incremental compilation cache

Fixes rust-lang#89149
Fixes rust-lang#88829

Related: https://internals.rust-lang.org/t/interaction-between-incremental-compilation-and-emit/20551
@bors bors closed this as completed in fc1a4c5 Apr 7, 2024
@hydra
Copy link
Author

hydra commented Apr 7, 2024

@pacak Great to see this fixed, thanks for the investigation and PR!

bjorn3 pushed a commit to rust-lang/rustc_codegen_cranelift that referenced this issue Apr 11, 2024
Save/restore more items in cache with incremental compilation

Right now they don't play very well together, consider a simple example:

```
$ export RUSTFLAGS="--emit asm"
$ cargo new --lib foo
     Created library `foo` package
$ cargo build -q
$ touch src/lib.rs
$ cargo build
error: could not copy
  "/path/to/foo/target/debug/deps/foo-e307cc7fa7b6d64f.4qbzn9k8mosu50a5.rcgu.s"
  to "/path/to/foo/target/debug/deps/foo-e307cc7fa7b6d64f.s":
  No such file or directory (os error 2)
```

Touch triggers the rebuild, incremental compilation detects no changes (yay) and everything explodes while trying to copy files were they should go.

This pull request fixes it by copying and restoring more files in the incremental compilation cache

Fixes rust-lang/rust#89149
Fixes rust-lang/rust#88829

Related: https://internals.rust-lang.org/t/interaction-between-incremental-compilation-and-emit/20551
RalfJung pushed a commit to RalfJung/miri that referenced this issue Apr 15, 2024
Save/restore more items in cache with incremental compilation

Right now they don't play very well together, consider a simple example:

```
$ export RUSTFLAGS="--emit asm"
$ cargo new --lib foo
     Created library `foo` package
$ cargo build -q
$ touch src/lib.rs
$ cargo build
error: could not copy
  "/path/to/foo/target/debug/deps/foo-e307cc7fa7b6d64f.4qbzn9k8mosu50a5.rcgu.s"
  to "/path/to/foo/target/debug/deps/foo-e307cc7fa7b6d64f.s":
  No such file or directory (os error 2)
```

Touch triggers the rebuild, incremental compilation detects no changes (yay) and everything explodes while trying to copy files were they should go.

This pull request fixes it by copying and restoring more files in the incremental compilation cache

Fixes rust-lang/rust#89149
Fixes rust-lang/rust#88829

Related: https://internals.rust-lang.org/t/interaction-between-incremental-compilation-and-emit/20551
jieyouxu added a commit to jieyouxu/rust that referenced this issue Jun 3, 2024
Show files produced by `--emit foo` in json artifact notifications

Right now it is possible to ask `rustc` to save some intermediate representation into one or more files with `--emit=foo`, but figuring out what exactly was produced is difficult. This pull request adds information about `llvm_ir` and `asm` intermediate files into notifications produced by `--json=artifacts`.

Related discussion: https://internals.rust-lang.org/t/easier-access-to-files-generated-by-emit-foo/20477

Motivation - `cargo-show-asm` parses those intermediate files and presents them in a user friendly way, but right now I have to apply some dirty hacks. Hacks make behavior confusing: hintron/computer-enhance#35

This pull request introduces a new behavior: now `rustc` will emit a new artifact notification for every artifact type user asked to `--emit`, for example for `--emit asm` those will include all the `.s` files.

Most users won't notice this behavior, to be affected by it all of the following must hold:
- user must use `rustc` binary directly (when `cargo` invokes `rustc` - it consumes artifact notifications and doesn't emit anything)
- user must specify both `--emit xxx` and `--json artifacts`
- user must refuse to handle unknown artifact types
- user must disable incremental compilation (or deal with it better than cargo does, or use a workaround like `save-temps`) in order not to hit rust-lang#88829 / rust-lang#89149
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jun 3, 2024
Show files produced by `--emit foo` in json artifact notifications

Right now it is possible to ask `rustc` to save some intermediate representation into one or more files with `--emit=foo`, but figuring out what exactly was produced is difficult. This pull request adds information about `llvm_ir` and `asm` intermediate files into notifications produced by `--json=artifacts`.

Related discussion: https://internals.rust-lang.org/t/easier-access-to-files-generated-by-emit-foo/20477

Motivation - `cargo-show-asm` parses those intermediate files and presents them in a user friendly way, but right now I have to apply some dirty hacks. Hacks make behavior confusing: hintron/computer-enhance#35

This pull request introduces a new behavior: now `rustc` will emit a new artifact notification for every artifact type user asked to `--emit`, for example for `--emit asm` those will include all the `.s` files.

Most users won't notice this behavior, to be affected by it all of the following must hold:
- user must use `rustc` binary directly (when `cargo` invokes `rustc` - it consumes artifact notifications and doesn't emit anything)
- user must specify both `--emit xxx` and `--json artifacts`
- user must refuse to handle unknown artifact types
- user must disable incremental compilation (or deal with it better than cargo does, or use a workaround like `save-temps`) in order not to hit rust-lang#88829 / rust-lang#89149
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jun 3, 2024
Show files produced by `--emit foo` in json artifact notifications

Right now it is possible to ask `rustc` to save some intermediate representation into one or more files with `--emit=foo`, but figuring out what exactly was produced is difficult. This pull request adds information about `llvm_ir` and `asm` intermediate files into notifications produced by `--json=artifacts`.

Related discussion: https://internals.rust-lang.org/t/easier-access-to-files-generated-by-emit-foo/20477

Motivation - `cargo-show-asm` parses those intermediate files and presents them in a user friendly way, but right now I have to apply some dirty hacks. Hacks make behavior confusing: hintron/computer-enhance#35

This pull request introduces a new behavior: now `rustc` will emit a new artifact notification for every artifact type user asked to `--emit`, for example for `--emit asm` those will include all the `.s` files.

Most users won't notice this behavior, to be affected by it all of the following must hold:
- user must use `rustc` binary directly (when `cargo` invokes `rustc` - it consumes artifact notifications and doesn't emit anything)
- user must specify both `--emit xxx` and `--json artifacts`
- user must refuse to handle unknown artifact types
- user must disable incremental compilation (or deal with it better than cargo does, or use a workaround like `save-temps`) in order not to hit rust-lang#88829 / rust-lang#89149
bors added a commit to rust-lang-ci/rust that referenced this issue Jun 4, 2024
Show files produced by `--emit foo` in json artifact notifications

Right now it is possible to ask `rustc` to save some intermediate representation into one or more files with `--emit=foo`, but figuring out what exactly was produced is difficult. This pull request adds information about `llvm_ir` and `asm` intermediate files into notifications produced by `--json=artifacts`.

Related discussion: https://internals.rust-lang.org/t/easier-access-to-files-generated-by-emit-foo/20477

Motivation - `cargo-show-asm` parses those intermediate files and presents them in a user friendly way, but right now I have to apply some dirty hacks. Hacks make behavior confusing: hintron/computer-enhance#35

This pull request introduces a new behavior: now `rustc` will emit a new artifact notification for every artifact type user asked to `--emit`, for example for `--emit asm` those will include all the `.s` files.

Most users won't notice this behavior, to be affected by it all of the following must hold:
- user must use `rustc` binary directly (when `cargo` invokes `rustc` - it consumes artifact notifications and doesn't emit anything)
- user must specify both `--emit xxx` and `--json artifacts`
- user must refuse to handle unknown artifact types
- user must disable incremental compilation (or deal with it better than cargo does, or use a workaround like `save-temps`) in order not to hit rust-lang#88829 / rust-lang#89149
bjorn3 pushed a commit to bjorn3/rust that referenced this issue Jun 30, 2024
Show files produced by `--emit foo` in json artifact notifications

Right now it is possible to ask `rustc` to save some intermediate representation into one or more files with `--emit=foo`, but figuring out what exactly was produced is difficult. This pull request adds information about `llvm_ir` and `asm` intermediate files into notifications produced by `--json=artifacts`.

Related discussion: https://internals.rust-lang.org/t/easier-access-to-files-generated-by-emit-foo/20477

Motivation - `cargo-show-asm` parses those intermediate files and presents them in a user friendly way, but right now I have to apply some dirty hacks. Hacks make behavior confusing: hintron/computer-enhance#35

This pull request introduces a new behavior: now `rustc` will emit a new artifact notification for every artifact type user asked to `--emit`, for example for `--emit asm` those will include all the `.s` files.

Most users won't notice this behavior, to be affected by it all of the following must hold:
- user must use `rustc` binary directly (when `cargo` invokes `rustc` - it consumes artifact notifications and doesn't emit anything)
- user must specify both `--emit xxx` and `--json artifacts`
- user must refuse to handle unknown artifact types
- user must disable incremental compilation (or deal with it better than cargo does, or use a workaround like `save-temps`) in order not to hit rust-lang#88829 / rust-lang#89149
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants