Skip to content

Commit

Permalink
Merge pull request #1530 from davidhewitt/build-error-messages
Browse files Browse the repository at this point in the history
build: improve error message for multiple sysconfigs found
  • Loading branch information
davidhewitt authored Mar 30, 2021
2 parents 2939bf1 + f897562 commit bc826d1
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,12 +390,16 @@ fn find_sysconfigdata(cross: &CrossCompileConfig) -> Result<PathBuf> {
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))
Expand Down Expand Up @@ -846,7 +850,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()
Expand Down Expand Up @@ -914,3 +918,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)
});
}

0 comments on commit bc826d1

Please sign in to comment.