sfackler / rust-openssl

OpenSSL bindings for Rust
1.39k stars 743 forks source link

openssl-sys rebuilds every time I modify a file #543

Closed gsingh93 closed 7 years ago

gsingh93 commented 7 years ago

This may be an issue with Cargo, but I want to confirm it's not an issue with this crate first. When I change a file, openssl-sys shouldn't have to rebuild if it was already built, but it seems like it's being built every time. Steps to reproduce:

  1. Run cargo init build-test && cd build-test
  2. Put the following in Cargo.toml
    
    [package]
    name = "build-test"
    version = "0.1.0"

[dependencies] openssl = "0.9.4"

3. Put the following in `src/lib.rs`

[cfg(test)]

mod tests {

[test]

fn it_works() {
    println!("works!");
}

}


4. `cargo build` will pull this crate and all of it's dependencies and build them
5. Modify `lib.rs` by changing the string being printed
6. Run `cargo build` and you'll see `openssl-sys` is being built again. Only `build-test` should be built again, not any of it's dependencies.

My cargo version is `cargo 0.15.0-nightly (298a012 2016-12-20)`. I'm using Ubuntu 14.04.
sfackler commented 7 years ago

I can't reproduce this on OSX at least. Seems like it's a cargo issue rather than an openssl issue though.

alexcrichton commented 7 years ago

@gsingh93 can you set RUST_LOG=cargo::ops::cargo_rustc::fingerprint=info when a spurious recompile happens? That should explain at least what's going on here.

gsingh93 commented 7 years ago
vagrant@vagrant-ubuntu-trusty-64:/vagrant/build-test$ RUST_LOG=cargo::ops::cargo_rustc::fingerprint=info cargo build
INFO:cargo::ops::cargo_rustc::fingerprint: stale: /vagrant/build-test/src/lib.rs -- 1483306440.000000000s vs 1483302213.000000000s
INFO:cargo::ops::cargo_rustc::fingerprint: fingerprint error for build-test v0.1.0 (file:///vagrant/build-test): mtime based components have changed: previously Some(FileTime { seconds: 1483302213, nanos: 0 }) now None, paths are "/vagrant/build-test/target/debug/.fingerprint/build-test-944083931e2f0d10/dep-lib-build-test" and "/vagrant/build-test/target/debug/.fingerprint/build-test-944083931e2f0d10/dep-lib-build-test"
INFO:cargo::ops::cargo_rustc::fingerprint: fingerprint error for openssl v0.9.4: rust compiler has changed
INFO:cargo::ops::cargo_rustc::fingerprint: fingerprint error for bitflags v0.7.0: rust compiler has changed
INFO:cargo::ops::cargo_rustc::fingerprint: fingerprint error for lazy_static v0.2.2: rust compiler has changed
INFO:cargo::ops::cargo_rustc::fingerprint: fingerprint error for libc v0.2.18: rust compiler has changed
INFO:cargo::ops::cargo_rustc::fingerprint: fingerprint error for openssl-sys v0.9.4: rust compiler has changed
INFO:cargo::ops::cargo_rustc::fingerprint: fingerprint error for openssl-sys v0.9.4: rust compiler has changed
INFO:cargo::ops::cargo_rustc::fingerprint: fingerprint error for pkg-config v0.3.8: rust compiler has changed
INFO:cargo::ops::cargo_rustc::fingerprint: fingerprint error for openssl v0.9.4: rust compiler has changed
   Compiling openssl v0.9.4
   Compiling bitflags v0.7.0
   Compiling lazy_static v0.2.2
   Compiling pkg-config v0.3.8
   Compiling libc v0.2.18
   Compiling openssl-sys v0.9.4
   Compiling build-test v0.1.0 (file:///vagrant/build-test)
    Finished debug [unoptimized + debuginfo] target(s) in 8.51 secs

Based on that output, I think it's related to the fact that I'm building in Vagrant but modifying files from the native OS?

gsingh93 commented 7 years ago

Ok, the real issue here is emacs is using flycheck-mode, which is trying to compile the project on my host OS, which fails on my host OS because I don't have the right openssl lib installed. This means when I rebuild in vagrant, it needs to rebuild openssl-sys because the last build (on the host OS) failed. Disabling flycheck-mode fixes the problem.

Thanks for the help and sorry for the noise.

Timmmm commented 1 day ago

I'm running into the same issue but I'm not using Emacs. The new option is CARGO_LOG=cargo::core::compiler::fingerprint=info and the first error it gives is:

   1.115283379s  INFO prepare_target{force=false package_id=rget v0.1.0 (/home/me/workspace/rget) target="rget"}: cargo::core::compiler::fingerprint: dependency on `build_script_main` is newer than we are 1729007301.753356001s > 1729007286.214545739s "/home/me/.cargo/registry/src/index.crates.io-6f17d22bba15001f/openssl-sys-0.9.103"

I'm guessing it's rust-analyzer doing this, but that is a shame. :-/