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

cargo rustc --workspace/--exclude #8651

Closed
xd009642 opened this issue Aug 26, 2020 · 6 comments
Closed

cargo rustc --workspace/--exclude #8651

xd009642 opened this issue Aug 26, 2020 · 6 comments
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`

Comments

@xd009642
Copy link

So I'm working on tarpaulin, and I'm trying to solve an issue where linker flags of dependencies can conflict with the linker flags I need to set for code coverage, namely -C link-dead-code (conflict issue rust-lang/rust#64685). It should also keep the target directory smaller by not having dead code for all the dependencies included and prevent rebuilds when working with tarpaulin making things faster. So that's the motivation.

Now my idea to solve this is using cargo rustc to just pass the flags to the crate only. However if the user is using workspaces and has multiple packages in their project all the packages need link-dead-code applied not just the one under test. But I get the feeling from the docs that this isn't how cargo rustc works?

Providing cargo rustc works as I've grokked it, I was thinking that making the flags compatible with cargo build/test/etc and allowing it to operate on a whole workspace would be a solution.

Also, I'll need this to work with cargo test --bins/--examples/--doc/--lib/--benches/--tests with the compiled artefacts and anything in the project workspace linked with dead code. But that's just a side note in case I'm wrong and there's a better solution for doing this either with cargo rustc or a different cargo command

@xd009642 xd009642 added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label Aug 26, 2020
@ehuss
Copy link
Contributor

ehuss commented Aug 26, 2020

You are correct, cargo rustc only applies to the final artifact.

I would suggest looking at RUSTC_WORKSPACE_WRAPPER (see #8143), which is used for all workspace members. You could inject your own flags via that.

@xd009642
Copy link
Author

Oh cool, so that's available on stable as well? Or does the tracking issue mean it's not yet on stable rust?

@ehuss
Copy link
Contributor

ehuss commented Aug 26, 2020

It is not stable, it requires -Zunstable-options.

@xd009642
Copy link
Author

xd009642 commented Aug 26, 2020

So I'm part way through implementing this and I've got this as compiler output:

 -C link-dead-code --cfg=tarpaulin -C debuginfo=2  rustc --crate-name faktory ...

Is there a way to get the args to appear after rustc? I've had a perusal of the issue and associated PR and didn't spot anything.

In the meantime I'm going to keep looking and adjust it so it should create this monstrosity (which shouldn't work): this didn't work

rustc -C link-dead-code --cfg=tarpaulin -C debuginfo=2  --cfg=tarpaulin_rustc --crate-name faktory ...

I also tried RUSTC="rustc <ARGS>..." which didn't work. Also, considered getting a rustc build-plans and modding it, but they're being removed because of issues so that's a no. And of course looking for a postfix wrapper but I couldn't find mention of one

@ehuss
Copy link
Contributor

ehuss commented Aug 28, 2020

RUSTC_WORKSPACE_WRAPPER should point to an executable that replaces rustc. It is passed the path to rustc and all its arguments, and you can just append to the argument list, and execute rustc (the first argument). Here is where cargo clippy uses clippy-driver as a wrapper.

Thinking about it some more, I can see that might be awkward for your use case since you can't pass in arguments via the environment variable, so you would need a dedicated executable for that. I added a note to the tracking issue about that.

@ehuss
Copy link
Contributor

ehuss commented Sep 18, 2020

I'm going to close, as I think this seems to be mostly addressed by RUSTC_WORKSPACE_WRAPPER. Feel free to reopen if that is not the case, or if there is some feedback for that feature, please leave a comment on that tracking issue.

@ehuss ehuss closed this as completed Sep 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`
Projects
None yet
Development

No branches or pull requests

2 participants