Skip to content

Commit

Permalink
sanity check CI
Browse files Browse the repository at this point in the history
Revert "Detect target based on interpreter for pep517 build-wheel"

This reverts commit 88bce88.
  • Loading branch information
kcking committed May 14, 2024
1 parent 88bce88 commit 76a7ea2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 35 deletions.
11 changes: 1 addition & 10 deletions src/build_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,16 +551,7 @@ impl BuildOptions {
target_triple = None;
}

let mut target = Target::from_target_triple(target_triple)?;
if !target.user_specified && !universal2 {
if let Some(interpreter) = self.interpreter.first() {
if let Some(detected_target) =
crate::target::detect_arch_from_python(interpreter, &target)
{
target = Target::from_target_triple(Some(detected_target))?;
}
}
}
let target = Target::from_target_triple(target_triple)?;

let wheel_dir = match self.out {
Some(ref dir) => dir.clone(),
Expand Down
20 changes: 17 additions & 3 deletions src/develop.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::build_options::CargoOptions;
use crate::target::detect_arch_from_python;
use crate::target::Arch;
use crate::BuildContext;
use crate::BuildOptions;
use crate::PlatformTag;
Expand Down Expand Up @@ -307,8 +307,22 @@ 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 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"),
}
}

Expand Down
22 changes: 0 additions & 22 deletions src/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use std::env;
use std::fmt;
use std::path::Path;
use std::path::PathBuf;
use std::process::Command;
use std::str;
use target_lexicon::{Architecture, Environment, Triple};
use tracing::error;
Expand Down Expand Up @@ -619,24 +618,3 @@ fn rustc_version_meta() -> Result<VersionMeta> {
})?;
Ok(meta)
}

pub(crate) fn detect_arch_from_python(python: &PathBuf, target: &Target) -> Option<String> {
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 {
return Some("x86_64-apple-darwin".to_string());
} else if platform.contains("arm64") && target.target_arch() != Arch::Aarch64 {
return Some("aarch64-apple-darwin".to_string());
}
}
}
_ => eprintln!("⚠️ Warning: Failed to determine python platform"),
}
None
}

0 comments on commit 76a7ea2

Please sign in to comment.