Skip to content

Commit a92cdd3

Browse files
committed
Add instructions on how to use cargo's configuration file to setup sccache.
1 parent 347ff60 commit a92cdd3

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

README.md

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ We recommend you install Rust via [Rustup](https://rustup.rs/). The generated bi
4343
Build
4444
-----
4545

46-
> $ cargo build [--features=all|redis|s3|gcs] [--release]
46+
```text
47+
cargo build [--features=all|redis|s3|gcs] [--release]
48+
```
4749

4850
### Building portable binaries
4951

@@ -53,7 +55,7 @@ When building with the `gcs` feature, `sccache` will depend on OpenSSL, which ca
5355

5456
You will need to download and build OpenSSL with `-fPIC` in order to statically link against it.
5557

56-
```
58+
```bash
5759
./config -fPIC --prefix=/usr/local --openssldir=/usr/local/ssl
5860
make
5961
make install
@@ -68,7 +70,7 @@ Build with `cargo` and use `ldd` to check that the resulting binary does not dep
6870

6971
Just setting the below environment variable will enable static linking.
7072

71-
```
73+
```bash
7274
export OPENSSL_STATIC=yes
7375
```
7476

@@ -80,7 +82,7 @@ On Windows it is fairly straight forward to just ship the required `libcrypto` a
8082

8183
It is possible to statically link against the CRT using a `.cargo/config` file with the following contents.
8284

83-
```
85+
```toml
8486
[target.x86_64-pc-windows-msvc]
8587
rustflags = ["-Ctarget-feature=+crt-static"]
8688
```
@@ -105,13 +107,17 @@ set OPENSSL_LIBS=libcrypto64MT:libssl64MT
105107

106108
### With Rust
107109

108-
`$ cargo install sccache`
110+
```bash
111+
cargo install sccache
112+
```
109113

110114
### Windows
111115

112116
sccache can also be installed via [scoop](https://scoop.sh/)
113117

114-
`> scoop install sccache`
118+
```
119+
scoop install sccache
120+
```
115121

116122
---
117123

@@ -120,11 +126,24 @@ Usage
120126

121127
Running sccache is like running ccache: wrap your compilation commands with it, like so:
122128

123-
> $ sccache gcc -o foo.o -c foo.c
129+
```bash
130+
sccache gcc -o foo.o -c foo.c
131+
```
132+
133+
If you want to use sccache for your rust builds you can define `build.rustc-wrapper` in the
134+
[cargo configuration file](https://doc.rust-lang.org/cargo/reference/config.html). For example, you can set it globally
135+
in `$HOME/.cargo/config` by adding:
124136

125-
or use it with rust, like so:
137+
```toml
138+
[build]
139+
rustc-wrapper = "[path to sccache]"
140+
```
141+
142+
Alternatively you can use the environment variable `RUSTC_WRAPPER`:
126143

127-
> $ RUSTC_WRAPPER=[path to sccache] cargo build
144+
```text
145+
RUSTC_WRAPPER=[path to sccache] cargo build
146+
```
128147

129148
Sccache (tries to) support gcc, clang, [diab](https://www.windriver.com/products/development-tools/#diab_compiler) and MSVC. If you don't [specify otherwise](#storage-options), sccache will use a local disk cache.
130149

0 commit comments

Comments
 (0)