Skip to content

Commit

Permalink
Set link args in build script
Browse files Browse the repository at this point in the history
While working on converting our UEFI images to a workspace I found that
the cargo configuration file cannot be used. `config.toml` is a
*project*-level configuration. It will only be read from the current
directory and up, and not in:

- package directories in a workspace
- package directory 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.

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 <[email protected]>
  • Loading branch information
crawfxrd committed Dec 19, 2024
1 parent 46a8376 commit 67d63a7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
11 changes: 0 additions & 11 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,2 @@
[build]
target = "x86_64-unknown-uefi"

[target.x86_64-unknown-uefi]
rustflags = [
"-Clink-arg=/heap:0,0",
"-Clink-arg=/stack:0,0",
"-Clink-arg=/dll",
"-Clink-arg=/base:0",
"-Clink-arg=/align:32",
"-Clink-arg=/filealign:32",
"-Clink-arg=/subsystem:efi_boot_service_driver"
]
16 changes: 16 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// SPDX-License-Identifier: GPL-3.0-only

use std::env;

fn main() {
let target = env::var("TARGET").unwrap();
if target.ends_with("-unknown-uefi") {
println!("cargo::rustc-link-arg=/heap:0,0");
println!("cargo::rustc-link-arg=/stack:0,0");
println!("cargo::rustc-link-arg=/dll");
println!("cargo::rustc-link-arg=/base:0");
println!("cargo::rustc-link-arg=/align:32");
println!("cargo::rustc-link-arg=/filealign:32");
println!("cargo::rustc-link-arg=/subsystem:efi_boot_service_driver");
}
}

0 comments on commit 67d63a7

Please sign in to comment.