Patch sysconfig data at install time (#9857)

## Summary

This PR reimplements
[`sysconfigpatcher`](https://github.com/bluss/sysconfigpatcher) in Rust
and applies it to our Python installations at install-time, ensuring
that the `sysconfig` data is more likely to be correct.

For now, we only rewrite prefixes (i.e., any path that starts with
`/install` gets rewritten to the correct absolute path for the current
machine).

Unlike `sysconfigpatcher`, this PR does not yet do any of the following:

- Patch `pkginfo` files.
- Change `clang` references to `cc`.

A few things that we should do as follow-ups, in my opinion:

1. Rewrite
[`AR`](c1ebf8ab92/src/sysconfigpatcher.py (L61)).
2. Remove `-isysroot`, which we already do for newer builds.
This commit is contained in:
Charlie Marsh 2024-12-13 14:36:22 -05:00 committed by GitHub
parent 5903ce5759
commit d2fb4c585d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 817 additions and 19 deletions

View file

@ -46,7 +46,7 @@ pub struct Interpreter {
sys_executable: PathBuf,
sys_path: Vec<PathBuf>,
stdlib: PathBuf,
sysconfig_prefix: Option<PathBuf>,
standalone: bool,
tags: OnceLock<Tags>,
target: Option<Target>,
prefix: Option<Prefix>,
@ -80,7 +80,7 @@ impl Interpreter {
sys_executable: info.sys_executable,
sys_path: info.sys_path,
stdlib: info.stdlib,
sysconfig_prefix: info.sysconfig_prefix,
standalone: info.standalone,
tags: OnceLock::new(),
target: None,
prefix: None,
@ -368,11 +368,6 @@ impl Interpreter {
&self.stdlib
}
/// Return the `prefix` path for this Python interpreter, as returned by `sysconfig.get_config_var("prefix")`.
pub fn sysconfig_prefix(&self) -> Option<&Path> {
self.sysconfig_prefix.as_deref()
}
/// Return the `purelib` path for this Python interpreter, as returned by `sysconfig.get_paths()`.
pub fn purelib(&self) -> &Path {
&self.scheme.purelib
@ -441,8 +436,7 @@ impl Interpreter {
///
/// See: <https://github.com/indygreg/python-build-standalone/issues/382>
pub fn is_standalone(&self) -> bool {
self.sysconfig_prefix()
.is_some_and(|prefix| prefix == Path::new("/install"))
self.standalone
}
/// Return the [`Layout`] environment used to install wheels into this interpreter.
@ -626,7 +620,7 @@ struct InterpreterInfo {
sys_executable: PathBuf,
sys_path: Vec<PathBuf>,
stdlib: PathBuf,
sysconfig_prefix: Option<PathBuf>,
standalone: bool,
pointer_size: PointerSize,
gil_disabled: bool,
}
@ -854,6 +848,7 @@ mod tests {
"arch": "x86_64"
},
"manylinux_compatible": false,
"standalone": false,
"markers": {
"implementation_name": "cpython",
"implementation_version": "3.12.0",