Skip to content

Commit

Permalink
Merge pull request #423 from messense/musl-no-crt-static
Browse files Browse the repository at this point in the history
Fix building for musl libc
  • Loading branch information
konstin authored Feb 17, 2021
2 parents aac56f4 + ecfc655 commit c8107b8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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,
Expand Down
17 changes: 16 additions & 1 deletion src/target.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -80,6 +81,7 @@ impl fmt::Display for Arch {
pub struct Target {
os: OS,
arch: Arch,
env: Option<Env>,
}

impl Target {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit c8107b8

Please sign in to comment.