Skip to content

Compiled crates are not reused across dev/release even if the configuration is the same #7627

Closed
@Vlad-Shcherbina

Description

@Vlad-Shcherbina

Steps to reproduce

  1. Create a crate with the following Cargo.toml:
    [package]
    name = "cargo_cache_is_frustrating"
    version = "0.1.0"
    edition = "2018"
    
    [dependencies]
    bitflags = "1.2"
    
    [profile.dev]
    opt-level = 3
    debug = false
    rpath = false
    lto = false
    debug-assertions = false
    codegen-units = 16
    panic = 'unwind'
    incremental = false
    overflow-checks = false
    
    [profile.release]  # exactly the same
    opt-level = 3
    debug = false
    rpath = false
    lto = false
    debug-assertions = false
    codegen-units = 16
    panic = 'unwind'
    incremental = false
    overflow-checks = false
  2. cargo build
  3. cargo build --release

Actual result

> cargo build
   Compiling bitflags v1.2.1
   Compiling cargo_cache_is_frustrating v0.1.0 (...\cargo_cache_is_frustrating)
    Finished dev [optimized] target(s) in 1.92s
> cargo build --release
   Compiling bitflags v1.2.1
   Compiling cargo_cache_is_frustrating v0.1.0 (...\cargo_cache_is_frustrating)
    Finished release [optimized] target(s) in 4.33s

Expected result

> cargo build
   Compiling bitflags v1.2.1
   Compiling cargo_cache_is_frustrating v0.1.0 (...\cargo_cache_is_frustrating)
    Finished dev [optimized] target(s) in 1.92s
> cargo build --release
    Finished release [optimized] target(s) in 0.00s

I checked cargo --build-plan outputs and they're identical
except they use paths in target/debug and target/release and

 {
     "invocations": [
         ...
         {
             "package_name": "bitflags",
             ...
             "env": {
                 ...
-                "PROFILE": "debug",
+                "PROFILE": "release",

Why do I care

In this case maybe I don't. It's just a small repro. However, this also happens with dependency profile overrides, and there it entirely defeats one of their main purposes.

Version info

> cargo version --verbose
cargo 1.41.0-nightly (8280633db 2019-11-11)
release: 1.41.0
commit-hash: 8280633db680dec5bfe1de25156d1a1d53e6d190
commit-date: 2019-11-11

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions