Skip to content

Commit bc826d1

Browse files
authored
Merge pull request #1530 from davidhewitt/build-error-messages
build: improve error message for multiple sysconfigs found
2 parents 2939bf1 + f897562 commit bc826d1

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

build.rs

+19-7
Original file line numberDiff line numberDiff line change
@@ -390,12 +390,16 @@ fn find_sysconfigdata(cross: &CrossCompileConfig) -> Result<PathBuf> {
390390
cross.lib_dir.display()
391391
);
392392
} else if sysconfig_paths.len() > 1 {
393-
bail!(
394-
"Detected multiple possible python versions, please set the PYO3_PYTHON_VERSION \
395-
variable to the wanted version on your system or set the _PYTHON_SYSCONFIGDATA_NAME \
396-
variable to the wanted sysconfigdata file name\nsysconfigdata paths = {:?}",
397-
sysconfig_paths
398-
)
393+
let mut error_msg = String::from(
394+
"Detected multiple possible Python versions. Please set either the \
395+
PYO3_CROSS_PYTHON_VERSION variable to the wanted version or the \
396+
_PYTHON_SYSCONFIGDATA_NAME variable to the wanted sysconfigdata file name.\n\n\
397+
sysconfigdata files found:",
398+
);
399+
for path in sysconfig_paths {
400+
error_msg += &format!("\n\t{}", path.display());
401+
}
402+
bail!("{}", error_msg);
399403
}
400404

401405
Ok(sysconfig_paths.remove(0))
@@ -846,7 +850,7 @@ fn abi3_without_interpreter() -> Result<()> {
846850
Ok(())
847851
}
848852

849-
fn main() -> Result<()> {
853+
fn main_impl() -> Result<()> {
850854
// If PYO3_NO_PYTHON is set with abi3, we can build PyO3 without calling Python.
851855
// We only check for the abi3-py3{ABI3_MAX_MINOR} because lower versions depend on it.
852856
if env::var_os("PYO3_NO_PYTHON").is_some()
@@ -914,3 +918,11 @@ fn main() -> Result<()> {
914918

915919
Ok(())
916920
}
921+
922+
fn main() {
923+
// Print out error messages using display, to get nicer formatting.
924+
let _ = main_impl().map_err(|e| {
925+
eprintln!("Error: {}", e);
926+
std::process::exit(1)
927+
});
928+
}

0 commit comments

Comments
 (0)