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

Passing arguments to underlying invocations of cargo #1170

Closed
artemagvanian opened this issue May 8, 2024 · 9 comments
Closed

Passing arguments to underlying invocations of cargo #1170

artemagvanian opened this issue May 8, 2024 · 9 comments

Comments

@artemagvanian
Copy link

I wonder if it is possible to run dylint lint pass with -Z build-std passed to all underlying cargo invocations. One of the lints I am writing depends on having standard library MIR accessible during the compilation. While it is possible to achieve this by configuring the crate on which the lint runs, it would be ideal to have this behavior out of the box for the end user.

@smoelius
Copy link
Collaborator

smoelius commented May 8, 2024

Might this work?

cargo dylint ... -- -Z build-std

The arguments after -- are forwarded to cargo check, which cargo dylint runs under the hood.

@artemagvanian
Copy link
Author

That worked! Thanks!

@artemagvanian
Copy link
Author

A follow-up on the previous question: is it possible to do the same thing with dylint_testing?

@smoelius
Copy link
Collaborator

smoelius commented May 8, 2024

Hmm. dylint_testing is a wrapper around compiletest-rs, which runs rustc directly. Furthermore, dylint_testing has a "test builder" that allows one to pass flags to rustc.

For example, here it used to pass the --test flag to rustc:

dylint_testing::ui::Test::src_base(
env!("CARGO_PKG_NAME"),
&Path::new(env!("CARGO_MANIFEST_DIR")).join("ui"),
)
.rustc_flags(["--test"])
.run();

So if one could figure out what flags Cargo passes to rustc when -Z build-std is enabled, one could pass them to rustc using a test builder.

At least, I think that should work.

@artemagvanian
Copy link
Author

Thanks again! Unfortunately, it was more complicated than just passing flags to rustc, so we ended up building a simple test harness that runs dylint directly and diffs the outputs.

@smoelius
Copy link
Collaborator

Thanks, I was curious to know how this went. Can I ask what more was required?

@artemagvanian
Copy link
Author

From what I could gather, it would require manually resolving std, setting up a fake workspace for it, and then linking it as an extern. If you are interested, this is the first PR for cargo build-std that briefly explains how they do it

@artemagvanian
Copy link
Author

On the other note, I opened this issue in compiletest, so maybe someone who knows more than me could give their opinion

@smoelius
Copy link
Collaborator

Thanks for the explanation. It is unfortunate that dylint_testing did not help here, but I am glad you were able to find a solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants