Skip to content

Commit

Permalink
Add PEP 656 musllinux support
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed May 19, 2021
1 parent 0afd208 commit 84d96a5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/auditwheel/audit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ pub fn auditwheel_rs(
target: &Target,
manylinux: Option<Manylinux>,
) -> Result<Policy, AuditWheelError> {
// TODO: add support for musllinux: https://github.com/pypa/auditwheel/issues/305
if !target.is_linux() || manylinux == Some(Manylinux::Off) {
return Ok(Policy::default());
}
Expand Down
50 changes: 34 additions & 16 deletions src/auditwheel/manylinux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize};
use std::fmt;
use std::str::FromStr;

/// Decides how to handle manylinux compliance
/// Decides how to handle manylinux and musllinux compliance
#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq, Copy)]
pub enum Manylinux {
/// Use the manylinux_x_y tag
Expand All @@ -13,15 +13,18 @@ pub enum Manylinux {
/// GLIBC version minor
y: u16,
},
/// Use the musllinux_x_y tag
Musllinux {
/// musl libc version major
x: u16,
/// musl libc version minor
y: u16,
},
/// Use the native linux tag
Off,
}

impl Manylinux {
fn new(x: u16, y: u16) -> Self {
Self::Manylinux { x, y }
}

/// `manylinux1` aka `manylinux_2_5`
pub fn manylinux1() -> Self {
Self::Manylinux { x: 2, y: 5 }
Expand All @@ -47,6 +50,7 @@ impl Manylinux {
Vec::new()
}
}
Manylinux::Musllinux { .. } => Vec::new(),
Manylinux::Off => Vec::new(),
}
}
Expand All @@ -56,6 +60,7 @@ impl fmt::Display for Manylinux {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Manylinux::Manylinux { x, y } => write!(f, "manylinux_{}_{}", x, y),
Manylinux::Musllinux { x, y } => write!(f, "musllinux_{}_{}", x, y),
Manylinux::Off => write!(f, "linux"),
}
}
Expand All @@ -71,17 +76,30 @@ impl FromStr for Manylinux {
"2010" | "manylinux2010" => Ok(Manylinux::manylinux2010()),
"2014" | "manylinux2014" => Ok(Manylinux::manylinux2014()),
_ => {
let value = value.strip_prefix("manylinux_").unwrap_or(value);
let mut parts = value.split('_');
let x = parts
.next()
.and_then(|x| x.parse::<u16>().ok())
.ok_or("invalid manylinux option")?;
let y = parts
.next()
.and_then(|y| y.parse::<u16>().ok())
.ok_or("invalid manylinux option")?;
Ok(Manylinux::new(x, y))
if let Some(value) = value.strip_prefix("musllinux_") {
let mut parts = value.split('_');
let x = parts
.next()
.and_then(|x| x.parse::<u16>().ok())
.ok_or("invalid musllinux option")?;
let y = parts
.next()
.and_then(|y| y.parse::<u16>().ok())
.ok_or("invalid musllinux option")?;
Ok(Manylinux::Musllinux { x, y })
} else {
let value = value.strip_prefix("manylinux_").unwrap_or(value);
let mut parts = value.split('_');
let x = parts
.next()
.and_then(|x| x.parse::<u16>().ok())
.ok_or("invalid manylinux option")?;
let y = parts
.next()
.and_then(|y| y.parse::<u16>().ok())
.ok_or("invalid manylinux option")?;
Ok(Manylinux::Manylinux { x, y })
}
}
}
}
Expand Down

0 comments on commit 84d96a5

Please sign in to comment.