mirror of
https://github.com/astral-sh/uv.git
synced 2025-10-28 10:50:29 +00:00
Add UV_LIBC to allow libc selection in multi-libc environment (#14646)
Closes #14262 ## Description Adds `UV_LIBC` environment variable and implements check within `Libc::from_env` as recommended here: https://github.com/astral-sh/uv/issues/14262#issuecomment-3014600313 Gave this a few passes to make sure I follow dev practices within uv as best I am able. Feel free to call out anything that could be improved. ## Test Plan Planned to simply run existing test suite. Open to adding more tests once implementation is validated due to my limited Rust experience.
This commit is contained in:
parent
03de6c36e3
commit
e547527587
3 changed files with 37 additions and 14 deletions
|
|
@ -5,6 +5,8 @@ use std::ops::Deref;
|
||||||
use std::{fmt, str::FromStr};
|
use std::{fmt, str::FromStr};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
|
use uv_static::EnvVars;
|
||||||
|
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
#[error("Unknown operating system: {0}")]
|
#[error("Unknown operating system: {0}")]
|
||||||
|
|
@ -15,6 +17,8 @@ pub enum Error {
|
||||||
UnknownLibc(String),
|
UnknownLibc(String),
|
||||||
#[error("Unsupported variant `{0}` for architecture `{1}`")]
|
#[error("Unsupported variant `{0}` for architecture `{1}`")]
|
||||||
UnsupportedVariant(String, String),
|
UnsupportedVariant(String, String),
|
||||||
|
#[error(transparent)]
|
||||||
|
LibcDetectionError(#[from] LibcDetectionError),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Architecture variants, e.g., with support for different instruction sets
|
/// Architecture variants, e.g., with support for different instruction sets
|
||||||
|
|
@ -95,22 +99,32 @@ pub enum Libc {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Libc {
|
impl Libc {
|
||||||
pub(crate) fn from_env() -> Result<Self, LibcDetectionError> {
|
pub(crate) fn from_env() -> Result<Self, Error> {
|
||||||
match std::env::consts::OS {
|
match std::env::consts::OS {
|
||||||
"linux" => Ok(Self::Some(match detect_linux_libc()? {
|
"linux" => {
|
||||||
LibcVersion::Manylinux { .. } => match std::env::consts::ARCH {
|
if let Ok(libc) = std::env::var(EnvVars::UV_LIBC) {
|
||||||
// Checks if the CPU supports hardware floating-point operations.
|
if !libc.is_empty() {
|
||||||
// Depending on the result, it selects either the `gnueabihf` (hard-float) or `gnueabi` (soft-float) environment.
|
return Self::from_str(&libc);
|
||||||
// download-metadata.json only includes armv7.
|
}
|
||||||
"arm" | "armv5te" | "armv7" => match detect_hardware_floating_point_support() {
|
}
|
||||||
Ok(true) => target_lexicon::Environment::Gnueabihf,
|
|
||||||
Ok(false) => target_lexicon::Environment::Gnueabi,
|
Ok(Self::Some(match detect_linux_libc()? {
|
||||||
Err(_) => target_lexicon::Environment::Gnu,
|
LibcVersion::Manylinux { .. } => match std::env::consts::ARCH {
|
||||||
|
// Checks if the CPU supports hardware floating-point operations.
|
||||||
|
// Depending on the result, it selects either the `gnueabihf` (hard-float) or `gnueabi` (soft-float) environment.
|
||||||
|
// download-metadata.json only includes armv7.
|
||||||
|
"arm" | "armv5te" | "armv7" => {
|
||||||
|
match detect_hardware_floating_point_support() {
|
||||||
|
Ok(true) => target_lexicon::Environment::Gnueabihf,
|
||||||
|
Ok(false) => target_lexicon::Environment::Gnueabi,
|
||||||
|
Err(_) => target_lexicon::Environment::Gnu,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => target_lexicon::Environment::Gnu,
|
||||||
},
|
},
|
||||||
_ => target_lexicon::Environment::Gnu,
|
LibcVersion::Musllinux { .. } => target_lexicon::Environment::Musl,
|
||||||
},
|
}))
|
||||||
LibcVersion::Musllinux { .. } => target_lexicon::Environment::Musl,
|
}
|
||||||
})),
|
|
||||||
"windows" | "macos" => Ok(Self::None),
|
"windows" | "macos" => Ok(Self::None),
|
||||||
// Use `None` on platforms without explicit support.
|
// Use `None` on platforms without explicit support.
|
||||||
_ => Ok(Self::None),
|
_ => Ok(Self::None),
|
||||||
|
|
|
||||||
|
|
@ -154,6 +154,10 @@ impl EnvVars {
|
||||||
/// `--no-python-downloads` option. Whether uv should allow Python downloads.
|
/// `--no-python-downloads` option. Whether uv should allow Python downloads.
|
||||||
pub const UV_PYTHON_DOWNLOADS: &'static str = "UV_PYTHON_DOWNLOADS";
|
pub const UV_PYTHON_DOWNLOADS: &'static str = "UV_PYTHON_DOWNLOADS";
|
||||||
|
|
||||||
|
/// Overrides the environment-determined libc on linux systems when filling in the current platform
|
||||||
|
/// within Python version requests. Options are: `gnu`, `gnueabi`, `gnueabihf`, `musl`, and `none`.
|
||||||
|
pub const UV_LIBC: &'static str = "UV_LIBC";
|
||||||
|
|
||||||
/// Equivalent to the `--compile-bytecode` command-line argument. If set, uv
|
/// Equivalent to the `--compile-bytecode` command-line argument. If set, uv
|
||||||
/// will compile Python source files to bytecode after installation.
|
/// will compile Python source files to bytecode after installation.
|
||||||
pub const UV_COMPILE_BYTECODE: &'static str = "UV_COMPILE_BYTECODE";
|
pub const UV_COMPILE_BYTECODE: &'static str = "UV_COMPILE_BYTECODE";
|
||||||
|
|
|
||||||
|
|
@ -167,6 +167,11 @@ Defaults to `~/.local/bin`.
|
||||||
Equivalent to the `--keyring-provider` command-line argument. If set, uv
|
Equivalent to the `--keyring-provider` command-line argument. If set, uv
|
||||||
will use this value as the keyring provider.
|
will use this value as the keyring provider.
|
||||||
|
|
||||||
|
### `UV_LIBC`
|
||||||
|
|
||||||
|
Overrides the environment-determined libc on linux systems when filling in the current platform
|
||||||
|
within Python version requests. Options are: `gnu`, `gnueabi`, `gnueabihf`, `musl`, and `none`.
|
||||||
|
|
||||||
### `UV_LINK_MODE`
|
### `UV_LINK_MODE`
|
||||||
|
|
||||||
Equivalent to the `--link-mode` command-line argument. If set, uv will use this as
|
Equivalent to the `--link-mode` command-line argument. If set, uv will use this as
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue