From 8e86632722062031c3224f37527f10aea37c0ba2 Mon Sep 17 00:00:00 2001 From: "Jonathan D.K. Gibbons" Date: Tue, 9 Aug 2022 13:13:45 -0400 Subject: [PATCH] Tweak build for nix-provided toolchain also Prebuilt toolchain from ARM is still supported. --- build.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/build.rs b/build.rs index d724521a..80fa15c2 100644 --- a/build.rs +++ b/build.rs @@ -133,18 +133,25 @@ fn main() -> Result<(), Box> { let output = Command::new("arm-none-eabi-gcc") .arg("-print-sysroot") - .output() - .expect("failed"); + .output().ok(); + let sysroot = output + .as_ref().and_then(|o|std::str::from_utf8(&o.stdout).ok()) + .unwrap_or("").trim(); - let sysroot = std::str::from_utf8(&output.stdout).unwrap().trim(); let gcc_toolchain = if sysroot.is_empty() { String::from("/usr/include/") } else { format!("{sysroot}/include") }; - let mut command = cc::Build::new() - .compiler("clang") + let mut command = cc::Build::new(); + if env::var_os("CC").is_none() { + command.compiler("clang"); + } else { + // Let cc::Build determine CC from the environment variable + } + + command .file("./src/c/src.c") .file("./src/c/sjlj.s") .file(format!("{bolos_sdk}/src/os_io_usb.c")) @@ -197,8 +204,7 @@ fn main() -> Result<(), Box> { .flag("-fno-jump-tables") .flag("-fshort-enums") .flag("-mno-unaligned-access") - .flag("-Wno-unused-command-line-argument") - .clone(); + .flag("-Wno-unused-command-line-argument"); #[cfg(feature = "ccid")] {