Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: improve error message for multiple sysconfigs found #1530

Merged
merged 1 commit into from
Mar 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,12 +392,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 @@ -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()
Expand Down Expand Up @@ -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)
});
}