use cargo rustc for macro expansion so -Zbuild-std can be supported#5214
use cargo rustc for macro expansion so -Zbuild-std can be supported#5214skrap wants to merge 3 commits into
cargo rustc for macro expansion so -Zbuild-std can be supported#5214Conversation
0689c20 to
b5da051
Compare
|
Cc @mbyx for ctest |
b5da051 to
1100563
Compare
| .arg("--edition") | ||
| .arg(EDITION) // By default, -Zunpretty=expanded uses 2015 edition. | ||
| .arg(canonicalize(crate_path)?); | ||
| .env("RUSTFLAGS", "") // ignore RUSTFLAGS so we don't get -Dwarnings |
There was a problem hiding this comment.
Add a TestGenerator::expansion_rustflags(&str) and set RUSTFLAGS only if that has been called, otherwise just let it inherit. Since there might be some global options needed to build.
There was a problem hiding this comment.
We were not building with inherited RUSTFLAGS before this change, as RUSTFLAGS are a cargo-ism, and we were not using cargo before, but rather using rustc directly.
I think I will be a bit more tactical and just add a -Awarnings at the end of RUSTFLAGS so we don't error out over warnings if -Dwarnings is present. No new API required, and should be compatible with existing clients.
There was a problem hiding this comment.
Fair point about compatibility! We probably shouldn't suppress warnings though, there could be some papercuts.
I think it might be best to leave exact env up to the user, since sometimes build scripts pick up other env that you may want to control. So perhaps:
impl TestGenerator {
fn expansion_env(&mut self, k: impl AsRef<OsStr>, v: impl AsRef<OsStr>) -> &mut Self;
fn expansion_env_clear(&mut self) -> &mut Self;
}Then call cmd.env_clear().env(expansion_env) on the Command.
There was a problem hiding this comment.
But to what end? This is adding API surface which no crate user has asked for, and it might or might not be the correct thing. The previous code would emit warnings into /dev/null and then move on, and I think we should retain that behavior until some motivated person comes along to ask for it to change.
I would prefer we stick to the goal of this PR which is to enable tier 3 folks like me to build libc, and this API is beyond that goal.
There was a problem hiding this comment.
If just calling .env_clear() works then I'm fine with that and no new API. But I don't want to hardcode any RUSTFLAGS - if those need to be adjusted then we should go with the suggested API.
We should give users a chance to catch anything warnings that happen during expansion in case it's due to the config they're providing. Macro expansion can be env-dependent as well.
|
Reminder, once the PR becomes ready for a review, use |
bef315b to
af836b6
Compare
This comment has been minimized.
This comment has been minimized.
|
@rustbot review I think I have addressed the feedback, though in exploring the changes I sometimes made some different choices. I've left comments in the conversations where appropriate. |
2ef0daf to
3294988
Compare
| /// Configures any extra arguments which to be passed to cargo | ||
| /// during macro expansion. This can be used, for example, to pass | ||
| /// -Zbuild-std if required. | ||
| pub fn set_macro_expansion_cargo_args(&mut self, args: Vec<String>) { | ||
| self.macro_expansion_cargo_args = args; | ||
| } |
There was a problem hiding this comment.
To keep things a bit more composable so you can set args one at a time, replace this with fn expansion_cargo_arg(&mut self, &str) and fn clear_expansion_cargo_args(&mut self).
Also these methods should return &mut Self
There was a problem hiding this comment.
Curious why we would need a clear(). Why would a crate user add arguments only to remove them? Again I find myself concerned about increasing the API surface without a clear use case.
There was a problem hiding this comment.
Any kind of pattern that sets defaults then clears them, so you can just use store the args in the TestGenerator rather than tracking them separately. Not likely to be used a lot: it's just the sort of thing that's pretty easy to add now, but more likely to be worked around than added in the future.
Rather than clear, something like expansion_cargo_args_mut(&mut self) -> &mut Vec<String> would be fine too for more flexibility.
| .arg("--edition") | ||
| .arg(EDITION) // By default, -Zunpretty=expanded uses 2015 edition. | ||
| .arg(canonicalize(crate_path)?); | ||
| .env("RUSTFLAGS", "") // ignore RUSTFLAGS so we don't get -Dwarnings |
There was a problem hiding this comment.
Fair point about compatibility! We probably shouldn't suppress warnings though, there could be some papercuts.
I think it might be best to leave exact env up to the user, since sometimes build scripts pick up other env that you may want to control. So perhaps:
impl TestGenerator {
fn expansion_env(&mut self, k: impl AsRef<OsStr>, v: impl AsRef<OsStr>) -> &mut Self;
fn expansion_env_clear(&mut self) -> &mut Self;
}Then call cmd.env_clear().env(expansion_env) on the Command.
3294988 to
9dd5dd1
Compare
This comment has been minimized.
This comment has been minimized.
9dd5dd1 to
ba0cdaa
Compare
ba0cdaa to
f752fb9
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
@rustbot review Further review feedback. I'm a bit shy about adding more API than necessary for the stated purpose of the PR. If we have a clear use case for the API proposed, I think that should be proposed in a separate PR. |
| /// Configures the crate name which should be used during macro expansion. | ||
| /// If the tested crate uses `#![crate_name = "..."]`, this must be called with the | ||
| /// same name. Otherwise, there will be an error about `--crate-name` not | ||
| /// matching. |
There was a problem hiding this comment.
| /// Configures the crate name which should be used during macro expansion. | |
| /// If the tested crate uses `#![crate_name = "..."]`, this must be called with the | |
| /// same name. Otherwise, there will be an error about `--crate-name` not | |
| /// matching. | |
| /// Configures the crate name which should be used during macro expansion. | |
| /// | |
| /// If the tested crate uses `#![crate_name = "..."]`, this must be called with the | |
| /// same name. Otherwise, there will be an error about `--crate-name` not | |
| /// matching. |
so rustdoc doesn't mush into the summary
| /// Configures any extra arguments which to be passed to cargo | ||
| /// during macro expansion. This can be used, for example, to pass | ||
| /// -Zbuild-std if required. | ||
| pub fn set_macro_expansion_cargo_args(&mut self, args: Vec<String>) { | ||
| self.macro_expansion_cargo_args = args; | ||
| } |
There was a problem hiding this comment.
Any kind of pattern that sets defaults then clears them, so you can just use store the args in the TestGenerator rather than tracking them separately. Not likely to be used a lot: it's just the sort of thing that's pretty easy to add now, but more likely to be worked around than added in the future.
Rather than clear, something like expansion_cargo_args_mut(&mut self) -> &mut Vec<String> would be fine too for more flexibility.
| .arg("--edition") | ||
| .arg(EDITION) // By default, -Zunpretty=expanded uses 2015 edition. | ||
| .arg(canonicalize(crate_path)?); | ||
| .env("RUSTFLAGS", "") // ignore RUSTFLAGS so we don't get -Dwarnings |
There was a problem hiding this comment.
If just calling .env_clear() works then I'm fine with that and no new API. But I don't want to hardcode any RUSTFLAGS - if those need to be adjusted then we should go with the suggested API.
We should give users a chance to catch anything warnings that happen during expansion in case it's due to the config they're providing. Macro expansion can be env-dependent as well.
There was a problem hiding this comment.
Just updating the status here.
Also, regarding the general concern about API surface area: don't worry about it :) as long as it's somewhat sane, for ctest I tend to err on the side of adding small things we might need while related code is already being modified, rather than leaving a gap that might need ctest-specific changes in the future. There might be somebody who appreciates it even if libc doesn't have an immediate use.
Description
Address #5204 by invoking macro expansion through
cargo rustcinstead of rustc directly. This allows the use of the-Zbuild-stdflag, enabling targets without a prebuilt std (e.g. tier 3 targets) to build the libc tests.Checklist
libc-test/semverhave been updated*LASTor*MAXareincluded (see #3131)
cd libc-test && cargo test --target mytarget);especially relevant for platforms that may not be checked in CI