Skip to content

Patch additional sysconfig values such as clang at install time #9916

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 73 additions & 11 deletions crates/uv-python/src/sysconfig/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ mod parser;
/// Replacement mode for sysconfig values.
#[derive(Debug)]
enum ReplacementMode {
Partial { from: String },
Full,
}

Expand All @@ -52,8 +53,13 @@ struct ReplacementEntry {

impl ReplacementEntry {
/// 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 {
ReplacementMode::Partial { from } => entry
.split_whitespace()
.map(|word| if word == from { &self.to } else { word })
.collect::<Vec<_>>()
.join(" "),
ReplacementMode::Full => self.to.clone(),
}
}
Expand All @@ -62,13 +68,69 @@ impl ReplacementEntry {
/// Mapping for sysconfig keys to lookup and replace with the appropriate entry.
static DEFAULT_VARIABLE_UPDATES: LazyLock<BTreeMap<String, ReplacementEntry>> =
LazyLock::new(|| {
BTreeMap::from_iter([(
"AR".to_string(),
ReplacementEntry {
mode: ReplacementMode::Full,
to: "ar".to_string(),
},
)])
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(),
ReplacementEntry {
mode: ReplacementMode::Full,
to: "ar".to_string(),
},
),
])
});

/// Update the `sysconfig` data in a Python installation.
Expand Down Expand Up @@ -292,8 +354,8 @@ mod tests {
# system configuration generated and used by the sysconfig module
build_time_vars = {
"AR": "ar",
"CC": "clang -pthread",
"CXX": "clang++ -pthread",
"CC": "cc -pthread",
"CXX": "c++ -pthread",
"PYTHON_BUILD_STANDALONE": 1
}
"###);
Expand All @@ -316,7 +378,7 @@ mod tests {
insta::assert_snapshot!(data.to_string_pretty()?, @r###"
# system configuration generated and used by the sysconfig module
build_time_vars = {
"BLDSHARED": "clang -bundle -undefined dynamic_lookup -arch arm64",
"BLDSHARED": "cc -bundle -undefined dynamic_lookup -arch arm64",
"PYTHON_BUILD_STANDALONE": 1
}
"###);
Expand Down
Loading