Skip to content

Commit

Permalink
fix: use language as default compiler name (#936)
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv authored Jun 19, 2024
1 parent 53a4392 commit 48b7e05
Showing 1 changed file with 51 additions and 27 deletions.
78 changes: 51 additions & 27 deletions src/recipe/jinja.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,36 +188,42 @@ fn jinja_pin_function(
}

fn default_compiler(platform: Platform, language: &str) -> Option<String> {
match language {
// Platform agnostic compilers
"fortran" => Some("gfortran"),
"rust" => Some("rust"),
"go" => Some("go"),
"go-nocgo" => Some("go-nocgo"),
// Platform specific compilers
_ => {
if platform.is_windows() {
match language {
"c" => Some("vs2017"),
"cxx" => Some("vs2017"),
_ => None,
}
} else if platform.is_osx() {
match language {
"c" => Some("clang"),
"cxx" => Some("clangxx"),
_ => None,
}
} else {
match language {
"c" => Some("gcc"),
"cxx" => Some("gxx"),
_ => None,
Some(
match language {
// Platform agnostic compilers
"fortran" => "gfortran",
lang if !["c", "cxx"].contains(&lang) => lang,
// Platform specific compilers
_ => {
if platform.is_windows() {
match language {
"c" => "vs2017",
"cxx" => "vs2017",
_ => unreachable!(),
}
} else if platform.is_osx() {
match language {
"c" => "clang",
"cxx" => "clangxx",
_ => unreachable!(),
}
} else if matches!(platform, Platform::EmscriptenWasm32) {
match language {
"c" => "emscripten",
"cxx" => "emscripten",
_ => unreachable!(),
}
} else {
match language {
"c" => "gcc",
"cxx" => "gxx",
_ => unreachable!(),
}
}
}
}
}
.map(|s| s.to_string())
.to_string(),
)
}

fn compiler_stdlib_eval(
Expand Down Expand Up @@ -1131,4 +1137,22 @@ mod tests {
assert!(jinja.eval("cmp(python, '==3.7')").is_err());
assert!(jinja.eval("${{ \"foo\" | escape }}").is_err());
}

#[test]
fn test_default_compiler() {
let platform = Platform::Linux64;
assert_eq!("gxx", default_compiler(platform, "cxx").unwrap());
assert_eq!("cuda", default_compiler(platform, "cuda").unwrap());
assert_eq!("gcc", default_compiler(platform, "c").unwrap());

let platform = Platform::Linux32;
assert_eq!("gxx", default_compiler(platform, "cxx").unwrap());
assert_eq!("cuda", default_compiler(platform, "cuda").unwrap());
assert_eq!("gcc", default_compiler(platform, "c").unwrap());

let platform = Platform::Win64;
assert_eq!("vs2017", default_compiler(platform, "cxx").unwrap());
assert_eq!("vs2017", default_compiler(platform, "c").unwrap());
assert_eq!("cuda", default_compiler(platform, "cuda").unwrap());
}
}

0 comments on commit 48b7e05

Please sign in to comment.