mirror of
https://github.com/astral-sh/uv.git
synced 2025-09-28 04:54:47 +00:00
Patch additional sysconfig values such as clang at install time (#9916)
## Summary Minor follow up to https://github.com/astral-sh/uv/pull/9905 to patch `clang` with `cc`. Implements the replacements used in [sysconfigpatcher](https://github.com/bluss/sysconfigpatcher/blob/main/src/sysconfigpatcher.py#L54), namely ```python DEFAULT_VARIABLE_UPDATES = { "CC": WordReplace("clang", "cc"), "CXX": WordReplace("clang++", "c++"), "BLDSHARED": WordReplace("clang", "cc"), "LDSHARED": WordReplace("clang", "cc"), "LDCXXSHARED": WordReplace("clang++", "c++"), "LINKCC": WordReplace("clang", "cc"), "AR": "ar", } ``` ## Test Plan Added an additional test. Tested local python installs. Related traces ``` TRACE Updated `AR` from `/tools/clang-linux64/bin/llvm-ar` to `ar` TRACE Updated `CC` from `clang -pthread` to `cc -pthread` TRACE Updated `CXX` from `clang++ -pthread` to `c++ -pthread` TRACE Updated `BLDSHARED` from `clang -pthread -shared -L/tools/deps/lib` to `cc -pthread -shared -L/tools/deps/lib` TRACE Updated `LDSHARED` from `clang -pthread -shared -L/tools/deps/lib` to `cc -pthread -shared -L/tools/deps/lib` TRACE Updated `LDCXXSHARED` from `clang++ -pthread -shared` to `c++ -pthread -shared` TRACE Updated `LINKCC` from `clang -pthread` to `cc -pthread ``` ## Pending Discussion Items https://github.com/astral-sh/uv/pull/9905#issuecomment-2543879587
This commit is contained in:
parent
6dfe1774e8
commit
e730ef19f1
1 changed files with 73 additions and 11 deletions
|
@ -40,6 +40,7 @@ mod parser;
|
||||||
/// Replacement mode for sysconfig values.
|
/// Replacement mode for sysconfig values.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum ReplacementMode {
|
enum ReplacementMode {
|
||||||
|
Partial { from: String },
|
||||||
Full,
|
Full,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,8 +53,13 @@ struct ReplacementEntry {
|
||||||
|
|
||||||
impl ReplacementEntry {
|
impl ReplacementEntry {
|
||||||
/// Patches a sysconfig value either partially (replacing a specific word) or fully.
|
/// Patches a sysconfig value either partially (replacing a specific word) or fully.
|
||||||
fn patch(&self, _entry: &str) -> String {
|
fn patch(&self, entry: &str) -> String {
|
||||||
match &self.mode {
|
match &self.mode {
|
||||||
|
ReplacementMode::Partial { from } => entry
|
||||||
|
.split_whitespace()
|
||||||
|
.map(|word| if word == from { &self.to } else { word })
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join(" "),
|
||||||
ReplacementMode::Full => self.to.clone(),
|
ReplacementMode::Full => self.to.clone(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,13 +68,69 @@ impl ReplacementEntry {
|
||||||
/// Mapping for sysconfig keys to lookup and replace with the appropriate entry.
|
/// Mapping for sysconfig keys to lookup and replace with the appropriate entry.
|
||||||
static DEFAULT_VARIABLE_UPDATES: LazyLock<BTreeMap<String, ReplacementEntry>> =
|
static DEFAULT_VARIABLE_UPDATES: LazyLock<BTreeMap<String, ReplacementEntry>> =
|
||||||
LazyLock::new(|| {
|
LazyLock::new(|| {
|
||||||
BTreeMap::from_iter([(
|
BTreeMap::from_iter([
|
||||||
|
(
|
||||||
|
"CC".to_string(),
|
||||||
|
ReplacementEntry {
|
||||||
|
mode: ReplacementMode::Partial {
|
||||||
|
from: "clang".to_string(),
|
||||||
|
},
|
||||||
|
to: "cc".to_string(),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"CXX".to_string(),
|
||||||
|
ReplacementEntry {
|
||||||
|
mode: ReplacementMode::Partial {
|
||||||
|
from: "clang++".to_string(),
|
||||||
|
},
|
||||||
|
to: "c++".to_string(),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"BLDSHARED".to_string(),
|
||||||
|
ReplacementEntry {
|
||||||
|
mode: ReplacementMode::Partial {
|
||||||
|
from: "clang".to_string(),
|
||||||
|
},
|
||||||
|
to: "cc".to_string(),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"LDSHARED".to_string(),
|
||||||
|
ReplacementEntry {
|
||||||
|
mode: ReplacementMode::Partial {
|
||||||
|
from: "clang".to_string(),
|
||||||
|
},
|
||||||
|
to: "cc".to_string(),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"LDCXXSHARED".to_string(),
|
||||||
|
ReplacementEntry {
|
||||||
|
mode: ReplacementMode::Partial {
|
||||||
|
from: "clang++".to_string(),
|
||||||
|
},
|
||||||
|
to: "c++".to_string(),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"LINKCC".to_string(),
|
||||||
|
ReplacementEntry {
|
||||||
|
mode: ReplacementMode::Partial {
|
||||||
|
from: "clang".to_string(),
|
||||||
|
},
|
||||||
|
to: "cc".to_string(),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
(
|
||||||
"AR".to_string(),
|
"AR".to_string(),
|
||||||
ReplacementEntry {
|
ReplacementEntry {
|
||||||
mode: ReplacementMode::Full,
|
mode: ReplacementMode::Full,
|
||||||
to: "ar".to_string(),
|
to: "ar".to_string(),
|
||||||
},
|
},
|
||||||
)])
|
),
|
||||||
|
])
|
||||||
});
|
});
|
||||||
|
|
||||||
/// Update the `sysconfig` data in a Python installation.
|
/// Update the `sysconfig` data in a Python installation.
|
||||||
|
@ -292,8 +354,8 @@ mod tests {
|
||||||
# system configuration generated and used by the sysconfig module
|
# system configuration generated and used by the sysconfig module
|
||||||
build_time_vars = {
|
build_time_vars = {
|
||||||
"AR": "ar",
|
"AR": "ar",
|
||||||
"CC": "clang -pthread",
|
"CC": "cc -pthread",
|
||||||
"CXX": "clang++ -pthread",
|
"CXX": "c++ -pthread",
|
||||||
"PYTHON_BUILD_STANDALONE": 1
|
"PYTHON_BUILD_STANDALONE": 1
|
||||||
}
|
}
|
||||||
"###);
|
"###);
|
||||||
|
@ -316,7 +378,7 @@ mod tests {
|
||||||
insta::assert_snapshot!(data.to_string_pretty()?, @r###"
|
insta::assert_snapshot!(data.to_string_pretty()?, @r###"
|
||||||
# system configuration generated and used by the sysconfig module
|
# system configuration generated and used by the sysconfig module
|
||||||
build_time_vars = {
|
build_time_vars = {
|
||||||
"BLDSHARED": "clang -bundle -undefined dynamic_lookup -arch arm64",
|
"BLDSHARED": "cc -bundle -undefined dynamic_lookup -arch arm64",
|
||||||
"PYTHON_BUILD_STANDALONE": 1
|
"PYTHON_BUILD_STANDALONE": 1
|
||||||
}
|
}
|
||||||
"###);
|
"###);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue