From 60ff795df77376378bf17397c9b4e519053a1d5a Mon Sep 17 00:00:00 2001 From: rmsyn Date: Sat, 4 May 2024 21:10:49 +0000 Subject: [PATCH] riscv: build: make `cfg` variables more robust Change which Cargo `CFG` environment variables are used to select the custom `cfg` variables. See https://github.com/rust-embedded/riscv/pull/204#issuecomment-2094089195 for discussion. --- riscv/build.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/riscv/build.rs b/riscv/build.rs index 30db72e7..25dcadff 100644 --- a/riscv/build.rs +++ b/riscv/build.rs @@ -1,12 +1,13 @@ use std::env; fn main() { - let target = env::var("TARGET").unwrap(); + let target = env::var("CARGO_CFG_TARGET_ARCH").unwrap(); + let ptr_width = env::var("CARGO_CFG_TARGET_POINTER_WIDTH").unwrap(); - if target.starts_with("riscv32") { + if target.contains("riscv") && ptr_width == "32" { println!("cargo:rustc-cfg=riscv"); println!("cargo:rustc-cfg=riscv32"); - } else if target.starts_with("riscv64") { + } else if target.contains("riscv") && ptr_width == "64" { println!("cargo:rustc-cfg=riscv"); println!("cargo:rustc-cfg=riscv64"); }