From 384aec788a0c39a334e4c81b4e224b99dd59e394 Mon Sep 17 00:00:00 2001 From: Tim Crawford Date: Sun, 15 Dec 2024 16:35:51 -0700 Subject: [PATCH] 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. 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 --- .cargo/config.toml | 11 ----------- build.rs | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 11 deletions(-) create mode 100644 build.rs diff --git a/.cargo/config.toml b/.cargo/config.toml index 8b6e8d5..85d49dc 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -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" -] diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..6077d90 --- /dev/null +++ b/build.rs @@ -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"); + } +}