Skip to content

Commit

Permalink
Merge pull request #1730 from messense/rustc-deployment-target
Browse files Browse the repository at this point in the history
Query default macOS deployment target from `rustc --print deployment-target`
  • Loading branch information
messense authored Aug 12, 2023
2 parents e02368b + a6e988c commit 38d33b3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ freebsd_task:
macos_arm64_task:
name: Test (arm64 macOS)
macos_instance:
image: ghcr.io/cirruslabs/macos-monterey-xcode
image: ghcr.io/cirruslabs/macos-monterey-xcode:latest
env:
PATH: $HOME/.cargo/bin:/opt/homebrew/opt/[email protected]/bin:$PATH
target_cache:
Expand Down
25 changes: 24 additions & 1 deletion src/build_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1154,9 +1154,32 @@ fn macosx_deployment_target(
}

pub(crate) fn rustc_macosx_target_version(target: &str) -> (u16, u16) {
use std::process::Command;
use std::process::{Command, Stdio};
use target_lexicon::OperatingSystem;

// On rustc 1.71.0+ we can use `rustc --print deployment-target`
if let Ok(output) = Command::new("rustc")
.stderr(Stdio::piped())
.stdout(Stdio::piped())
.env_remove("MACOSX_DEPLOYMENT_TARGET")
.args(["--target", target])
.args(["--print", "deployment-target"])
.output()
{
if output.status.success() {
let target_version = std::str::from_utf8(&output.stdout)
.unwrap()
.split('=')
.last()
.and_then(|v| v.trim().split_once('.'));
if let Some((major, minor)) = target_version {
let major: u16 = major.parse().unwrap();
let minor: u16 = minor.parse().unwrap();
return (major, minor);
}
}
}

let fallback_version = if target == "aarch64-apple-darwin" {
(11, 0)
} else {
Expand Down

0 comments on commit 38d33b3

Please sign in to comment.