Skip to content

Commit 11399f9

Browse files
committed
Set link args in build script
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, and will only be read from the directory cargo was invoked from. 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/build-scripts.html Signed-off-by: Tim Crawford <[email protected]>
1 parent 46a8376 commit 11399f9

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

.cargo/config.toml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,2 @@
11
[build]
22
target = "x86_64-unknown-uefi"
3-
4-
[target.x86_64-unknown-uefi]
5-
rustflags = [
6-
"-Clink-arg=/heap:0,0",
7-
"-Clink-arg=/stack:0,0",
8-
"-Clink-arg=/dll",
9-
"-Clink-arg=/base:0",
10-
"-Clink-arg=/align:32",
11-
"-Clink-arg=/filealign:32",
12-
"-Clink-arg=/subsystem:efi_boot_service_driver"
13-
]

build.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// SPDX-License-Identifier: GPL-3.0-only
2+
3+
use std::env;
4+
5+
fn main() {
6+
println!("cargo::rerun-if-changed=build.rs");
7+
8+
let target = env::var("TARGET").unwrap();
9+
if target.ends_with("-unknown-uefi") {
10+
println!("cargo::rustc-link-arg=/heap:0,0");
11+
println!("cargo::rustc-link-arg=/stack:0,0");
12+
println!("cargo::rustc-link-arg=/dll");
13+
println!("cargo::rustc-link-arg=/base:0");
14+
println!("cargo::rustc-link-arg=/align:32");
15+
println!("cargo::rustc-link-arg=/filealign:32");
16+
println!("cargo::rustc-link-arg=/subsystem:efi_boot_service_driver");
17+
}
18+
}

0 commit comments

Comments
 (0)