From ba305cef9fbb37b2428f650a821f1e8e18f2aca0 Mon Sep 17 00:00:00 2001 From: Tim Crawford Date: Mon, 16 Dec 2024 18:31:48 -0700 Subject: [PATCH] book: Set driver link-arg in `build.rs` `config.toml` is a project-level configuration. Cargo will only read the configuration from the current directory and up, and not in: - package directories in a workspace - package directories when `--manifest-path` is used Use `build.rs` instead, which will be executed before the package is built and only apply the flags for the specific package. This allows mixing drivers and applications in a workspace while still invoking Cargo from the workspace root. Ref: https://doc.rust-lang.org/cargo/reference/config.html#hierarchical-structure Ref: https://doc.rust-lang.org/cargo/reference/build-scripts.html Signed-off-by: Tim Crawford --- book/src/how_to/building_drivers.md | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/book/src/how_to/building_drivers.md b/book/src/how_to/building_drivers.md index 4d783f8aa..b0a2c55e6 100644 --- a/book/src/how_to/building_drivers.md +++ b/book/src/how_to/building_drivers.md @@ -11,10 +11,17 @@ value to `efi_boot_service_driver` or `efi_runtime_driver`. Example: -```toml -# In .cargo/config.toml: -[build] -rustflags = ["-C", "link-args=/subsystem:efi_runtime_driver"] +```rust +// In build.rs + +fn main() { + println!("cargo::rerun-if-changed=build.rs"); + + let target = std::env::var("TARGET").unwrap(); + if target.ends_with("-unknown-uefi") { + println!("cargo::rustc-link-arg=/subsystem:efi_runtime_driver"); + } +} ``` [spec-images]: https://uefi.org/specs/UEFI/2.10/02_Overview.html#uefi-images