From b58a52901b842275f8f9b868065a7507f4f4daa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Misty=20De=20M=C3=A9o?= Date: Tue, 28 Nov 2023 09:35:52 -0800 Subject: [PATCH] feat: set CC/CXX in generic builds --- cargo-dist/src/generic_build.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/cargo-dist/src/generic_build.rs b/cargo-dist/src/generic_build.rs index 6473bccfa..a4814a416 100644 --- a/cargo-dist/src/generic_build.rs +++ b/cargo-dist/src/generic_build.rs @@ -48,6 +48,30 @@ impl<'a> DistGraphBuilder<'a> { } } +fn platform_appropriate_cc(target: &str) -> &str { + if target.contains("darwin") { + "clang" + } else if target.contains("linux") { + "gcc" + } else if target.contains("windows") { + "cl.exe" + } else { + "cc" + } +} + +fn platform_appropriate_cxx(target: &str) -> &str { + if target.contains("darwin") { + "clang++" + } else if target.contains("linux") { + "g++" + } else if target.contains("windows") { + "cl.exe" + } else { + "c++" + } +} + /// Build a generic target pub fn build_generic_target(dist_graph: &DistGraph, target: &GenericBuildStep) -> Result<()> { let mut command_string = target.build_command.clone(); @@ -89,6 +113,13 @@ pub fn build_generic_target(dist_graph: &DistGraph, target: &GenericBuildStep) - // it's building for. command.env("CARGO_DIST_TARGET", &target.target_triple); + let cc = + std::env::var("CC").unwrap_or(platform_appropriate_cc(&target.target_triple).to_owned()); + command.env("CC", cc); + let cxx = + std::env::var("CXX").unwrap_or(platform_appropriate_cxx(&target.target_triple).to_owned()); + command.env("CXX", cxx); + // Pass CFLAGS/LDFLAGS for C builds if let Some(cflags) = cflags { // These typically contain the same values as each other.