Skip to content

Commit

Permalink
Better error message when cargo didn't build a cdylib
Browse files Browse the repository at this point in the history
Fixes #1019
  • Loading branch information
messense committed Jul 20, 2022
1 parent 6ccca84 commit cdec6aa
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/build_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,16 +605,14 @@ impl BuildContext {
) -> Result<PathBuf> {
let artifacts = compile(self, python_interpreter, &self.bridge)
.context("Failed to build a native library through cargo")?;
let artifacts = artifacts
.get(0)
.context("Failed to build a native library through cargo")?;

let artifact = artifacts.get("cdylib").cloned().ok_or_else(|| {
anyhow!(
"Cargo didn't build a cdylib. Did you miss crate-type = [\"cdylib\"] \
in the lib section of your Cargo.toml?",
)
})?;
let error_msg = "Cargo didn't build a cdylib. Did you miss crate-type = [\"cdylib\"] \
in the lib section of your Cargo.toml?";
let artifacts = artifacts.get(0).context(error_msg)?;

let artifact = artifacts
.get("cdylib")
.cloned()
.ok_or_else(|| anyhow!(error_msg,))?;

if let Some(extension_name) = extension_name {
warn_missing_py_init(&artifact, extension_name)
Expand Down

0 comments on commit cdec6aa

Please sign in to comment.