-
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 support for wrapping cargo's rustc invocations by setting RUSTC_WRAPPER #3887
Conversation
r? @brson (rust_highfive has picked a reviewer for you, use r? to override) |
A Travis build failed because I have a line that's >100 characters. I fixed it locally, I'll push it after I get review since there will assuredly be other changes to make. |
Seems related to #3815. Why doesn't existing |
@matklad oh the use case here I think is a little different than #3815 where most cargo developers won't use #3815 day-to-day, but many may use sccache day-to-day (once it's working well w/ rust code). Unfortunately I do believe, though, that |
I think this solution may be specific to sscache, because it fixes particular command line format (i.e. Some alternatives (I don't think any of them is better than this PR)
I think you can specify |
The problem here is that you then have no way to also tell cargo to use a specific rustc except for munging As it stands this is definitely a sccache-specific option right now. However, I've seen lots of tools over the years that wrap C++ compiler invocations in a similar manner (ccache and distcc are the first two that come to mind), so I wouldn't be surprised to see someone find another interesting use case here.
I would disagree with this, as this would not work if you set |
I didn't think of that, thanks! Looks great to me both implementation- and API-wise! |
I fixed the overly-long line and added a test that uses |
☔ The latest upstream changes (presumably #3898) made this pull request unmergeable. Please resolve the merge conflicts. |
Can this be merged? |
☔ The latest upstream changes (presumably #3930) made this pull request unmergeable. Please resolve the merge conflicts. |
📌 Commit 20f23d9 has been approved by |
Add support for wrapping cargo's rustc invocations by setting RUSTC_WRAPPER To use sccache for cargo builds we need a simple way to get sccache into the rustc commandline when cargo invokes rustc. Currently this is only possible by hard-linking or copying the `sccache` binary to be named `rustc` and then either setting `RUSTC` to its path or putting it first in `$PATH`, both of which are sort of clunky and require manual steps even if installing sccache via `cargo install`. This patch adds support for a `RUSTC_WRAPPER` environment variable which, if set, will simply be inserted as the actual binary for all rustc process execution, with rustc and all other rustc arguments following. I didn't add any tests for this, I couldn't figure out the right place to put them, and presumably we'd need to build a helper binary of some sort to use as the wrapper. If you've got suggestions for how to do that properly I'd be happy to write tests. This works well in my local testing: ``` luser@eye7:/build/read-process-memory$ /build/cargo/target/release/cargo clean; time RUSTC_WRAPPER=/build/sccache2/target/release/sccache RUSTC=/home/luser/.rustup/toolchains/beta-x86_64-unknown-linux-gnu/bin/rustc /build/cargo/target/release/cargo build Compiling getopts v0.2.14 Compiling log v0.3.6 Compiling libc v0.2.16 Compiling rand v0.3.14 Compiling pulldown-cmark v0.0.3 Compiling tempdir v0.3.5 Compiling skeptic v0.5.0 Compiling read-process-memory v0.1.2-pre (file:///build/read-process-memory) Finished dev [unoptimized + debuginfo] target(s) in 7.31 secs real 0m7.733s user 0m0.060s sys 0m0.036s luser@eye7:/build/read-process-memory$ /build/cargo/target/release/cargo clean; time RUSTC_WRAPPER=/build/sccache2/target/release/sccache RUSTC=/home/luser/.rustup/toolchains/beta-x86_64-unknown-linux-gnu/bin/rustc /build/cargo/target/release/cargo build Compiling getopts v0.2.14 Compiling libc v0.2.16 Compiling log v0.3.6 Compiling pulldown-cmark v0.0.3 Compiling rand v0.3.14 Compiling tempdir v0.3.5 Compiling skeptic v0.5.0 Compiling read-process-memory v0.1.2-pre (file:///build/read-process-memory) Finished dev [unoptimized + debuginfo] target(s) in 0.97 secs real 0m1.049s user 0m0.060s sys 0m0.036s ``` The use of beta rustc is just to pick up the fix for making `--emit=dep-info` faster (which should ship in 1.17). If this patch ships in cargo then in the future developers should simply be able to `cargo install sccache; export RUSTC_WRAPPER=sccache` and `cargo build` as normal, but benefit from local sccache caching.
☀️ Test successful - status-appveyor, status-travis |
Why not just have Cargo check if |
We were not sure how well it would actually work in practice! Also enabling caching might make some people uneasy. |
To use sccache for cargo builds we need a simple way to get sccache into the rustc commandline when cargo invokes rustc. Currently this is only possible by hard-linking or copying the
sccache
binary to be namedrustc
and then either settingRUSTC
to its path or putting it first in$PATH
, both of which are sort of clunky and require manual steps even if installing sccache viacargo install
.This patch adds support for a
RUSTC_WRAPPER
environment variable which, if set, will simply be inserted as the actual binary for all rustc process execution, with rustc and all other rustc arguments following.I didn't add any tests for this, I couldn't figure out the right place to put them, and presumably we'd need to build a helper binary of some sort to use as the wrapper. If you've got suggestions for how to do that properly I'd be happy to write tests.
This works well in my local testing:
The use of beta rustc is just to pick up the fix for making
--emit=dep-info
faster (which should ship in 1.17). If this patch ships in cargo then in the future developers should simply be able tocargo install sccache; export RUSTC_WRAPPER=sccache
andcargo build
as normal, but benefit from local sccache caching.