Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cargo fix --edition to prepare for Rust edition 2024 #2345

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
51 changes: 31 additions & 20 deletions src/auditwheel/audit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,16 @@ fn policy_is_satisfied(
}
offending_libs.insert(dep.clone());
}
if let Some(sym_list) = policy.blacklist.get(dep) {
let mut intersection: Vec<_> = sym_list.intersection(&undef_symbols).cloned().collect();
if !intersection.is_empty() {
intersection.sort();
offending_blacklist_syms.insert(dep, intersection);
match policy.blacklist.get(dep) {
Some(sym_list) => {
let mut intersection: Vec<_> =
sym_list.intersection(&undef_symbols).cloned().collect();
if !intersection.is_empty() {
intersection.sort();
offending_blacklist_syms.insert(dep, intersection);
}
}
_ => {}
}
}
for library in versioned_libraries {
Expand Down Expand Up @@ -263,14 +267,18 @@ fn policy_is_satisfied(

fn get_default_platform_policies() -> Vec<Policy> {
if let Ok(Some(musl_libc)) = find_musl_libc() {
if let Ok(Some((major, minor))) = get_musl_version(musl_libc) {
return MUSLLINUX_POLICIES
.iter()
.filter(|policy| {
policy.name == "linux" || policy.name == format!("musllinux_{major}_{minor}")
})
.cloned()
.collect();
match get_musl_version(musl_libc) {
Ok(Some((major, minor))) => {
return MUSLLINUX_POLICIES
.iter()
.filter(|policy| {
policy.name == "linux"
|| policy.name == format!("musllinux_{major}_{minor}")
})
.cloned()
.collect();
}
_ => {}
}
}
MANYLINUX_POLICIES.clone()
Expand Down Expand Up @@ -394,16 +402,19 @@ pub fn auditwheel_rs(
}
Err(err) => Err(err),
}
} else if let Some(policy) = highest_policy {
Ok(policy)
} else {
eprintln!(
"⚠️ Warning: No compatible platform tag found, using the linux tag instead. \
match highest_policy {
Some(policy) => Ok(policy),
_ => {
eprintln!(
"⚠️ Warning: No compatible platform tag found, using the linux tag instead. \
You won't be able to upload those wheels to PyPI."
);
);

// Fallback to linux
Ok(Policy::default())
// Fallback to linux
Ok(Policy::default())
}
}
}?;
Ok((policy, should_repair))
}
Expand Down
11 changes: 4 additions & 7 deletions src/auditwheel/platform_tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,10 @@ impl PlatformTag {
/// manylinux aliases
pub fn aliases(&self) -> Vec<String> {
match self {
PlatformTag::Manylinux { .. } => {
if let Some(policy) = Policy::from_name(&self.to_string()) {
policy.aliases
} else {
Vec::new()
}
}
PlatformTag::Manylinux { .. } => match Policy::from_name(&self.to_string()) {
Some(policy) => policy.aliases,
_ => Vec::new(),
},
PlatformTag::Musllinux { .. } => Vec::new(),
PlatformTag::Linux => Vec::new(),
}
Expand Down
27 changes: 15 additions & 12 deletions src/build_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,12 +339,15 @@ impl BuildContext {
}
}
let new_rpath = new_rpaths.join(":");
if let Err(err) = patchelf::set_rpath(&artifact.path, &new_rpath) {
eprintln!(
"⚠️ Warning: Failed to set rpath for {}: {}",
artifact.path.display(),
err
);
match patchelf::set_rpath(&artifact.path, &new_rpath) {
Err(err) => {
eprintln!(
"⚠️ Warning: Failed to set rpath for {}: {}",
artifact.path.display(),
err
);
}
_ => {}
}
}
}
Expand Down Expand Up @@ -557,16 +560,16 @@ impl BuildContext {
// macOS
(Os::Macos, Arch::X86_64) | (Os::Macos, Arch::Aarch64) => {
let ((x86_64_major, x86_64_minor), (arm64_major, arm64_minor)) = macosx_deployment_target(env::var("MACOSX_DEPLOYMENT_TARGET").ok().as_deref(), self.universal2)?;
let x86_64_tag = if let Some(deployment_target) = self.pyproject_toml.as_ref().and_then(|x| x.target_config("x86_64-apple-darwin")).and_then(|config| config.macos_deployment_target.as_ref()) {
let x86_64_tag = match self.pyproject_toml.as_ref().and_then(|x| x.target_config("x86_64-apple-darwin")).and_then(|config| config.macos_deployment_target.as_ref()) { Some(deployment_target) => {
deployment_target.replace('.', "_")
} else {
} _ => {
format!("{x86_64_major}_{x86_64_minor}")
};
let arm64_tag = if let Some(deployment_target) = self.pyproject_toml.as_ref().and_then(|x| x.target_config("aarch64-apple-darwin")).and_then(|config| config.macos_deployment_target.as_ref()) {
}};
let arm64_tag = match self.pyproject_toml.as_ref().and_then(|x| x.target_config("aarch64-apple-darwin")).and_then(|config| config.macos_deployment_target.as_ref()) { Some(deployment_target) => {
deployment_target.replace('.', "_")
} else {
} _ => {
format!("{arm64_major}_{arm64_minor}")
};
}};
if self.universal2 {
format!(
"macosx_{x86_64_tag}_x86_64.macosx_{arm64_tag}_arm64.macosx_{x86_64_tag}_universal2"
Expand Down
40 changes: 24 additions & 16 deletions src/build_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,15 +250,17 @@ impl BuildOptions {
let host_python = &host_interpreters[0];
eprintln!("🐍 Using host {host_python} for cross-compiling preparation");
// pyo3
env::set_var("PYO3_PYTHON", &host_python.executable);
unsafe { env::set_var("PYO3_PYTHON", &host_python.executable) };
// rust-cpython, and legacy pyo3 versions
env::set_var("PYTHON_SYS_EXECUTABLE", &host_python.executable);
unsafe { env::set_var("PYTHON_SYS_EXECUTABLE", &host_python.executable) };

let sysconfig_path = find_sysconfigdata(cross_lib_dir.as_ref(), target)?;
env::set_var(
"MATURIN_PYTHON_SYSCONFIGDATA_DIR",
sysconfig_path.parent().unwrap(),
);
unsafe {
env::set_var(
"MATURIN_PYTHON_SYSCONFIGDATA_DIR",
sysconfig_path.parent().unwrap(),
)
};

let sysconfig_data = parse_sysconfigdata(host_python, sysconfig_path)?;
let major = sysconfig_data
Expand Down Expand Up @@ -623,10 +625,11 @@ impl BuildContextBuilder {
let mut target = Target::from_target_triple(target_triple)?;
if !target.user_specified && !universal2 {
if let Some(interpreter) = build_options.interpreter.first() {
if let Some(detected_target) =
crate::target::detect_arch_from_python(interpreter, &target)
{
target = Target::from_target_triple(Some(detected_target))?;
match crate::target::detect_arch_from_python(interpreter, &target) {
Some(detected_target) => {
target = Target::from_target_triple(Some(detected_target))?;
}
_ => {}
}
}
}
Expand Down Expand Up @@ -1138,12 +1141,17 @@ pub fn find_bridge(cargo_metadata: &Metadata, bridge: Option<&str>) -> Result<Br
);
}

return if let Some((major, minor)) = has_abi3(cargo_metadata)? {
eprintln!("🔗 Found {lib} bindings with abi3 support for Python ≥ {major}.{minor}");
Ok(BridgeModel::BindingsAbi3(major, minor))
} else {
eprintln!("🔗 Found {lib} bindings");
Ok(bridge)
return match has_abi3(cargo_metadata)? {
Some((major, minor)) => {
eprintln!(
"🔗 Found {lib} bindings with abi3 support for Python ≥ {major}.{minor}"
);
Ok(BridgeModel::BindingsAbi3(major, minor))
}
_ => {
eprintln!("🔗 Found {lib} bindings");
Ok(bridge)
}
};
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/ci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1260,12 +1260,12 @@ mod tests {

#[test]
fn test_generate_github_zig_pytest() {
let gen = GenerateCI {
let r#gen = GenerateCI {
zig: true,
pytest: true,
..Default::default()
};
let conf = gen
let conf = r#gen
.generate_github(
"example",
&BridgeModel::Bindings("pyo3".to_string(), 7),
Expand Down
21 changes: 12 additions & 9 deletions src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,15 +347,18 @@ fn cargo_build_command(
#[cfg(feature = "zig")]
if context.zig {
// Pass zig command to downstream, eg. python3-dll-a
if let Ok((zig_cmd, zig_args)) = cargo_zigbuild::Zig::find_zig() {
if zig_args.is_empty() {
build_command.env("ZIG_COMMAND", zig_cmd);
} else {
build_command.env(
"ZIG_COMMAND",
format!("{} {}", zig_cmd.display(), zig_args.join(" ")),
);
};
match cargo_zigbuild::Zig::find_zig() {
Ok((zig_cmd, zig_args)) => {
if zig_args.is_empty() {
build_command.env("ZIG_COMMAND", zig_cmd);
} else {
build_command.env(
"ZIG_COMMAND",
format!("{} {}", zig_cmd.display(), zig_args.join(" ")),
);
};
}
_ => {}
}
}

Expand Down
18 changes: 12 additions & 6 deletions src/develop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,16 @@ fn parse_direct_url_path(pip_show_output: &str) -> Result<Option<PathBuf>> {
.captures(pip_show_output)
.map(|c| c.get(1))
{
if let Some(Some(direct_url_path)) = Regex::new(r" (.*direct_url.json)")?
match Regex::new(r" (.*direct_url.json)")?
.captures(pip_show_output)
.map(|c| c.get(1))
{
return Ok(Some(
PathBuf::from(location.as_str()).join(direct_url_path.as_str()),
));
Some(Some(direct_url_path)) => {
return Ok(Some(
PathBuf::from(location.as_str()).join(direct_url_path.as_str()),
));
}
_ => {}
}
}
Ok(None)
Expand Down Expand Up @@ -308,8 +311,11 @@ pub fn develop(develop_options: DevelopOptions, venv_dir: &Path) -> Result<()> {

// check python platform and architecture
if !target.user_specified {
if let Some(detected_target) = detect_arch_from_python(&python, &target) {
target_triple = Some(detected_target);
match detect_arch_from_python(&python, &target) {
Some(detected_target) => {
target_triple = Some(detected_target);
}
_ => {}
}
}

Expand Down
20 changes: 13 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,11 @@ fn run() -> Result<()> {

let mut wheels = build_context.build_wheels()?;
if !no_sdist {
if let Some(sd) = build_context.build_source_distribution()? {
wheels.push(sd);
match build_context.build_source_distribution()? {
Some(sd) => {
wheels.push(sd);
}
_ => {}
}
}

Expand Down Expand Up @@ -551,11 +554,14 @@ fn main() {
#[cfg(not(debug_assertions))]
setup_panic_hook();

if let Err(e) = run() {
eprintln!("💥 maturin failed");
for cause in e.chain() {
eprintln!(" Caused by: {cause}");
match run() {
Err(e) => {
eprintln!("💥 maturin failed");
for cause in e.chain() {
eprintln!(" Caused by: {cause}");
}
std::process::exit(1);
}
std::process::exit(1);
_ => {}
}
}
19 changes: 11 additions & 8 deletions src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,15 +318,18 @@ impl Metadata23 {
if let Some(gui_scripts) = &project.gui_scripts {
self.gui_scripts.clone_from(gui_scripts);
}
if let Some(entry_points) = &project.entry_points {
// Raise error on ambiguous entry points: https://www.python.org/dev/peps/pep-0621/#entry-points
if entry_points.contains_key("console_scripts") {
bail!("console_scripts is not allowed in project.entry-points table");
}
if entry_points.contains_key("gui_scripts") {
bail!("gui_scripts is not allowed in project.entry-points table");
match &project.entry_points {
Some(entry_points) => {
// Raise error on ambiguous entry points: https://www.python.org/dev/peps/pep-0621/#entry-points
if entry_points.contains_key("console_scripts") {
bail!("console_scripts is not allowed in project.entry-points table");
}
if entry_points.contains_key("gui_scripts") {
bail!("gui_scripts is not allowed in project.entry-points table");
}
self.entry_points.clone_from(entry_points);
}
self.entry_points.clone_from(entry_points);
_ => {}
}
}
Ok(())
Expand Down
Loading
Loading