Skip to content

Commit

Permalink
Fix maturin develop for arm64 Python on M1 Mac when default toolcha…
Browse files Browse the repository at this point in the history
…in is x86_64
  • Loading branch information
messense committed Jun 21, 2022
1 parent cecd677 commit 7980b82
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Expose commonly used Cargo CLI options in `maturin build` command in [#972](https://github.com/PyO3/maturin/pull/972)
* Add support for `wasm32-unknown-emscripten` target in [#974](https://github.com/PyO3/maturin/pull/974)
* Allow overriding platform release version using env var in [#975](https://github.com/PyO3/maturin/pull/975)
* Fix `maturin develop` for arm64 Python on M1 Mac when default toolchain is x86_64 in [#980](https://github.com/PyO3/maturin/pull/980)

## [0.12.20] - 2022-06-15

Expand Down
27 changes: 26 additions & 1 deletion src/develop.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::build_options::CargoOptions;
use crate::target::Arch;
use crate::BuildOptions;
use crate::PlatformTag;
use crate::PythonInterpreter;
Expand All @@ -22,7 +23,28 @@ pub fn develop(
extras: Vec<String>,
) -> Result<()> {
let target = Target::from_target_triple(None)?;
let mut target_triple = None;
let python = target.get_venv_python(&venv_dir);

// check python platform and architecture
match Command::new(&python)
.arg("-c")
.arg("import sysconfig; print(sysconfig.get_platform(), end='')")
.output()
{
Ok(output) if output.status.success() => {
let platform = String::from_utf8_lossy(&output.stdout);
if platform.contains("macos") {
if platform.contains("x86_64") && target.target_arch() != Arch::X86_64 {
target_triple = Some("x86_64-apple-darwin".to_string());
} else if platform.contains("arm64") && target.target_arch() != Arch::Aarch64 {
target_triple = Some("aarch64-apple-darwin".to_string());
}
}
}
_ => eprintln!("⚠️ Warning: Failed to determine python platform"),
}

// Store wheel in a unique location so we don't get name clashes with parallel runs
let wheel_dir = TempDir::new().context("Failed to create temporary directory")?;

Expand All @@ -35,7 +57,10 @@ pub fn develop(
skip_auditwheel: false,
zig: false,
universal2: false,
cargo: cargo_options,
cargo: CargoOptions {
target: target_triple,
..cargo_options
},
};

let build_context = build_options.into_build_context(release, strip, true)?;
Expand Down

0 comments on commit 7980b82

Please sign in to comment.