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

fix: set OUT_DIR for all units with build scripts #13204

Merged
merged 2 commits into from
Jan 8, 2024

Conversation

Rustin170506
Copy link
Member

@Rustin170506 Rustin170506 commented Dec 25, 2023

What does this PR try to resolve?

close #13127

  • Added a minimal case to cover this behavior.
  • Set OUT_DIR for all units with build scripts.

How should we test and review this PR?

Check out the unit test.

Additional information

None

@rustbot
Copy link
Collaborator

rustbot commented Dec 25, 2023

r? @ehuss

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 25, 2023
@Rustin170506 Rustin170506 changed the title WIP: test: include a case for setting OUT_DIR fix: set OUT_DIR for all units with build scripts Dec 27, 2023
@Rustin170506 Rustin170506 marked this pull request as ready for review December 27, 2023 02:50
Copy link
Member Author

@Rustin170506 Rustin170506 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔢 Self-check

tests/testsuite/test.rs Outdated Show resolved Hide resolved
Comment on lines +189 to +213
// Add `OUT_DIR` to env vars if unit has a build script.
let units_with_build_script = &self
.bcx
.roots
.iter()
.filter(|unit| self.build_scripts.contains_key(unit))
.dedup_by(|x, y| x.pkg.package_id() == y.pkg.package_id())
.collect::<Vec<_>>();
for unit in units_with_build_script {
for dep in &self.bcx.unit_graph[unit] {
if dep.unit.mode.is_run_custom_build() {
let out_dir = self
.files()
.build_script_out_dir(&dep.unit)
.display()
.to_string();
let script_meta = self.get_run_build_script_metadata(&dep.unit);
self.compilation
.extra_env
.entry(script_meta)
.or_insert_with(Vec::new)
.push(("OUT_DIR".to_string(), out_dir));
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm understanding this, we only really need to set OUT_DIR once per package and the previous code did that be assuming the lib unit was sufficient (but some packages don't have that).

I'm assuming there isn't a more direct way to iterate over packages to find out the necessary information and set it, and instead we have to walk all units and de-dupe down to individual packages?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I think your understanding is correct. Before https://github.com/rust-lang/cargo/pull/3310/files, we set it for every unit.
image

@ehuss
Copy link
Contributor

ehuss commented Jan 2, 2024

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 2, 2024
Signed-off-by: hi-rustin <rustin.liu@gmail.com>

test: remove the env set by Cargo

Signed-off-by: hi-rustin <rustin.liu@gmail.com>

Fix

Signed-off-by: hi-rustin <rustin.liu@gmail.com>
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
@rustbot rustbot added the A-testing-cargo-itself Area: cargo's tests label Jan 8, 2024
@Rustin170506
Copy link
Member Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author. labels Jan 8, 2024
@ehuss
Copy link
Contributor

ehuss commented Jan 8, 2024

Thanks!

@bors r+

@bors
Copy link
Collaborator

bors commented Jan 8, 2024

📌 Commit 6739c7e has been approved by ehuss

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 8, 2024
@bors
Copy link
Collaborator

bors commented Jan 8, 2024

⌛ Testing commit 6739c7e with merge 0c98d6e...

@bors
Copy link
Collaborator

bors commented Jan 8, 2024

☀️ Test successful - checks-actions
Approved by: ehuss
Pushing 0c98d6e to master...

@bors bors merged commit 0c98d6e into rust-lang:master Jan 8, 2024
17 of 18 checks passed
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 10, 2024
Update cargo

14 commits in 2ce45605d9db521b5fd6c1211ce8de6055fdb24e..3e428a38a34e820a461d2cc082e726d3bda71bcb
2024-01-04 18:04:13 +0000 to 2024-01-09 20:46:36 +0000
- refactor: replace `iter_join` with `itertools::join` (rust-lang/cargo#13275)
- docs(unstable): doc comments for items and fields (rust-lang/cargo#13274)
- crates-io: Set `Content-Type: application/json` only for requests with a body payload (rust-lang/cargo#13264)
- fix: only inherit workspace package table if the new package is a member (rust-lang/cargo#13261)
- feat(cli): add colors to `-Zhelp` console output (rust-lang/cargo#13269)
- chore(deps): update msrv (rust-lang/cargo#13266)
- refactor(toml): Make it more obvious to update package-dependent fields (rust-lang/cargo#13267)
- chore(ci): Fix MSRV:3 updates (rust-lang/cargo#13268)
- chore(ci): Shot-in-the-dark fix for MSRV updating (rust-lang/cargo#13265)
- fix: set OUT_DIR for all units with build scripts (rust-lang/cargo#13204)
- fix(manifest): Provide unused key warnings for lints table (rust-lang/cargo#13262)
- test(manifest): Verify we warn on unused workspace.package fields (rust-lang/cargo#13263)
- docs(changelog): Call out cargo-new lockfile change (rust-lang/cargo#13260)
- chore: Add dependency dashboard (rust-lang/cargo#13255)

r? ghost
@ehuss ehuss added this to the 1.77.0 milestone Mar 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-testing-cargo-itself Area: cargo's tests S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OUT_DIR env var Behaviour discrepancy between testing a whole crate and individual test
5 participants