Skip to content

Commit e730ef1

Browse files
authored
Patch additional sysconfig values such as clang at install time (#9916)
## Summary Minor follow up to #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 #9905 (comment)
1 parent 6dfe177 commit e730ef1

File tree

1 file changed

+73
-11
lines changed
  • crates/uv-python/src/sysconfig

1 file changed

+73
-11
lines changed

crates/uv-python/src/sysconfig/mod.rs

Lines changed: 73 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ mod parser;
4040
/// Replacement mode for sysconfig values.
4141
#[derive(Debug)]
4242
enum ReplacementMode {
43+
Partial { from: String },
4344
Full,
4445
}
4546

@@ -52,8 +53,13 @@ struct ReplacementEntry {
5253

5354
impl ReplacementEntry {
5455
/// Patches a sysconfig value either partially (replacing a specific word) or fully.
55-
fn patch(&self, _entry: &str) -> String {
56+
fn patch(&self, entry: &str) -> String {
5657
match &self.mode {
58+
ReplacementMode::Partial { from } => entry
59+
.split_whitespace()
60+
.map(|word| if word == from { &self.to } else { word })
61+
.collect::<Vec<_>>()
62+
.join(" "),
5763
ReplacementMode::Full => self.to.clone(),
5864
}
5965
}
@@ -62,13 +68,69 @@ impl ReplacementEntry {
6268
/// Mapping for sysconfig keys to lookup and replace with the appropriate entry.
6369
static DEFAULT_VARIABLE_UPDATES: LazyLock<BTreeMap<String, ReplacementEntry>> =
6470
LazyLock::new(|| {
65-
BTreeMap::from_iter([(
66-
"AR".to_string(),
67-
ReplacementEntry {
68-
mode: ReplacementMode::Full,
69-
to: "ar".to_string(),
70-
},
71-
)])
71+
BTreeMap::from_iter([
72+
(
73+
"CC".to_string(),
74+
ReplacementEntry {
75+
mode: ReplacementMode::Partial {
76+
from: "clang".to_string(),
77+
},
78+
to: "cc".to_string(),
79+
},
80+
),
81+
(
82+
"CXX".to_string(),
83+
ReplacementEntry {
84+
mode: ReplacementMode::Partial {
85+
from: "clang++".to_string(),
86+
},
87+
to: "c++".to_string(),
88+
},
89+
),
90+
(
91+
"BLDSHARED".to_string(),
92+
ReplacementEntry {
93+
mode: ReplacementMode::Partial {
94+
from: "clang".to_string(),
95+
},
96+
to: "cc".to_string(),
97+
},
98+
),
99+
(
100+
"LDSHARED".to_string(),
101+
ReplacementEntry {
102+
mode: ReplacementMode::Partial {
103+
from: "clang".to_string(),
104+
},
105+
to: "cc".to_string(),
106+
},
107+
),
108+
(
109+
"LDCXXSHARED".to_string(),
110+
ReplacementEntry {
111+
mode: ReplacementMode::Partial {
112+
from: "clang++".to_string(),
113+
},
114+
to: "c++".to_string(),
115+
},
116+
),
117+
(
118+
"LINKCC".to_string(),
119+
ReplacementEntry {
120+
mode: ReplacementMode::Partial {
121+
from: "clang".to_string(),
122+
},
123+
to: "cc".to_string(),
124+
},
125+
),
126+
(
127+
"AR".to_string(),
128+
ReplacementEntry {
129+
mode: ReplacementMode::Full,
130+
to: "ar".to_string(),
131+
},
132+
),
133+
])
72134
});
73135

74136
/// Update the `sysconfig` data in a Python installation.
@@ -292,8 +354,8 @@ mod tests {
292354
# system configuration generated and used by the sysconfig module
293355
build_time_vars = {
294356
"AR": "ar",
295-
"CC": "clang -pthread",
296-
"CXX": "clang++ -pthread",
357+
"CC": "cc -pthread",
358+
"CXX": "c++ -pthread",
297359
"PYTHON_BUILD_STANDALONE": 1
298360
}
299361
"###);
@@ -316,7 +378,7 @@ mod tests {
316378
insta::assert_snapshot!(data.to_string_pretty()?, @r###"
317379
# system configuration generated and used by the sysconfig module
318380
build_time_vars = {
319-
"BLDSHARED": "clang -bundle -undefined dynamic_lookup -arch arm64",
381+
"BLDSHARED": "cc -bundle -undefined dynamic_lookup -arch arm64",
320382
"PYTHON_BUILD_STANDALONE": 1
321383
}
322384
"###);

0 commit comments

Comments
 (0)