Use _PYTHON_SYSCONFIGDATA_NAME in find_sysconfigdata when cross-compiling

This commit is contained in:
messense 2021-03-10 17:20:50 +08:00
parent 5014b60e5e
commit b9a2c64157
1 changed files with 12 additions and 6 deletions

View File

@ -407,12 +407,18 @@ fn find_sysconfigdata(cross: &CrossCompileConfig) -> Result<PathBuf> {
"Could not find either libpython.so or _sysconfigdata*.py in {}",
cross.lib_dir.display()
);
} else if sysconfig_paths.len() > 1 {
bail!(
"Detected multiple possible python versions, please set the PYO3_PYTHON_VERSION \
variable to the wanted version on your system\nsysconfigdata paths = {:?}",
sysconfig_paths
)
} else {
if let Some(sysconfig_name) = env::var_os("_PYTHON_SYSCONFIGDATA_NAME") {
sysconfig_paths.retain(|p| *p == Path::new(&sysconfig_name).with_extension("py"));
}
if sysconfig_paths.len() > 1 {
bail!(
"Detected multiple possible python versions, please set the PYO3_PYTHON_VERSION \
variable to the wanted version on your system or set the _PYTHON_SYSCONFIGDATA_NAME \
variable to the wanted sysconfigdata file name\nsysconfigdata paths = {:?}",
sysconfig_paths
)
}
}
Ok(sysconfig_paths.remove(0))