From b9a2c64157dbb3bde47aa1394a632ef11ff09df2 Mon Sep 17 00:00:00 2001 From: messense Date: Wed, 10 Mar 2021 17:20:50 +0800 Subject: [PATCH] Use _PYTHON_SYSCONFIGDATA_NAME in find_sysconfigdata when cross-compiling --- build.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/build.rs b/build.rs index 7db5782a..32533bb6 100644 --- a/build.rs +++ b/build.rs @@ -407,12 +407,18 @@ fn find_sysconfigdata(cross: &CrossCompileConfig) -> Result { "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))