Skip to content

Commit

Permalink
book: Set driver link-arg in build.rs
Browse files Browse the repository at this point in the history
`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 <tcrawford@system76.com>
  • Loading branch information
crawfxrd committed Dec 17, 2024
1 parent 2aaa2fe commit ba305ce
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions book/src/how_to/building_drivers.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ba305ce

Please sign in to comment.