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(build-rs)!: Updates from an audit #14817

Merged
merged 11 commits into from
Nov 14, 2024
Merged

Conversation

epage
Copy link
Contributor

@epage epage commented Nov 13, 2024

What does this PR try to resolve?

Did a quick audit for parts of the API and implementation that stood out to me. So far, I've mostly focused on "input".

How should we test and review this PR?

Additional information

CC @CAD97

@rustbot
Copy link
Collaborator

rustbot commented Nov 13, 2024

r? @ehuss

rustbot has assigned @ehuss.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 13, 2024
Copy link
Contributor

@CAD97 CAD97 left a comment

Choose a reason for hiding this comment

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

Improvements all look good to me 👍

crates/build-rs/src/input.rs Outdated Show resolved Hide resolved
var_os(key).is_some()
}

#[track_caller]
Copy link
Contributor

Choose a reason for hiding this comment

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

Note to reviewers: buildscripts are compiled without debug info by default, so backtraces aren't helpful. That's why #[track_caller] is applied so liberally here, so the caller actually knows where the bad call was made.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wonder where we should record design principles like that. For example, I had considered moving to env! but realized that re-running is cheaper than recompilation

Copy link
Contributor

Choose a reason for hiding this comment

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

The default answer would be a DESIGN.md alongside README.md. That seems as reasonable a choice as any other1, although any such document always is difficult to organize and keep up to date.

As for env! — it's lots of "fun" to keep track of whether we're querying the environment for building build-rs (set at our compile time) or for the client buildscript (only set at our run time).

Footnotes

  1. The main alternative being a wiki page, which is even less likely to be updated or even looked at ime since it isn't colocated.

Copy link
Member

Choose a reason for hiding this comment

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

For build-rs I think we should in general query only runtime envs, though I don't fully get the context of using env! for this function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The only time we use env! is to get build-rss MSRV. If we were to do things at compile time, we'd have to turn all of these functions into macros so that env! runs in the callers context.

crates/build-rs/src/input.rs Outdated Show resolved Hide resolved
Copy link
Member

@weihanglo weihanglo left a comment

Choose a reason for hiding this comment

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

Thank you both. Looks great!

Comment on lines +596 to +601
match value.parse() {
Ok(s) => s,
Err(err) => {
panic!("{err}")
}
}
Copy link
Member

Choose a reason for hiding this comment

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

nit: any reason we can't do this?

Suggested change
match value.parse() {
Ok(s) => s,
Err(err) => {
panic!("{err}")
}
}
value.parse().unwrap()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The question is whether to report Debug or Display

@weihanglo
Copy link
Member

Anyway, the only nit is just a nit. Going to merge this now.

@weihanglo weihanglo added this pull request to the merge queue Nov 14, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 14, 2024
@weihanglo weihanglo added this pull request to the merge queue Nov 14, 2024
Merged via the queue into rust-lang:master with commit 3ad481e Nov 14, 2024
20 checks passed
@epage epage deleted the cleanup branch November 14, 2024 15:53
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 16, 2024
Update cargo

