Skip to content

Commit

Permalink
Query default macOS deployment target from `rustc --print deployment-…
Browse files Browse the repository at this point in the history
…target`
  • Loading branch information
messense committed Aug 12, 2023
1 parent e02368b commit edf72d7
Showing 1 changed file with 24 additions and 1 deletion.
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 edf72d7

Please sign in to comment.