Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix building for musl libc #423

Merged
merged 1 commit into from
Feb 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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