-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Rework rmake support library API #122460
Rework rmake support library API #122460
Conversation
a6f4f6a
to
4acb17e
Compare
.input_file("b.rs") | ||
.enable_unstable_options() | ||
.codegen_opt(PreferDynamic) | ||
.codegen_opt(SymbolManglingVersion(SymbolManglingVersion::Legacy)) |
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'm not sure whether this really is better than what we had before (with merging the two like -Cprefer-dynamic
into one line, which could be asserted by arg panicking when it sees -Z or -C).
downsides: it's more verbose and requires hardcoding the command line interface in the support library
upsides: 🤷 you get compile time instead of runtime checks?
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.
Don't really have a super strong opinion for the support library API atm, still experimenting shrug
It does hardcode the cli interface into the support library. But if the cli interface changes, then surely the tests affected will have to change with it anyway?
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.
Also I can omit the codegen_opt layer and just provide e.g. prefer_dynamic()
/ lto(LtoKind::Fat)
directly.
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 think arg is still simpler, easier to maintain and more obvious to understand
.arg("symbol-mangling-version=legacy") | ||
Rustc::new() | ||
.input_file("a.rs") | ||
.cfg("x") |
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 do like this helper, it makes the test shorter
Before: to write test you needed only to write almost as if bash command lines. Maybe something like https://docs.rs/xshell/latest/xshell/ ? Used in r-a and looks cute. |
Oh, I see you really went for it full steam ahead 😆 This approach is of course highly bike-sheddable and I'm sure that it will have both fans and people who don't like it. Now that I look at it, I have to agree with Nilstrieb here that perhaps the strongly typed wrappers are too much, and they make it unnecessarily opaque to the reader - who probably knows the CLI flag, but might not know the wrapper. It's true that with the wrapper we can easily search for all usages of that flag in the run-make tests, but if you want to grep e.g. for all usages of On the other hand, I would keep some of the high-level helpers for things that are super common, but not very interesting and are "almost always boilerpate", for example the output |
i agree that common things like -o deserve helpers, especially (or maybe rather only) if they make the code shorter/simpler. |
I'm not sure why I thought it was a problem when I did the run-make infra PR initially, when I could've just re-exported xshell. Now that I did write the super strongly-typed API, I think the shell version is just easier to read lol extern run_make_support;
use run_make_support::anyhow;
use run_make_support::xshell::{Shell, cmd};
fn main() -> anyhow::Result<()> {
let sh = Shell::new()?;
let _blah = cmd!(sh, "rustc a.rs -Zunpretty=hir").read()?;
} Maybe just go with the shell version after all? I want to get the API bikeshedding done before other tests are ported over :3 |
That approach could make it simpler to port the existing tests. I would still keep some "context object", on which we can either call In test DSLs, I often appreciate how I can do asserts on the return value of something, e.g. let res = Command::new().set_arg(foo).run().assert_ok();
assert_eq!(res.get_output("bar"), "baz"); But I'm not actually sure if we need that in runmake tests, since we usually just invoke the compiler and then check the filesystem. One thing that could be annoying with the shell approach is setting default values. E.g., we might want to set |
So the xshell version for a-b-a-linker-guard looks something like: fn main() -> anyhow::Result<()> {
let sh = Shell::new()?;
let rustc = rustc();
let out_dir = out_dir();
cmd!(
sh,
"{rustc} a.rs --out-dir={out_dir} -L {out_dir} --cfg x -C prefer-dynamic \
-Z unstable-options -C symbol-mangling-version=legacy"
)
.run()?;
cmd!(
sh,
"{rustc} b.rs --out-dir={out_dir} -L {out_dir} -C prefer-dynamic -Z unstable-options \
-C symbol-mangling-version=legacy"
)
.run()?;
run("b");
cmd!(
sh,
"{rustc} a.rs --out-dir={out_dir} -L {out_dir} --cfg y -C prefer-dynamic \
-Z unstable-options -C symbol-mangling-version=legacy"
)
.run()?;
run_fail("b");
} |
Now that I see how this version looks like... I think I personally prefer the typed API version, but with only a selected few helper methods (and not full-blown typed API) like Nils suggested. That way, we can still have presets (like |
With the typed-but-not-too-strongly API: fn main() {
Rustc::new()
.input("a.rs")
.cfg("x")
.arg("-Zunstable-options")
.arg("-Cprefer-dynamic")
.arg("-Csymbol-mangling-version=legacy")
.run();
Rustc::new()
.input("b.rs")
.arg("-Zunstable-options")
.arg("-Cprefer-dynamic")
.arg("-Csymbol-mangling-version=legacy")
.run();
run("b");
Rustc::new()
.input("a.rs")
.cfg("y")
.arg("-Zunstable-options")
.arg("-Cprefer-dynamic")
.arg("-Csymbol-mangling-version=legacy")
.run();
run_fail("b");
} |
That looks like a good compromise to me. |
@rustbot ready wait... |
use std::collections::HashMap; | ||
|
||
fn main() { | ||
if std::env::var("TARGET").unwrap() != "wasm32-wasip1" { | ||
return; | ||
} | ||
|
||
rustc().arg("foo.rs").arg("--target=wasm32-wasip1").run(); | ||
rustc().arg("bar.rs").arg("--target=wasm32-wasip1").arg("-Clto").arg("-O").run(); | ||
Rustc::new().input("foo.rs").target("wasm32-wasip1").run(); |
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.
Why rustc()
->Rustc::new()
?
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.
Previously rustc()
just called RustcInvocationBuilder::new()
(which is now Rustc
), it felt like an really unnecessary wrapper
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 think it looks nicer
I'm going to approve this, we can always change it later. |
…kingjubilee Rollup of 13 pull requests Successful merges: - rust-lang#121281 (regression test for rust-lang#103626) - rust-lang#121940 (Mention Register Size in `#[warn(asm_sub_register)]`) - rust-lang#122217 (Handle str literals written with `'` lexed as lifetime) - rust-lang#122379 (transmute: caution against int2ptr transmutation) - rust-lang#122460 (Rework rmake support library API) - rust-lang#122797 (Fix compile of wasm64-unknown-unknown target) - rust-lang#122875 (CFI: Support self_cell-like recursion) - rust-lang#122879 (CFI: Strip auto traits off Virtual calls) - rust-lang#122895 (add some ice tests 5xxxx to 9xxxx) - rust-lang#122907 (Uniquify `ReError` on input mode in canonicalizer) - rust-lang#122923 (In `pretty_print_type()`, print `async fn` futures' paths instead of spans.) - rust-lang#122942 (Add test in higher ranked subtype) - rust-lang#122963 (core/panicking: fix outdated comment) r? `@ghost` `@rustbot` modify labels: rollup
…=Nilstrieb Rework rmake support library API ### Take 1: Strongly-typed API Context: rust-lang#122448 (comment) > My 2 cents: from my experience with writing similar "test DSLs", I would suggest to create these helpers as soon as possible in the process (basically the first time someone needs them, not only after N similar usages), and basically treat any imperative code in these high-level tests as a maintenance burden, basically making them as declarative as possible. Otherwise it might be a bit annoying to keep refactoring the tests later once such helpers are available. > > I would even discourage the arg method and create explicit methods for setting things like unpretty, the output file etc., but this might be more controversial, as it will make the invoked command-line arguments more opaque. cc ``@Kobzol`` for the testing DSL suggestion. Example: ```rs let output = Rustc::new() .input_file("main.rs") .emit(&[EmitKind::Metadata]) .extern_("stable", &stable_path) .output(); ``` ### Take 2: xshell-based macro API Example: ```rs let sh = Shell::new()?; let stable_path = stable_path.to_string_lossy(); let output = cmd!(sh, "rustc main.rs --emit=metadata --extern stable={stable_path}").output()?; ``` ### Take 3: Weakly-typed API with a few helper methods ```rs let output = Rustc::new() .input("main.rs") .emit("metadata") .extern_("stable", &stable_path) .output(); ```
🔒 Merge conflict This pull request and the master branch diverged in a way that cannot be automatically merged. Please rebase on top of the latest master branch, and let the reviewer approve again. How do I rebase?Assuming
You may also read Git Rebasing to Resolve Conflicts by Drew Blessing for a short tutorial. Please avoid the "Resolve conflicts" button on GitHub. It uses Sometimes step 4 will complete without asking for resolution. This is usually due to difference between how Error message
|
☔ The latest upstream changes (presumably #122966) made this pull request unmergeable. Please resolve the merge conflicts. |
4e8753b
to
1f2178b
Compare
Changes since last reviewed:
@rustbot ready |
@bors r+ |
☀️ Test successful - checks-actions |
Finished benchmarking commit (0157da4): comparison URL. Overall result: ❌ regressions - ACTION NEEDEDNext Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 670.379s -> 671.34s (0.14%) |
This only modified tests, so the result is noise. @rustbot label: +perf-regression-triaged |
Take 1: Strongly-typed API
Context: #122448 (comment)
cc @Kobzol for the testing DSL suggestion.
Example:
Take 2: xshell-based macro API
Example:
Take 3: Weakly-typed API with a few helper methods