diff --git a/Cargo.lock b/Cargo.lock index 80fae15..e1733ee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -55,12 +55,22 @@ dependencies = [ "serde", ] +[[package]] +name = "camino" +version = "1.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c59e92b5a388f549b863a7bea62612c09f24c8393560709a54558a9abdfb3b9c" +dependencies = [ + "serde", +] + [[package]] name = "cargo-fuzz" version = "0.11.2" dependencies = [ "anyhow", "assert_cmd", + "cargo_metadata", "clap", "current_platform", "predicates", @@ -69,6 +79,29 @@ dependencies = [ "toml", ] +[[package]] +name = "cargo-platform" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e34637b3140142bdf929fb439e8aa4ebad7651ebf7b1080b3930aa16ac1459ff" +dependencies = [ + "serde", +] + +[[package]] +name = "cargo_metadata" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d886547e41f740c616ae73108f6eb70afe6d940c7bc697cb30f13daec073037" +dependencies = [ + "camino", + "cargo-platform", + "semver", + "serde", + "serde_json", + "thiserror", +] + [[package]] name = "cc" version = "1.0.77" @@ -106,7 +139,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn", + "syn 1.0.105", ] [[package]] @@ -236,6 +269,12 @@ dependencies = [ "either", ] +[[package]] +name = "itoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" + [[package]] name = "libc" version = "0.2.138" @@ -320,7 +359,7 @@ dependencies = [ "proc-macro-error-attr", "proc-macro2", "quote", - "syn", + "syn 1.0.105", "version_check", ] @@ -337,18 +376,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.47" +version = "1.0.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725" +checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.21" +version = "1.0.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" dependencies = [ "proc-macro2", ] @@ -417,17 +456,51 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "ryu" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" + [[package]] name = "semver" version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e25dfac463d778e353db5be2449d1cce89bd6fd23c9f1ea21310ce6e5a1b29c4" +dependencies = [ + "serde", +] [[package]] name = "serde" -version = "1.0.149" +version = "1.0.193" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "256b9932320c590e707b94576e3cc1f7c9024d0ee6612dfbcf1cb106cbe8e055" +checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.193" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] + +[[package]] +name = "serde_json" +version = "1.0.108" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b" +dependencies = [ + "itoa", + "ryu", + "serde", +] [[package]] name = "strsim" @@ -446,6 +519,17 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "syn" +version = "2.0.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "tempfile" version = "3.3.0" @@ -475,6 +559,26 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95059e91184749cb66be6dc994f67f182b6d897cb3df74a5bf66b5e709295fd8" +[[package]] +name = "thiserror" +version = "1.0.50" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.50" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] + [[package]] name = "toml" version = "0.5.9" diff --git a/Cargo.toml b/Cargo.toml index ae30e61..606f101 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,6 +19,7 @@ clap = { version = "4.0.29", features = ["derive", "deprecated"] } tempfile = "3.3.0" toml = "0.5.9" rustc_version = "0.4.0" +cargo_metadata = "0.18.1" [dev-dependencies] assert_cmd = "2.0.7" diff --git a/src/project.rs b/src/project.rs index b4da718..ac38baa 100644 --- a/src/project.rs +++ b/src/project.rs @@ -1,6 +1,7 @@ use crate::options::{self, BuildMode, BuildOptions, Sanitizer}; use crate::utils::default_target; use anyhow::{anyhow, bail, Context, Result}; +use cargo_metadata::MetadataCommand; use std::collections::HashSet; use std::io::Read; use std::io::Write; @@ -931,25 +932,34 @@ pub struct Manifest { impl Manifest { pub fn parse(path: &Path) -> Result { - let contents = fs::read(path)?; - let value: toml::Value = toml::from_slice(&contents)?; - let package = value - .as_table() - .and_then(|v| v.get("package")) - .and_then(toml::Value::as_table); - let crate_name = package - .and_then(|v| v.get("name")) - .and_then(toml::Value::as_str) - .with_context(|| anyhow!("{} (package.name) is malformed", path.display()))? - .to_owned(); - let edition = package - .expect("can't be None at this point") - .get("edition") - .map(|v| match v.as_str() { - Some(s) => Ok(s.to_owned()), - None => bail!("{} (package.edition) is malformed", path.display()), - }) - .transpose()?; + let metatdata = MetadataCommand::new().exec().unwrap(); + let package = metatdata + .packages + .iter() + .find(|p| p.manifest_path == path) + .unwrap(); + let crate_name = package.name.clone(); + let edition = Some(String::from(package.edition.as_str())); + + // let contents = fs::read(path)?; + // let value: toml::Value = toml::from_slice(&contents)?; + // let package = value + // .as_table() + // .and_then(|v| v.get("package")) + // .and_then(toml::Value::as_table); + // let crate_name = package + // .and_then(|v| v.get("name")) + // .and_then(toml::Value::as_str) + // .with_context(|| anyhow!("{} (package.name) is malformed", path.display()))? + // .to_owned(); + // let edition = package + // .expect("can't be None at this point") + // .get("edition") + // .map(|v| match v.as_str() { + // Some(s) => Ok(s.to_owned()), + // None => bail!("{} (package.edition) is malformed", path.display()), + // }) + // .transpose()?; Ok(Manifest { crate_name, edition,