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

Query default macOS deployment target from rustc --print deployment-target #1730

Merged
merged 2 commits into from
Aug 12, 2023
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
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