From 722f5f23590d22caa5aee074b0ebf517ef8204e5 Mon Sep 17 00:00:00 2001 From: messense Date: Tue, 27 Sep 2022 14:52:43 +0800 Subject: [PATCH] Fix resolving crate name bug --- src/build_options.rs | 3 ++- src/cargo_toml.rs | 1 + src/project_layout.rs | 5 ++++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/build_options.rs b/src/build_options.rs index c63effba3..7fd5f620d 100644 --- a/src/build_options.rs +++ b/src/build_options.rs @@ -488,6 +488,7 @@ impl BuildOptions { let ProjectResolver { project_layout, cargo_toml_path, + cargo_toml, pyproject_toml_path, pyproject_toml, module_name, @@ -684,7 +685,7 @@ impl BuildOptions { .target_dir .clone() .unwrap_or_else(|| cargo_metadata.target_directory.clone().into_std_path_buf()); - let crate_name = metadata21.name.clone(); + let crate_name = cargo_toml.package.name; Ok(BuildContext { target, diff --git a/src/cargo_toml.rs b/src/cargo_toml.rs index 4bfff0f7c..6f3dd0d27 100644 --- a/src/cargo_toml.rs +++ b/src/cargo_toml.rs @@ -16,6 +16,7 @@ pub(crate) struct CargoTomlLib { #[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)] #[serde(rename_all = "kebab-case")] pub(crate) struct CargoTomlPackage { + pub(crate) name: String, metadata: Option, } diff --git a/src/project_layout.rs b/src/project_layout.rs index 98b882ce3..9c87f380f 100644 --- a/src/project_layout.rs +++ b/src/project_layout.rs @@ -31,6 +31,8 @@ pub struct ProjectResolver { pub project_layout: ProjectLayout, /// Cargo.toml path pub cargo_toml_path: PathBuf, + /// Parsed Cargo.toml + pub cargo_toml: CargoToml, /// pyproject.toml path pub pyproject_toml_path: PathBuf, /// Parsed pyproject.toml @@ -94,7 +96,7 @@ impl ProjectResolver { } let extra_metadata = cargo_toml.remaining_core_metadata(); - let crate_name = &metadata21.name; + let crate_name = &cargo_toml.package.name; // If the package name contains minuses, you must declare a module with // underscores as lib name @@ -145,6 +147,7 @@ impl ProjectResolver { Ok(Self { project_layout, cargo_toml_path: manifest_file, + cargo_toml, pyproject_toml_path: pyproject_file, pyproject_toml, module_name,