diff --git a/src/compile.rs b/src/compile.rs index 61db47564..b00c38324 100644 --- a/src/compile.rs +++ b/src/compile.rs @@ -5,6 +5,7 @@ use anyhow::{anyhow, bail, Context, Result}; use fat_macho::FatWriter; use fs_err::{self as fs, File}; use std::collections::HashMap; +use std::env; use std::io::{BufReader, Read}; use std::path::PathBuf; use std::process::{Command, Stdio}; @@ -162,9 +163,14 @@ fn compile_target( .iter() .fold("cargo".to_string(), |acc, x| acc + " " + x); + let mut rust_flags = env::var_os("RUSTFLAGS").unwrap_or_default(); + if context.target.is_musl_target() { + rust_flags.push(" -C target-feature=-crt-static"); + } let mut let_binding = Command::new("cargo"); let build_command = let_binding .args(&build_args) + .env("RUSTFLAGS", rust_flags) // We need to capture the json messages .stdout(Stdio::piped()) // We can't get colored human and json messages from rustc as they are mutually exclusive, diff --git a/src/target.rs b/src/target.rs index c1de2fca1..8b395cb88 100644 --- a/src/target.rs +++ b/src/target.rs @@ -1,5 +1,6 @@ use anyhow::{bail, format_err, Result}; use platform_info::*; +use platforms::target::Env; use platforms::Platform; use serde::{Deserialize, Serialize}; use std::env; @@ -80,6 +81,7 @@ impl fmt::Display for Arch { pub struct Target { os: OS, arch: Arch, + env: Option, } impl Target { @@ -139,7 +141,11 @@ impl Target { (OS::Windows, Arch::ARMV7L) => bail!("armv7l is not supported for Windows"), (_, _) => {} } - Ok(Target { os, arch }) + Ok(Target { + os, + arch, + env: platform.target_env, + }) } /// Returns whether the platform is 64 bit or 32 bit @@ -179,6 +185,15 @@ impl Target { self.os == OS::Windows } + /// Returns true if the current platform's target env is Musl + pub fn is_musl_target(&self) -> bool { + match self.env { + Some(Env::Musl) => true, + Some(_) => false, + None => false, + } + } + /// Returns the platform part of the tag for the wheel name for cffi wheels pub fn get_platform_tag(&self, manylinux: &Manylinux, universal2: bool) -> String { match (&self.os, &self.arch) {