Skip to content

Commit 3c809b2

Browse files
committed
Add local-only build scripts example in check-cfg docs
1 parent de88d8e commit 3c809b2

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/doc/src/reference/build-scripts.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,32 @@ if foo_bar_condition {
292292
}
293293
```
294294

295+
##### Example of local-only `build.rs`/build script
296+
297+
Build scripts can impose costs on downstream users, and crate authors who wish to avoid
298+
this can use "local-only" build scripts, which are active locally but not packaged in the
299+
distributed package. Completly removing the cost from downstream users.
300+
301+
The way to achieved this, is by excluding the `build.rs` in the `Cargo.toml` with the
302+
`exclude` key:
303+
304+
```diff
305+
[package]
306+
name = "foo"
307+
version = "0.1.0"
308+
+ exclude = ["build.rs"]
309+
```
310+
311+
*`build.rs`:*
312+
```rust
313+
fn main() {
314+
// Warning: build.rs is not published to crates.io.
315+
316+
println!("cargo::rerun-if-changed=build.rs");
317+
println!("cargo::rustc-check-cfg=cfg(foo)");
318+
}
319+
```
320+
295321
For a more complete example see in the [build script examples][build-script-examples] page
296322
the [conditional compilation][conditional-compilation-example] example.
297323

0 commit comments

Comments
 (0)