sfackler / rust-openssl

OpenSSL bindings for Rust
1.4k stars 751 forks source link

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

Closed Timmmm closed 1 day ago

Timmmm commented 1 day ago

Reopening #543

This is easy to reproduce:

cargo init build-test
cd build-test
cargo add openssl
cargo build
code . # Open VSCode and wait for a sec.
# Edit `src/main.rs` and save it.
cargo build

You must have rust-analyzer installed in VSCode.

You'll see that it rebuilds openssl-sys even though nothing changed there.

Fingerprint debug log:

❯ CARGO_LOG=cargo::core::compiler::fingerprint=info cargo build
   0.046237146s  INFO prepare_target{force=false package_id=build-test v0.1.0 (/home/me/build-test) target="build-test"}: cargo::core::compiler::fingerprint: dependency on `build_script_main` is newer than we are 1731590354.796380061s > 1731590228.618923184s "/home/me/.cargo/registry/src/index.crates.io-6f17d22bba15001f/openssl-sys-0.9.104"
   0.046267800s  INFO prepare_target{force=false package_id=build-test v0.1.0 (/home/me/build-test) target="build-test"}: cargo::core::compiler::fingerprint: dependency on `build_script_build` is newer than we are 1731590354.822379740s > 1731590229.889907768s "/home/me/.cargo/registry/src/index.crates.io-6f17d22bba15001f/openssl-0.10.68"
   0.046335072s  INFO prepare_target{force=false package_id=build-test v0.1.0 (/home/me/build-test) target="build-test"}: cargo::core::compiler::fingerprint: fingerprint dirty for build-test v0.1.0 (/home/me/build-test)/Build/TargetInner { name: "build-test", doc: true, ..: with_path("/home/me/build-test/src/main.rs", Edition2021) }
   0.046349564s  INFO prepare_target{force=false package_id=build-test v0.1.0 (/home/me/build-test) target="build-test"}: cargo::core::compiler::fingerprint:     dirty: FsStatusOutdated(StaleDepFingerprint { name: "openssl" })
   0.046494655s  INFO prepare_target{force=false package_id=openssl v0.10.68 target="openssl"}: cargo::core::compiler::fingerprint: fingerprint dirty for openssl v0.10.68/Build/TargetInner { ..: lib_target("openssl", ["lib"], "/home/me/.cargo/registry/src/index.crates.io-6f17d22bba15001f/openssl-0.10.68/src/lib.rs", Edition2021) }
   0.046506082s  INFO prepare_target{force=false package_id=openssl v0.10.68 target="openssl"}: cargo::core::compiler::fingerprint:     dirty: FsStatusOutdated(StaleDependency { name: "build_script_build", dep_mtime: FileTime { seconds: 1731590354, nanos: 822379740 }, max_mtime: FileTime { seconds: 1731590229, nanos: 889907768 } })
   0.047023475s  INFO prepare_target{force=false package_id=openssl v0.10.68 target="build-script-build"}: cargo::core::compiler::fingerprint: fingerprint dirty for openssl v0.10.68/RunCustomBuild/TargetInner { ..: custom_build_target("build-script-build", "/home/me/.cargo/registry/src/index.crates.io-6f17d22bba15001f/openssl-0.10.68/build.rs", Edition2021) }
   0.047034494s  INFO prepare_target{force=false package_id=openssl v0.10.68 target="build-script-build"}: cargo::core::compiler::fingerprint:     dirty: UnitDependencyInfoChanged { old_name: "build_script_main", old_fingerprint: 18015232584764894201, new_name: "build_script_main", new_fingerprint: 7179330508031645151 }
   0.053380961s  INFO prepare_target{force=false package_id=openssl-sys v0.9.104 target="build-script-main"}: cargo::core::compiler::fingerprint: fingerprint dirty for openssl-sys v0.9.104/RunCustomBuild/TargetInner { ..: custom_build_target("build-script-main", "/home/me/.cargo/registry/src/index.crates.io-6f17d22bba15001f/openssl-sys-0.9.104/build/main.rs", Edition2021) }
   0.053398653s  INFO prepare_target{force=false package_id=openssl-sys v0.9.104 target="build-script-main"}: cargo::core::compiler::fingerprint:     dirty: EnvVarChanged { name: "PKG_CONFIG_PATH", old_value: Some("/opt/rh/gcc-toolset-12/root/usr/lib64/pkgconfig:/opt/rh/gcc-toolset-12/root/usr/lib64/pkgconfig"), new_value: Some("/opt/rh/gcc-toolset-12/root/usr/lib64/pkgconfig:/opt/rh/gcc-toolset-12/root/usr/lib64/pkgconfig:/opt/rh/gcc-toolset-12/root/usr/lib64/pkgconfig") }
   0.054027350s  INFO prepare_target{force=false package_id=openssl-sys v0.9.104 target="openssl_sys"}: cargo::core::compiler::fingerprint: fingerprint dirty for openssl-sys v0.9.104/Build/TargetInner { ..: lib_target("openssl_sys", ["lib"], "/home/me/.cargo/registry/src/index.crates.io-6f17d22bba15001f/openssl-sys-0.9.104/src/lib.rs", Edition2021) }
   0.054040270s  INFO prepare_target{force=false package_id=openssl-sys v0.9.104 target="openssl_sys"}: cargo::core::compiler::fingerprint:     dirty: FsStatusOutdated(StaleDependency { name: "build_script_main", dep_mtime: FileTime { seconds: 1731590354, nanos: 796380061 }, max_mtime: FileTime { seconds: 1731590228, nanos: 618923184 } })
   Compiling openssl-sys v0.9.104
   Compiling openssl v0.10.68
   Compiling build-test v0.1.0 (/home/me/build-test)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.77s

It's something to do with rust-analyzer, but it still shouldn't happen. rust-analyzer doesn't cause unnecessary rebuilds of other crates. Potentially a bug with rust-analyzer but I'm not sure.

sfackler commented 1 day ago

Why is your PKG_CONFIG_PATH changing?

   0.053398653s  INFO prepare_target{force=false package_id=openssl-sys v0.9.104 target="build-script-main"}: cargo::core::compiler::fingerprint:     dirty: EnvVarChanged { name: "PKG_CONFIG_PATH", old_value: Some("/opt/rh/gcc-toolset-12/root/usr/lib64/pkgconfig:/opt/rh/gcc-toolset-12/root/usr/lib64/pkgconfig"), new_value: Some("/opt/rh/gcc-toolset-12/root/usr/lib64/pkgconfig:/opt/rh/gcc-toolset-12/root/usr/lib64/pkgconfig:/opt/rh/gcc-toolset-12/root/usr/lib64/pkgconfig") }
Timmmm commented 1 day ago

Ah good spot! It's because I have this in my .bashrc:

source /opt/rh/gcc-toolset-12/enable

I guess it just appends to PKG_CONFIG_PATH, and for some reason rust-analyzer and my shell have a different number of nested Bash sessions or something? That is kind of annoying; I can't really think of a good way to solve this so I guess I'll close it & fix my .bashrc. Would be nice if Cargo had slightly more readable & easy to access output for this at least!

Thanks for the help!