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

Cargo must be invoked twice in order to observe changes to a binary dependency #10527

Closed
Tracked by #10061
bstrie opened this issue Mar 31, 2022 · 2 comments · Fixed by #11353
Closed
Tracked by #10061

Cargo must be invoked twice in order to observe changes to a binary dependency #10527

bstrie opened this issue Mar 31, 2022 · 2 comments · Fixed by #11353
Labels
C-bug Category: bug Z-bindeps Nightly: binary artifact dependencies

Comments

@bstrie
Copy link
Contributor

bstrie commented Mar 31, 2022

Problem

For convenience I have also uploaded the failing code here: https://github.com/bstrie/bindeperror3

For the following code:

# Cargo.toml
[package]
name = "mycrate"
version = "0.0.0"
edition = "2021"

[dependencies]
sha2 = "0.10.2"
mybindep = { path = "mybindep", artifact = "bin" }
// src/main.rs
use sha2::{Sha256, Digest};

fn main() {
    let mut hasher = Sha256::new();
    hasher.update(include_bytes!(env!("CARGO_BIN_FILE_MYBINDEP")));
    println!("{:?}", hasher.finalize());
}
# mybindep/Cargo.toml
[package]
name = "mybindep"
version = "0.0.0"
edition = "2021"
fn main() {
    println!("foo");
}

Let us first run the code:

 > cargo run
   Compiling typenum v1.15.0
   Compiling version_check v0.9.4
   Compiling cfg-if v1.0.0
   Compiling cpufeatures v0.2.2
   Compiling mybindep v0.0.0 (/home/ben/code/scrap/bindeperror3/mybindep)
   Compiling generic-array v0.14.5
   Compiling block-buffer v0.10.2
   Compiling crypto-common v0.1.3
   Compiling digest v0.10.3
   Compiling sha2 v0.10.2
   Compiling mycrate v0.0.0 (/home/ben/code/scrap/bindeperror3)
    Finished dev [unoptimized + debuginfo] target(s) in 1.95s
     Running `target/debug/mycrate`
[35, 165, 2, 6, 70, 200, 127, 252, 43, 208, 70, 63, 14, 19, 101, 135, 230, 79, 67, 17, 117, 166, 95, 151, 147, 22, 222, 242, 7, 48, 74, 56]

Observe what happens if we make a change to mybindep:

- println!("foo");
+ println!("bar");

And then run the code again:

 > cargo run
   Compiling mybindep v0.0.0 (/home/ben/code/scrap/bindeperror3/mybindep)
    Finished dev [unoptimized + debuginfo] target(s) in 0.13s
     Running `target/debug/mycrate`
[35, 165, 2, 6, 70, 200, 127, 252, 43, 208, 70, 63, 14, 19, 101, 135, 230, 79, 67, 17, 117, 166, 95, 151, 147, 22, 222, 242, 7, 48, 74, 56]

Observe that while mybindep has been rebuilt, mycrate has not been rebuilt. We see that the hashed output of the mybindep binary as printed by mycrate is exactly the same as the first time, confirming that mycrate has not been rebuilt to include the new build of mybindep.

Now, without making any changes, immediately run the command again:

 > cargo run
   Compiling mycrate v0.0.0 (/home/ben/code/scrap/bindeperror3)
    Finished dev [unoptimized + debuginfo] target(s) in 0.23s
     Running `target/debug/mycrate`
[152, 255, 186, 13, 42, 128, 123, 193, 51, 22, 206, 127, 175, 78, 6, 146, 219, 61, 6, 224, 22, 93, 29, 5, 174, 55, 223, 183, 92, 29, 92, 43]

Now we see that mycrate has been rebuilt, and the different hash confirms that my crate is now observing the changed mybindep.

cc @Byron

Version

cargo 1.61.0-nightly (109bfbd 2022-03-17)
release: 1.61.0-nightly
commit-hash: 109bfbd055325ef87a6e7f63d67da7e838f8300b
commit-date: 2022-03-17
host: x86_64-unknown-linux-gnu
libgit2: 1.4.2 (sys:0.14.2 vendored)
libcurl: 7.80.0-DEV (sys:0.4.51+curl-7.80.0 vendored ssl:OpenSSL/1.1.1m)
os: Pop!_OS 21.10 (impish) [64-bit]
@bstrie bstrie added the C-bug Category: bug label Mar 31, 2022
@weihanglo weihanglo added the Z-bindeps Nightly: binary artifact dependencies label Apr 1, 2022
@bstrie
Copy link
Contributor Author

bstrie commented Apr 7, 2022

For anyone else hitting this issue, note that you can work around it via a top-level build script that contains the following:

println!("cargo:rerun-if-changed=directory_where_binary_dependency_lives");

bstrie added a commit to bstrie/enarx that referenced this issue Apr 7, 2022
This works around the bug reported at
rust-lang/cargo#10527

Signed-off-by: bstrie <865233+bstrie@users.noreply.github.com>
enarxbot pushed a commit to enarx/enarx that referenced this issue Apr 7, 2022
This works around the bug reported at
rust-lang/cargo#10527

Signed-off-by: bstrie <865233+bstrie@users.noreply.github.com>
@henrikpersson
Copy link

Was this fixed already? I can't reproduce it anymore, both binaries are being rebuilt on my first cargo run.

cargo 1.67.0-nightly (9286a1beb 2022-11-04)
release: 1.67.0-nightly
commit-hash: 9286a1beba5b28b115bad67de2ae91fb1c61eb0b
commit-date: 2022-11-04
host: aarch64-apple-darwin
libgit2: 1.5.0 (sys:0.15.0 vendored)
libcurl: 7.79.1 (sys:0.4.59+curl-7.86.0 system ssl:(SecureTransport) LibreSSL/3.3.6)
os: Mac OS 12.5.1 [64-bit]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug Z-bindeps Nightly: binary artifact dependencies
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants