Skip to content

Commit

Permalink
Auto merge of #13884 - Urgau:check-cfg-local-build-scripts, r=epage
Browse files Browse the repository at this point in the history
Add local-only build scripts example in check-cfg docs

This PR adds an example about creating/having "local-only" build scripts in the check-cfg docs.

r? `@weihanglo`
cc `@epage`
  • Loading branch information
bors committed May 8, 2024
2 parents de88d8e + 3c809b2 commit 6914ead
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/doc/src/reference/build-scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,32 @@ if foo_bar_condition {
}
```

##### Example of local-only `build.rs`/build script

Build scripts can impose costs on downstream users, and crate authors who wish to avoid
this can use "local-only" build scripts, which are active locally but not packaged in the
distributed package. Completly removing the cost from downstream users.

The way to achieved this, is by excluding the `build.rs` in the `Cargo.toml` with the
`exclude` key:

```diff
[package]
name = "foo"
version = "0.1.0"
+ exclude = ["build.rs"]
```

*`build.rs`:*
```rust
fn main() {
// Warning: build.rs is not published to crates.io.

println!("cargo::rerun-if-changed=build.rs");
println!("cargo::rustc-check-cfg=cfg(foo)");
}
```

For a more complete example see in the [build script examples][build-script-examples] page
the [conditional compilation][conditional-compilation-example] example.

Expand Down

0 comments on commit 6914ead

Please sign in to comment.