Skip to content

Commit

Permalink
Merge pull request #1701 from messense/warn-incompatible-target
Browse files Browse the repository at this point in the history
Warn about incompatible targets for musllinux
  • Loading branch information
messense authored Jul 26, 2023
2 parents f1f2cdf + b04d20a commit 1324acf
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
8 changes: 5 additions & 3 deletions src/build_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ impl BuildOptions {
x.compatibility()
})
.or(if use_zig {
if target.is_musl_target() {
if target.is_musl_libc() {
// Zig bundles musl 1.2
Some(PlatformTag::Musllinux { x: 1, y: 2 })
} else {
Expand All @@ -601,7 +601,7 @@ impl BuildOptions {
}
} else {
// Defaults to musllinux_1_2 for musl target if it's not bin bindings
if target.is_musl_target() && !bridge.is_bin() {
if target.is_musl_libc() && !bridge.is_bin() {
Some(PlatformTag::Musllinux { x: 1, y: 2 })
} else {
None
Expand All @@ -619,6 +619,8 @@ impl BuildOptions {
for platform_tag in &platform_tags {
if !platform_tag.is_supported() {
eprintln!("⚠️ Warning: {platform_tag} is unsupported by the Rust compiler.");
} else if platform_tag.is_musllinux() && !target.is_musl_libc() {
eprintln!("⚠️ Warning: {target} is not compatible with {platform_tag}.");
}
}

Expand Down Expand Up @@ -686,7 +688,7 @@ fn validate_bridge_type(
match bridge {
BridgeModel::Bin(None) => {
// Only support two different kind of platform tags when compiling to musl target without any binding crates
if platform_tags.iter().any(|tag| tag.is_musllinux()) && !target.is_musl_target() {
if platform_tags.iter().any(|tag| tag.is_musllinux()) && !target.is_musl_libc() {
bail!(
"Cannot mix musllinux and manylinux platform tags when compiling to {}",
target.target_triple()
Expand Down
4 changes: 2 additions & 2 deletions src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ fn compile_target(
// https://github.com/rust-lang/rust/issues/59302#issue-422994250
// We must only do this for libraries as it breaks binaries
// For some reason this value is ignored when passed as rustc argument
if context.target.is_musl_target()
if context.target.is_musl_libc()
&& !rustflags
.flags
.iter()
Expand Down Expand Up @@ -300,7 +300,7 @@ fn compile_target(
}
} else {
build.enable_zig_ar = true;
let zig_triple = if target.is_linux() && !target.is_musl_target() {
let zig_triple = if target.is_linux() && !target.is_musl_libc() {
match context.platform_tag.iter().find(|tag| tag.is_manylinux()) {
Some(PlatformTag::Manylinux { x, y }) => {
format!("{target_triple}.{x}.{y}")
Expand Down
8 changes: 7 additions & 1 deletion src/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ pub struct Target {
pub(crate) user_specified: bool,
}

impl fmt::Display for Target {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.triple)
}
}

impl Target {
/// Uses the given target triple or tries the guess the current target by using the one used
/// for compilation
Expand Down Expand Up @@ -502,7 +508,7 @@ impl Target {

/// Returns true if the current platform's target env is Musl
#[inline]
pub fn is_musl_target(&self) -> bool {
pub fn is_musl_libc(&self) -> bool {
matches!(
self.env,
Environment::Musl
Expand Down
2 changes: 1 addition & 1 deletion tests/common/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub fn test_integration(
for ((filename, supported_version), python_interpreter) in wheels.iter().zip(interpreter) {
if test_zig
&& build_context.target.is_linux()
&& !build_context.target.is_musl_target()
&& !build_context.target.is_musl_libc()
&& build_context.target.get_minimum_manylinux_tag() != PlatformTag::Linux
{
let rustc_ver = rustc_version::version()?;
Expand Down

0 comments on commit 1324acf

Please sign in to comment.