Skip to content

Commit

Permalink
feat: set CC/CXX in generic builds
Browse files Browse the repository at this point in the history
  • Loading branch information
mistydemeo committed Nov 28, 2023
1 parent ab9faaf commit b58a529
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions cargo-dist/src/generic_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit b58a529

Please sign in to comment.