Skip to content

Commit

Permalink
Respect MACOSX_DEPLOYMENT_TARGET in --python-platform (astral-sh#…
Browse files Browse the repository at this point in the history
…3470)

## Summary

This is universal environment variable used to determine the mac OS
deployment target. We now respect it in `--python-platform` -- so we
default to 12.0, but users can override it as needed.
  • Loading branch information
charliermarsh authored May 8, 2024
1 parent ca809ad commit 7d41e7d
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 19 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,9 @@ In addition, uv respects the following environment variables:
- `ZSH_VERSION`: Used to detect the use of the Zsh shell.
- `RAYON_NUM_THREADS`: Used to control the number of threads used when unzipping and installing
packages. See the [rayon documentation](https://docs.rs/rayon/latest/rayon/) for more.
- `MACOSX_DEPLOYMENT_TARGET`: Used with `--python-platform macos` and related variants to set the
deployment target (i.e., the minimum supported macOS version). Defaults to `12.0`, the
least-recent non-EOL macOS version at time of writing.

## Versioning

Expand Down
1 change: 1 addition & 0 deletions crates/uv-configuration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ rustc-hash = { workspace = true }
schemars = { workspace = true, optional = true }
serde = { workspace = true }
serde_json = { workspace = true }
tracing = { workspace = true }

[features]
default = []
55 changes: 38 additions & 17 deletions crates/uv-configuration/src/target_triple.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use tracing::debug;

use pep508_rs::MarkerEnvironment;
use platform_tags::{Arch, Os, Platform};

Expand Down Expand Up @@ -29,13 +31,18 @@ pub enum TargetTriple {
#[cfg_attr(feature = "schemars", schemars(rename = "x86_64-unknown-linux-gnu"))]
X8664UnknownLinuxGnu,

/// An ARM-based macOS target, as seen on Apple Silicon devices, with support for the
/// least-recent, non-EOL macOS version (12.0).
/// An ARM-based macOS target, as seen on Apple Silicon devices
///
/// By default, assumes the least-recent, non-EOL macOS version (12.0), but respects
/// the `MACOSX_DEPLOYMENT_TARGET` environment variable if set.
#[cfg_attr(feature = "clap", value(name = "aarch64-apple-darwin"))]
#[cfg_attr(feature = "schemars", schemars(rename = "aarch64-apple-darwin"))]
Aarch64AppleDarwin,

/// An x86 macOS target, with support for the least-recent, non-EOL macOS version (12.0).
/// An x86 macOS target.
///
/// By default, assumes the least-recent, non-EOL macOS version (12.0), but respects
/// the `MACOSX_DEPLOYMENT_TARGET` environment variable if set.
#[cfg_attr(feature = "clap", value(name = "x86_64-apple-darwin"))]
#[cfg_attr(feature = "schemars", schemars(rename = "x86_64-apple-darwin"))]
X8664AppleDarwin,
Expand Down Expand Up @@ -88,20 +95,20 @@ impl TargetTriple {
},
Arch::X86_64,
),
Self::Macos | Self::Aarch64AppleDarwin => Platform::new(
Os::Macos {
major: 12,
minor: 0,
},
Arch::Aarch64,
),
Self::X8664AppleDarwin => Platform::new(
Os::Macos {
major: 12,
minor: 0,
},
Arch::X86_64,
),
Self::Macos | Self::Aarch64AppleDarwin => {
let (major, minor) = macos_deployment_target().map_or((12, 0), |(major, minor)| {
debug!("Found macOS deployment target: {}.{}", major, minor);
(major, minor)
});
Platform::new(Os::Macos { major, minor }, Arch::Aarch64)
}
Self::X8664AppleDarwin => {
let (major, minor) = macos_deployment_target().map_or((12, 0), |(major, minor)| {
debug!("Found macOS deployment target: {}.{}", major, minor);
(major, minor)
});
Platform::new(Os::Macos { major, minor }, Arch::X86_64)
}
Self::Aarch64UnknownLinuxGnu => Platform::new(
Os::Manylinux {
major: 2,
Expand Down Expand Up @@ -271,3 +278,17 @@ impl TargetTriple {
}
}
}

/// Return the macOS deployment target as parsed from the environment.
fn macos_deployment_target() -> Option<(u16, u16)> {
let version = std::env::var("MACOSX_DEPLOYMENT_TARGET").ok()?;
let mut parts = version.split('.');

// Parse the major version (e.g., `12` in `12.0`).
let major = parts.next()?.parse::<u16>().ok()?;

// Parse the minor version (e.g., `0` in `12.0`), with a default of `0`.
let minor = parts.next().unwrap_or("0").parse::<u16>().ok()?;

Some((major, minor))
}
4 changes: 2 additions & 2 deletions uv.schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7d41e7d

Please sign in to comment.