Skip to content

Commit

Permalink
build.rs: Replace Target::env with Target::is_musl.
Browse files Browse the repository at this point in the history
Make the limited role of the `env` part of the target triple more clear.
  • Loading branch information
briansmith committed Aug 14, 2021
1 parent 31e9f68 commit b88024a
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,10 @@ fn ring_build_rs_main() {

let arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
let os = env::var("CARGO_CFG_TARGET_OS").unwrap();
let env = env::var("CARGO_CFG_TARGET_ENV").unwrap();
let is_musl = {
let env = env::var("CARGO_CFG_TARGET_ENV").unwrap();
env.starts_with("musl")
};

let is_git = std::fs::metadata(".git").is_ok();

Expand All @@ -330,7 +333,7 @@ fn ring_build_rs_main() {
let target = Target {
arch,
os,
env,
is_musl,
is_debug,
force_warnings_into_errors,
};
Expand Down Expand Up @@ -385,7 +388,9 @@ fn pregenerate_asm_main() {
struct Target {
arch: String,
os: String,
env: String,

/// Is the target one that uses the musl C standard library instead of the default?
is_musl: bool,

/// Is this a debug build? This affects whether assertions might be enabled
/// in the C code. For packaged builds, this should always be `false`.
Expand Down Expand Up @@ -560,8 +565,6 @@ fn cc(
out_path: &Path,
include_dir: &Path,
) -> Command {
let is_musl = target.env.starts_with("musl");

let mut c = cc::Build::new();
let _ = c.include("include");
let _ = c.include(include_dir);
Expand Down Expand Up @@ -610,7 +613,7 @@ fn cc(
//
// poly1305_vec.c requires <emmintrin.h> which requires <stdlib.h>.
if (target.arch == "wasm32" && target.os == "unknown")
|| (target.os == "linux" && is_musl && target.arch != "x86_64")
|| (target.os == "linux" && target.is_musl && target.arch != "x86_64")
{
if let Ok(compiler) = c.try_get_compiler() {
// TODO: Expand this to non-clang compilers in 0.17.0 if practical.
Expand All @@ -624,7 +627,7 @@ fn cc(
if target.force_warnings_into_errors {
c.warnings_into_errors(true);
}
if is_musl {
if target.is_musl {
// Some platforms enable _FORTIFY_SOURCE by default, but musl
// libc doesn't support it yet. See
// http://wiki.musl-libc.org/wiki/Future_Ideas#Fortify
Expand Down

0 comments on commit b88024a

Please sign in to comment.