Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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