Skip to content
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
9 changes: 8 additions & 1 deletion src/auditwheel/musllinux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ use std::process::{Command, Stdio};

/// Find musl libc path from executable's ELF header
pub fn find_musl_libc() -> Result<Option<PathBuf>> {
let buffer = fs::read("/bin/ls")?;
// Try /bin/ls first; fall back to /usr/bin/ls for distros that don't
// symlink /bin -> /usr/bin.
let ls_path = if Path::new("/bin/ls").exists() {
Path::new("/bin/ls")
} else {
Path::new("/usr/bin/ls")
};
let buffer = fs::read(ls_path)?;
let elf = Elf::parse(&buffer)?;
Ok(elf.interpreter.map(PathBuf::from))
}
Expand Down
22 changes: 12 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ use clap::CommandFactory;
use clap::{Parser, Subcommand};
use ignore::overrides::Override;
use maturin::{
BridgeModel, BuildOptions, CargoOptions, DevelopOptions, PathWriter, Target, TargetTriple,
UnpackedSdist, VirtualWriter, develop, find_path_deps, unpack_sdist, write_dist_info,
BridgeModel, BuildContext, BuildOptions, CargoOptions, DevelopOptions, PathWriter, Target,
TargetTriple, UnpackedSdist, VirtualWriter, develop, find_path_deps, unpack_sdist,
write_dist_info,
};
#[cfg(feature = "schemars")]
use maturin::{GenerateJsonSchemaOptions, generate_json_schema};
Expand Down Expand Up @@ -280,6 +281,13 @@ fn detect_venv(target: &Target) -> Result<PathBuf> {
///
/// The last line of stdout is used as return value from the python part of the implementation
fn pep517(subcommand: Pep517Command) -> Result<()> {
// PEP 517 builds default to release profile.
fn ensure_release_profile(context: &mut BuildContext) {
if context.cargo_options.profile.is_none() {
context.cargo_options.profile = Some("release".to_string());
}
}

match subcommand {
Pep517Command::WriteDistInfo {
build_options,
Expand All @@ -292,11 +300,7 @@ fn pep517(subcommand: Pep517Command) -> Result<()> {
.strip(strip_opt.strip)
.editable(false)
.build()?;

// TBD: does `--profile release` do anything here?
if context.cargo_options.profile.is_none() {
context.cargo_options.profile = Some("release".to_string());
}
ensure_release_profile(&mut context);

let mut writer =
VirtualWriter::new(PathWriter::from_path(metadata_directory), Override::empty());
Expand All @@ -319,9 +323,7 @@ fn pep517(subcommand: Pep517Command) -> Result<()> {
.strip(strip_opt.strip)
.editable(editable)
.build()?;
if build_context.cargo_options.profile.is_none() {
build_context.cargo_options.profile = Some("release".to_string());
}
ensure_release_profile(&mut build_context);
let wheels = build_context.build_wheels()?;
assert_eq!(wheels.len(), 1);
println!("{}", wheels[0].0.to_str().unwrap());
Expand Down
96 changes: 52 additions & 44 deletions src/module_writer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,52 +230,60 @@ pub fn add_data(
);
}
debug!("Adding data from {}", subdir.path().display());
(|| {
for file in WalkBuilder::new(subdir.path())
.standard_filters(false)
.build()
{
let file = file?;
let relative_path = file.path().strip_prefix(data).with_context(|| {
add_data_subdir(writer, subdir.path().as_path(), data, metadata24)
.with_context(|| format!("Failed to include data from {}", data.display()))?
}
}
Ok(())
}

/// Walk a single data subdirectory and add its files to the writer.
fn add_data_subdir(
writer: &mut impl ModuleWriter,
subdir_path: &Path,
data: &Path,
metadata24: &Metadata24,
) -> Result<()> {
for file in WalkBuilder::new(subdir_path)
.standard_filters(false)
.build()
{
let file = file?;
let relative_path = file.path().strip_prefix(data).with_context(|| {
format!(
"Data file {} is not under data dir {}",
file.path().display(),
data.display()
)
})?;
let relative = metadata24.get_data_dir().join(relative_path);

if file.path_is_symlink() {
// Copy the actual file contents, not the link, so that you can create a
// data directory by joining different data sources
let link_target = fs::read_link(file.path())?;
let source = if link_target.is_absolute() {
link_target
} else {
file.path()
.parent()
.with_context(|| {
format!(
"Data file {} is not under data dir {}",
file.path().display(),
data.display()
"Data symlink {} has no parent directory",
file.path().display()
)
})?;
let relative = metadata24.get_data_dir().join(relative_path);

if file.path_is_symlink() {
// Copy the actual file contents, not the link, so that you can create a
// data directory by joining different data sources
let link_target = fs::read_link(file.path())?;
let source = if link_target.is_absolute() {
link_target
} else {
file.path()
.parent()
.with_context(|| {
format!(
"Data symlink {} has no parent directory",
file.path().display()
)
})?
.join(link_target)
};
let mode = file_permission_mode(&source)?;
writer.add_file(relative, source, permission_is_executable(mode))?;
} else if file.path().is_file() {
let mode = file_permission_mode(file.path())?;
writer.add_file(relative, file.path(), permission_is_executable(mode))?;
} else if file.path().is_dir() {
// Intentionally ignored
} else {
bail!("Can't handle data dir entry {}", file.path().display());
}
}
Ok(())
})()
.with_context(|| format!("Failed to include data from {}", data.display()))?
})?
.join(link_target)
};
let mode = file_permission_mode(&source)?;
writer.add_file(relative, source, permission_is_executable(mode))?;
} else if file.path().is_file() {
let mode = file_permission_mode(file.path())?;
writer.add_file(relative, file.path(), permission_is_executable(mode))?;
} else if file.path().is_dir() {
// Intentionally ignored
} else {
bail!("Can't handle data dir entry {}", file.path().display());
}
}
Ok(())
Expand Down
Loading