From 8a9605a4399c7766c5dc83b7791e95ef95cd56ee Mon Sep 17 00:00:00 2001 From: messense Date: Tue, 20 Jul 2021 13:29:01 +0800 Subject: [PATCH] Add auditwheel support for musllinux --- src/auditwheel/audit.rs | 46 ++++++++++++++++++---------- src/auditwheel/musllinux-policy.json | 4 +-- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/src/auditwheel/audit.rs b/src/auditwheel/audit.rs index 1854ca072..13d0ccf08 100644 --- a/src/auditwheel/audit.rs +++ b/src/auditwheel/audit.rs @@ -1,6 +1,6 @@ -use super::policy::{Policy, MANYLINUX_POLICIES}; +use super::policy::{Policy, MANYLINUX_POLICIES, MUSLLINUX_POLICIES}; use crate::auditwheel::PlatformTag; -use crate::Target; +use crate::target::{Arch, Target}; use anyhow::Result; use fs_err::File; use goblin::elf::{sym::STT_FUNC, Elf}; @@ -253,18 +253,6 @@ pub fn auditwheel_rs( if !target.is_linux() || platform_tag == Some(PlatformTag::Linux) { return Ok(Policy::default()); } - if let Some(musl_tag @ PlatformTag::Musllinux { .. }) = platform_tag { - // TODO: add support for musllinux: https://github.com/pypa/auditwheel/issues/305 - eprintln!("⚠ Warning: no auditwheel support for musllinux yet"); - // HACK: fake a musllinux policy - return Ok(Policy { - name: musl_tag.to_string(), - aliases: Vec::new(), - priority: 0, - symbol_versions: Default::default(), - lib_whitelist: Default::default(), - }); - } let arch = target.target_arch().to_string(); let mut file = File::open(path).map_err(AuditWheelError::IoError)?; let mut buffer = Vec::new(); @@ -276,9 +264,35 @@ pub fn auditwheel_rs( let versioned_libraries = find_versioned_libraries(&elf, &buffer)?; // Find the highest possible policy, if any + let platform_policies = match platform_tag { + Some(PlatformTag::Manylinux { .. }) | None => MANYLINUX_POLICIES.clone(), + Some(PlatformTag::Musllinux { .. }) => { + MUSLLINUX_POLICIES + .clone() + .into_iter() + .map(|mut policy| { + // Fixup musl libc lib_whitelist + if policy.lib_whitelist.contains("libc.so") { + let soname = match target.target_arch() { + Arch::Aarch64 => "libc.musl-aarch64.so.1", + Arch::Armv7L => "libc.musl-armv7.so.1", + Arch::Powerpc64Le => "libc.musl-ppc64le.so.1", + Arch::Powerpc64 => unreachable!(), // musllinux doesn't support ppc64 + Arch::X86 => "libc.musl-x86.so.1", + Arch::X86_64 => "libc.musl-x86_64.so.1", + Arch::S390X => "libc.musl-s390x.so.1", + }; + policy.lib_whitelist.insert(soname.to_string()); + } + policy + }) + .collect() + } + Some(PlatformTag::Linux) => unreachable!(), + }; let mut highest_policy = None; - for policy in MANYLINUX_POLICIES.iter() { - let result = policy_is_satisfied(&policy, &elf, &arch, &deps, &versioned_libraries); + for policy in platform_policies.iter() { + let result = policy_is_satisfied(policy, &elf, &arch, &deps, &versioned_libraries); match result { Ok(_) => { highest_policy = Some(policy.clone()); diff --git a/src/auditwheel/musllinux-policy.json b/src/auditwheel/musllinux-policy.json index e4c770b80..6cf8c3186 100644 --- a/src/auditwheel/musllinux-policy.json +++ b/src/auditwheel/musllinux-policy.json @@ -23,7 +23,7 @@ } }, "lib_whitelist": [ - "libc.so", "libc.musl-x86_64.so.1" + "libc.so" ]}, {"name": "musllinux_1_2", "aliases": [], @@ -43,6 +43,6 @@ } }, "lib_whitelist": [ - "libc.so", "libc.musl-x86_64.so.1" + "libc.so" ]} ]