From f89756238a69b887e2e1628c97afb885140256e9 Mon Sep 17 00:00:00 2001 From: David Hewitt <1939362+davidhewitt@users.noreply.github.com> Date: Mon, 29 Mar 2021 08:37:27 +0100 Subject: [PATCH] build: improve error message for multiple sysconfigs found --- build.rs | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/build.rs b/build.rs index 08c3099650d..2a2ec184d94 100644 --- a/build.rs +++ b/build.rs @@ -392,12 +392,16 @@ fn find_sysconfigdata(cross: &CrossCompileConfig) -> Result { 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 or set the _PYTHON_SYSCONFIGDATA_NAME \ - variable to the wanted sysconfigdata file name\nsysconfigdata paths = {:?}", - sysconfig_paths - ) + let mut error_msg = String::from( + "Detected multiple possible Python versions. Please set either the \ + PYO3_CROSS_PYTHON_VERSION variable to the wanted version or the \ + _PYTHON_SYSCONFIGDATA_NAME variable to the wanted sysconfigdata file name.\n\n\ + sysconfigdata files found:", + ); + for path in sysconfig_paths { + error_msg += &format!("\n\t{}", path.display()); + } + bail!("{}", error_msg); } Ok(sysconfig_paths.remove(0)) @@ -843,7 +847,7 @@ fn abi3_without_interpreter() -> Result<()> { Ok(()) } -fn main() -> Result<()> { +fn main_impl() -> Result<()> { // If PYO3_NO_PYTHON is set with abi3, we can build PyO3 without calling Python. // We only check for the abi3-py3{ABI3_MAX_MINOR} because lower versions depend on it. if env::var_os("PYO3_NO_PYTHON").is_some() @@ -904,3 +908,11 @@ fn main() -> Result<()> { Ok(()) } + +fn main() { + // Print out error messages using display, to get nicer formatting. + let _ = main_impl().map_err(|e| { + eprintln!("Error: {}", e); + std::process::exit(1) + }); +}