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

Fix maturin develop for arm64 Python on M1 Mac when default toolchain is x86_64 #980

Merged
merged 1 commit into from
Jun 21, 2022
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
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