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

Changing workspace Cargo.toml doesn't invalidate build cache for workspace members #14154

Closed
illicitonion opened this issue Jun 26, 2024 · 6 comments · Fixed by #14973
Closed
Assignees
Labels
A-dep-info Area: dep-info, .d files A-environment-variables Area: environment variables A-rebuild-detection Area: rebuild detection and fingerprinting C-bug Category: bug S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review

Comments

@illicitonion
Copy link
Contributor

illicitonion commented Jun 26, 2024

Problem

The environment variables Cargo sets when building crates don't appear to get updated if the crate's Cargo.toml inherits values from the workspace, and the only change between builds is the value in the workspace's Cargo.toml.

Steps

% cat >Cargo.toml <<EOF
[workspace]
members = ["lib"]
package.version = "0.2.0"
package.readme = "beep.md"
EOF
% mkdir -p lib/src
% cat >lib/Cargo.toml <<EOF
[package]
name = "lib"
version = "0.1.0"
edition = "2021"
readme = { workspace = true }
EOF
% cat >lib/src/main.rs <<EOF
fn main() {
    println!("Readme: {}", env!("CARGO_PKG_README"));
}
EOF
% cargo run -p lib 2>/dev/null
Readme: ../beep.md
% cat >Cargo.toml <<EOF
[workspace]
members = ["lib"]
package.version = "0.2.0"
package.readme = true
EOF
% # Next command should print ../README.md because the workspace value changed:
% cargo run -p lib 2>/dev/null
Readme: ../beep.md
% # Clearing the cache forces a rebuild, which gives the correct value:
% rm -rf target
% cargo run -p lib 2>/dev/null
Readme: ../README.md

Possible Solution(s)

No response

Notes

No response

Version

cargo 1.79.0 (ffa9cf99a 2024-06-03)
release: 1.79.0
commit-hash: ffa9cf99a594e59032757403d4c780b46dc2c43a
commit-date: 2024-06-03
host: aarch64-apple-darwin
libgit2: 1.7.2 (sys:0.18.3 vendored)
libcurl: 8.1.2 (sys:0.4.72+curl-8.6.0 system ssl:(SecureTransport) LibreSSL/3.3.6)
ssl: OpenSSL 1.1.1w  11 Sep 2023
os: Mac OS 13.5.2 [64-bit]
@illicitonion illicitonion added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels Jun 26, 2024
@epage
Copy link
Contributor

epage commented Jun 26, 2024

Just reproduced this without workspace inheritance involved.

@epage epage added the A-rebuild-detection Area: rebuild detection and fingerprinting label Jun 26, 2024
@epage
Copy link
Contributor

epage commented Jun 26, 2024

Not seeing an existing issue for cargo-generated env variables but this seems similar in internals to #13280 and #10358.

@epage epage added S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted. and removed S-triage Status: This issue is waiting on initial triage. labels Jun 26, 2024
@weihanglo
Copy link
Member

Actually this doesn't need workspace to involve. Simply with a single package change package.readme = "foo" to package.readme = "bar", and observe it doesn't rebuild.

I believe the bug shares the same root cause from #13280 (comment), where CARGO_PKG_README was removed.

@weihanglo weihanglo added A-dep-info Area: dep-info, .d files A-environment-variables Area: environment variables S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review and removed S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted. labels Oct 9, 2024
@weihanglo
Copy link
Member

I'll go ahead a close this in favor of #13280. Thanks for the report and reproduction!

@weihanglo
Copy link
Member

Reopen since #13280 could have a partial fix not covering internal environment variables like CARGO_PKG_README.

@ranger-ross
Copy link
Contributor

@rustbot claim

ranger-ross added a commit to ranger-ross/cargo that referenced this issue Dec 24, 2024
This change moves the manifest metadata track to dep-info files
with the goal of reduce unneeded rebuilds when metadata is changed as
well fixing issues where builds are not retrigged due to metadata
changes when they should (ie. rust-lang#14154)
ranger-ross added a commit to ranger-ross/cargo that referenced this issue Dec 24, 2024
This change moves the manifest metadata track to dep-info files
with the goal of reduce unneeded rebuilds when metadata is changed as
well fixing issues where builds are not retrigged due to metadata
changes when they should (ie. rust-lang#14154)
github-merge-queue bot pushed a commit that referenced this issue Dec 24, 2024
<!--
Thanks for submitting a pull request 🎉! Here are some tips for you:

* If this is your first contribution, read "Cargo Contribution Guide"
first:
  https://doc.crates.io/contrib/
* Run `cargo fmt --all` to format your code changes.
* Small commits and pull requests are always preferable and easy to
review.
* If your idea is large and needs feedback from the community, read how:
  https://doc.crates.io/contrib/process/#working-on-large-features
* Cargo takes care of compatibility. Read our design principles:
  https://doc.crates.io/contrib/design.html
* When changing help text of cargo commands, follow the steps to
generate docs:

https://github.com/rust-lang/cargo/tree/master/src/doc#building-the-man-pages
* If your PR is not finished, set it as "draft" PR or add "WIP" in its
title.
* It's ok to use the CI resources to test your PR, but please don't
abuse them.

### What does this PR try to resolve?

Explain the motivation behind this change.
A clear overview along with an in-depth explanation are helpful.

You can use `Fixes #<issue number>` to associate this PR to an existing
issue.

### How should we test and review this PR?

Demonstrate how you test this change and guide reviewers through your
PR.
With a smooth review process, a pull request usually gets reviewed
quicker.

If you don't know how to write and run your tests, please read the
guide:
https://doc.crates.io/contrib/tests

### Additional information

Other information you want to mention in this PR, such as prior arts,
future extensions, an unresolved problem, or a TODO list.
-->

### What does this PR try to resolve?

Fixes #14154

~~Added some of the missing package metadata to the fingerprint so that
rebuilds are triggered correctly.~~
~~Also updated the test to prevent a future regression.~~

Moved the manifest metadata tracking to use dep info in favor of
fingerprint so that rebuilds are only triggered if the metadata is
actually used.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-dep-info Area: dep-info, .d files A-environment-variables Area: environment variables A-rebuild-detection Area: rebuild detection and fingerprinting C-bug Category: bug S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants