-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Add some validation to rustc-link-arg #9523
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great to me!
if !targets.iter().any(|target| target.is_bin()) { | ||
bail!( | ||
"invalid instruction `cargo:{}` from {}\n\ | ||
The package {} does not have a bin target.", | ||
key, | ||
whence, | ||
pkg_descr | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we extract the same logic from these three bail!
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about that, but I didn't see a way to consolidate it such that it wouldn't end up with more total lines of code. Only the first two have the same structure. The third has a different structure and text, which would need customization.
Thanks for the suggestion, I do agree it is a bit repetitive and verbose. Hopefully RFC 2795 will make progress, which I think would simplify this a bit.
If there are more link-types added in the future, perhaps might spend some more effort to consolidate it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. Thank for your detailed explanation!
BTW, RFC 2795 looks really promising 😲
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! I'll leave it up to you how you'd like to refactor as mentioned.
@bors r=alexcrichton |
📌 Commit 836e537 has been approved by |
☀️ Test successful - checks-actions |
Update cargo 10 commits in e931e4796b61de593aa1097649445e535c9c7ee0..0cecbd67323ca14a7eb6505900d0d7307b00355b 2021-05-24 16:17:27 +0000 to 2021-06-01 20:09:13 +0000 - Configure hosts separately from targets when --target is specified. (rust-lang/cargo#9322) - Add some validation to rustc-link-arg (rust-lang/cargo#9523) - Implement suggestions for unknown features in workspace (rust-lang/cargo#9420) - Extract common `make_dep_path` to cargo_util (rust-lang/cargo#9529) - Add a note about rustflags compatibility. (rust-lang/cargo#9524) - Consolidate doc collision detection. (rust-lang/cargo#9526) - Add `--depth` option for `cargo-tree` (rust-lang/cargo#9499) - `cargo tree -e no-proc-macro` to hide procedural macro dependencies (rust-lang/cargo#9488) - Update to semver 1.0.0 (rust-lang/cargo#9508) - Update tar dependency to 0.4.35 (rust-lang/cargo#9517)
Change `rustc-cdylib-link-arg` error to a warning. In #9523, an error was added if `cargo:rustc-cdylib-link-arg` was issued in a build script without actually having a cdylib target. This uncovered that there was an unintentional change in #8441 to cause those link args to be applied to transitive dependencies. This changes it so that the error is now a warning, with a note that this may become an error in the future. It also changes it so that the unstable `rustc-link-arg*` instructions only apply to the package that emitted them.
Change `rustc-cdylib-link-arg` error to a warning. In rust-lang#9523, an error was added if `cargo:rustc-cdylib-link-arg` was issued in a build script without actually having a cdylib target. This uncovered that there was an unintentional change in rust-lang#8441 to cause those link args to be applied to transitive dependencies. This changes it so that the error is now a warning, with a note that this may become an error in the future. It also changes it so that the unstable `rustc-link-arg*` instructions only apply to the package that emitted them.
Beta 1.54 backports This backports the following changes to 1.54 beta: * #9595 — Relax doc collision error. This was an unintended regression where a warning was switched to an error in 1.54. * #9563 — Change rustc-cdylib-link-arg error to a warning. Validation was added in #9523 (1.54) that generated an error. However, it was unknown at the time that use of link args via dependencies was being used. Rather than regress those projects (which has been on stable since 1.50), this switches the validation to a warning to indicate this was not intended. * #9604 — Disambiguate is_symlink. Required to get CI to pass.
This adds some validation, so that if a
cargo:rustc-link-arg-*
build script instruction specifies a target that doesn't exist, it will generate an error. This also changes a parse warning to an error if the=
is missing from BIN=ARG.I intentionally did not bother to add the validation to config overrides, as it is a bit trickier to do, and that feature is very rarely used (AFAIK), and I'm uncertain if rustc-link-arg is really useful in that context.
cc #9426