15 commits in 4a2d8dc636445b276288543882e076f254b3ae95..69e595908e2c420e7f0d1be34e6c5b984c8cfb84
2024-11-09 19:10:33 +0000 to 2024-11-16 01:26:11 +0000
- refactor(fingerprint): Track the intent for each use of `UnitHash` (rust-lang/cargo#14826)
- fix(toml): Update frontmatter parser for RFC 3503 (rust-lang/cargo#14792)
- docs(unstable): Move -Zwarnings from stable to unstable section (rust-lang/cargo#14827)
- Simplify English used in guide (rust-lang/cargo#14825)
- feat(resolver): Stabilize resolver v3 (rust-lang/cargo#14754)
- docs: Clean up doc comments (rust-lang/cargo#14823)
- fix(remove): On error, suggest other dependencies  (rust-lang/cargo#14818)
- Always include Cargo.lock in published crates (rust-lang/cargo#14815)
- fix(build-rs)!: Updates from an audit (rust-lang/cargo#14817)
- feat(rustdoc): diplay env vars in extra verbose mode  (rust-lang/cargo#14812)
- Migrate build-rs to the Cargo repo (rust-lang/cargo#14786)
- chore(ci): Check for clippy `correctness` (rust-lang/cargo#14796)
- git: do not validate submodules of fresh checkouts (rust-lang/cargo#14605)
- refactor: clone-on-write when needed for InternedString (rust-lang/cargo#14808)
- fix(docs): typo in cargo-fmt.md (rust-lang/cargo#14805)
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 16, 2024
Update cargo

15 commits in 4a2d8dc636445b276288543882e076f254b3ae95..69e595908e2c420e7f0d1be34e6c5b984c8cfb84
2024-11-09 19:10:33 +0000 to 2024-11-16 01:26:11 +0000
- refactor(fingerprint): Track the intent for each use of `UnitHash` (rust-lang/cargo#14826)
- fix(toml): Update frontmatter parser for RFC 3503 (rust-lang/cargo#14792)
- docs(unstable): Move -Zwarnings from stable to unstable section (rust-lang/cargo#14827)
- Simplify English used in guide (rust-lang/cargo#14825)
- feat(resolver): Stabilize resolver v3 (rust-lang/cargo#14754)
- docs: Clean up doc comments (rust-lang/cargo#14823)
- fix(remove): On error, suggest other dependencies  (rust-lang/cargo#14818)
- Always include Cargo.lock in published crates (rust-lang/cargo#14815)
- fix(build-rs)!: Updates from an audit (rust-lang/cargo#14817)
- feat(rustdoc): diplay env vars in extra verbose mode  (rust-lang/cargo#14812)
- Migrate build-rs to the Cargo repo (rust-lang/cargo#14786)
- chore(ci): Check for clippy `correctness` (rust-lang/cargo#14796)
- git: do not validate submodules of fresh checkouts (rust-lang/cargo#14605)
- refactor: clone-on-write when needed for InternedString (rust-lang/cargo#14808)
- fix(docs): typo in cargo-fmt.md (rust-lang/cargo#14805)
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 17, 2024
Update cargo

15 commits in 4a2d8dc636445b276288543882e076f254b3ae95..69e595908e2c420e7f0d1be34e6c5b984c8cfb84
2024-11-09 19:10:33 +0000 to 2024-11-16 01:26:11 +0000
- refactor(fingerprint): Track the intent for each use of `UnitHash` (rust-lang/cargo#14826)
- fix(toml): Update frontmatter parser for RFC 3503 (rust-lang/cargo#14792)
- docs(unstable): Move -Zwarnings from stable to unstable section (rust-lang/cargo#14827)
- Simplify English used in guide (rust-lang/cargo#14825)
- feat(resolver): Stabilize resolver v3 (rust-lang/cargo#14754)
- docs: Clean up doc comments (rust-lang/cargo#14823)
- fix(remove): On error, suggest other dependencies  (rust-lang/cargo#14818)
- Always include Cargo.lock in published crates (rust-lang/cargo#14815)
- fix(build-rs)!: Updates from an audit (rust-lang/cargo#14817)
- feat(rustdoc): diplay env vars in extra verbose mode  (rust-lang/cargo#14812)
- Migrate build-rs to the Cargo repo (rust-lang/cargo#14786)
- chore(ci): Check for clippy `correctness` (rust-lang/cargo#14796)
- git: do not validate submodules of fresh checkouts (rust-lang/cargo#14605)
- refactor: clone-on-write when needed for InternedString (rust-lang/cargo#14808)
- fix(docs): typo in cargo-fmt.md (rust-lang/cargo#14805)
@weihanglo weihanglo added this to the 1.84.0 milestone Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants