Skip to content

Commit

Permalink
Add musllinux policy
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Jul 31, 2021
1 parent 49e73e4 commit 03f5516
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/auditwheel/audit.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::policy::{Policy, POLICIES};
use super::policy::{Policy, MANYLINUX_POLICIES};
use crate::auditwheel::PlatformTag;
use crate::Target;
use anyhow::Result;
Expand Down Expand Up @@ -277,8 +277,8 @@ pub fn auditwheel_rs(

// Find the highest possible policy, if any
let mut highest_policy = None;
for policy in POLICIES.iter() {
let result = policy_is_satisfied(policy, &elf, &arch, &deps, &versioned_libraries);
for policy in MANYLINUX_POLICIES.iter() {
let result = policy_is_satisfied(&policy, &elf, &arch, &deps, &versioned_libraries);
match result {
Ok(_) => {
highest_policy = Some(policy.clone());
Expand Down
2 changes: 1 addition & 1 deletion src/auditwheel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ mod policy;

pub use self::audit::*;
pub use platform_tag::PlatformTag;
pub use policy::{Policy, POLICIES};
pub use policy::{Policy, MANYLINUX_POLICIES, MUSLLINUX_POLICIES};
48 changes: 48 additions & 0 deletions src/auditwheel/musllinux-policy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
[
{"name": "linux",
"aliases": [],
"priority": 0,
"symbol_versions": {},
"lib_whitelist": []
},
{"name": "musllinux_1_1",
"aliases": [],
"priority": 100,
"symbol_versions": {
"i686": {
},
"x86_64": {
},
"aarch64": {
},
"ppc64le": {
},
"s390x": {
},
"armv7l": {
}
},
"lib_whitelist": [
"libc.so", "libc.musl-x86_64.so.1"
]},
{"name": "musllinux_1_2",
"aliases": [],
"priority": 90,
"symbol_versions": {
"i686": {
},
"x86_64": {
},
"aarch64": {
},
"ppc64le": {
},
"s390x": {
},
"armv7l": {
}
},
"lib_whitelist": [
"libc.so", "libc.musl-x86_64.so.1"
]}
]
46 changes: 34 additions & 12 deletions src/auditwheel/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,24 @@ use std::fmt::{Display, Formatter};

/// The policies (allowed symbols) for the different manylinux tags, sorted from highest
/// priority to lowest
pub static POLICIES: Lazy<Vec<Policy>> = Lazy::new(|| {
// https://github.com/pypa/auditwheel/blob/master/auditwheel/policy/policy.json
pub static MANYLINUX_POLICIES: Lazy<Vec<Policy>> = Lazy::new(|| {
// https://github.com/pypa/auditwheel/blob/master/auditwheel/policy/manylinux-policy.json
let mut policies: Vec<Policy> = serde_json::from_slice(include_bytes!("manylinux-policy.json"))
.expect("invalid manylinux policy.json file");
policies.sort_by_key(|policy| -policy.priority);
policies
});

/// The policies (allowed symbols) for the different musllinux tags, sorted from highest
/// priority to lowest
pub static MUSLLINUX_POLICIES: Lazy<Vec<Policy>> = Lazy::new(|| {
// https://github.com/pypa/auditwheel/blob/master/auditwheel/policy/musllinux-policy.json
let mut policies: Vec<Policy> = serde_json::from_slice(include_bytes!("musllinux-policy.json"))
.expect("invalid musllinux policy.json file");
policies.sort_by_key(|policy| -policy.priority);
policies
});

/// Manylinux policy
#[derive(Debug, Clone, PartialEq, Deserialize)]
pub struct Policy {
Expand All @@ -35,7 +45,7 @@ pub struct Policy {
impl Default for Policy {
fn default() -> Self {
// defaults to linux
Policy::from_priority(0).unwrap()
Policy::from_name("linux").unwrap()
}
}

Expand All @@ -62,7 +72,12 @@ impl PartialOrd for Policy {
impl Policy {
/// Get highest priority policy than self
pub fn higher_priority_policies(&self) -> impl Iterator<Item = &Policy> {
POLICIES.iter().filter(move |p| p.priority > self.priority)
let policies = if self.name.starts_with("musllinux") {
&MUSLLINUX_POLICIES
} else {
&MANYLINUX_POLICIES
};
policies.iter().filter(move |p| p.priority > self.priority)
}

/// Get platform tag from this policy
Expand All @@ -72,21 +87,21 @@ impl Policy {

/// Get policy by it's platform tag name
pub fn from_name(name: &str) -> Option<Self> {
POLICIES
let policies = if name.starts_with("musllinux") {
&MUSLLINUX_POLICIES
} else {
&MANYLINUX_POLICIES
};
policies
.iter()
.find(|p| p.name == name || p.aliases.iter().any(|alias| alias == name))
.cloned()
}

/// Get policy by it's priority
pub fn from_priority(priority: i64) -> Option<Self> {
POLICIES.iter().find(|p| p.priority == priority).cloned()
}
}

#[cfg(test)]
mod test {
use super::{Policy, POLICIES};
use super::{Policy, MANYLINUX_POLICIES, MUSLLINUX_POLICIES};

#[test]
fn test_load_policy() {
Expand All @@ -106,7 +121,14 @@ mod test {

#[test]
fn test_policy_manylinux_tag() {
for policy in POLICIES.iter() {
for policy in MANYLINUX_POLICIES.iter() {
let _tag = policy.platform_tag();
}
}

#[test]
fn test_policy_musllinux_tag() {
for policy in MUSLLINUX_POLICIES.iter() {
let _tag = policy.platform_tag();
}
}
Expand Down

0 comments on commit 03f5516

Please sign in to comment.