doc: Update build script examples to use build-rs#16592
doc: Update build script examples to use build-rs#16592hksama wants to merge 1 commit intorust-lang:masterfrom
Conversation
| " | ||
| ).unwrap(); | ||
| println!("cargo::rerun-if-changed=build.rs"); | ||
| build_rs::output::rerun_if_changed("build.rs"); |
There was a problem hiding this comment.
A couple lines above OUT_DIR is read and could instead use out_dir()
| edition = "2024" | ||
|
|
||
| [build-dependencies] | ||
| build-rs= "0.3.0" |
There was a problem hiding this comment.
| build-rs= "0.3.0" | |
| build-rs = "0.3.0" |
| edition = "2024" | ||
|
|
||
| [build-dependencies] | ||
| build-rs= "0.3.0" |
There was a problem hiding this comment.
With this being in the docs, how are we going to keep it up-to-date?
| println!("cargo::rustc-link-search=native={}", out_dir); | ||
| println!("cargo::rustc-link-lib=static=hello"); | ||
| println!("cargo::rerun-if-changed=src/hello.c"); | ||
| build_rs::output::rustc_link_search(out_dir); |
There was a problem hiding this comment.
Shouldn't this be rustc_link_search_kind?
| ```toml | ||
| [build-dependencies] | ||
| cc = "1.0" | ||
| build-rs= "0.3.0" |
There was a problem hiding this comment.
| build-rs= "0.3.0" | |
| build-rs = "0.3.0" |
| println!("cargo::rustc-link-search=native={}", out_dir); | ||
| println!("cargo::rustc-link-lib=static=hello"); | ||
| println!("cargo::rerun-if-changed=src/hello.c"); | ||
| build_rs::output::rustc_link_search(out_dir); |
| } | ||
| cfg.compile("z_user"); | ||
| println!("cargo::rerun-if-changed=src/z_user.c"); | ||
| build_rs::output::rerun_if_changed("src/z_user.c"); |
There was a problem hiding this comment.
Shouldn't we use dep_metadata for DEP_Z_INCLUDE?
| build_rs::output::rustc_check_cfgs(&["ossl101","ossl102",]); | ||
| build_rs::output::rustc_check_cfgs(&["ossl110","ossl110g","ossl111",]); |
There was a problem hiding this comment.
Please clean up the code style
| For historical reasons, the `cargo::rustc-cdylib-link-arg` form is an alias | ||
| for `cargo::rustc-link-arg-cdylib`, and has the same meaning. | ||
|
|
||
| **Recommended:** Use [`build_rs::output::rustc_cdylib_link_arg`](https://docs.rs/build-rs/0.3.3/build_rs/output/fn.rustc_cdylib_link_arg.html) from the `build-rs` crate. |
There was a problem hiding this comment.
We don't need to recommend this under every entry
| > **Note** | ||
| > Build scripts communicate with Cargo by printing specially formatted lines to stdout. | ||
| > While you can print these lines manually (e.g., `println!("cargo::rerun-if-changed=build.rs")`), | ||
| > we recommend using the [`build-rs`](https://crates.io/crates/build-rs) crate. | ||
| > It provides a type-safe API that ensures your build instructions are formatted correctly. | ||
| > | ||
| > The examples in this reference guide use `build-rs` to demonstrate best practices, | ||
| > while the section headers preserve the raw protocol strings for specification purposes. |
There was a problem hiding this comment.
This is partly covered under " Life Cycle of a Build Script". Seems like adding a note about build-rs being an API for this to that would be cleaner
| fn main() { | ||
| // Tell Cargo that if the given file changes, to rerun this build script. | ||
| println!("cargo::rerun-if-changed=src/hello.c"); | ||
| //recommended method(using the build_rs crate) |
There was a problem hiding this comment.
This comment doesn't quite read correctly to me
Title: doc: Update build script examples to use build-rs
Description:
Updates the build script documentation to recommend the build-rs crate, as discussed in #15567.
Changes
Added a Note recommending build-rs for type safety in build-scripts.md.
Updated examples in build-script-examples.md to use build_rs::output::... functions instead of raw println! macros.
Preserved raw protocol strings in section headers for specification reference.
Relates to #15567.
Ready for FCP review.