From cd37107d2dc6b9ea83671a479d2b2b319838a07b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Misty=20De=20M=C3=A9o?= Date: Tue, 19 Sep 2023 15:53:54 -0700 Subject: [PATCH] Add Windows --- Cargo.lock | 38 ++++++++++++++++++++++++++++++++++++++ cargo-dist/Cargo.toml | 1 + cargo-dist/src/errors.rs | 4 ++++ cargo-dist/src/lib.rs | 13 +++++++++++++ 4 files changed, 56 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index a49c00d8f..b6e5a5389 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -305,6 +305,7 @@ dependencies = [ "cruet", "dialoguer", "flate2", + "goblin", "guppy", "include_dir", "insta", @@ -828,6 +829,17 @@ version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" +[[package]] +name = "goblin" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f27c1b4369c2cd341b5de549380158b105a04c331be5db9110eef7b6d2742134" +dependencies = [ + "log 0.4.20", + "plain", + "scroll", +] + [[package]] name = "guppy" version = "0.15.2" @@ -1499,6 +1511,12 @@ version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" +[[package]] +name = "plain" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" + [[package]] name = "proc-macro2" version = "1.0.66" @@ -1719,6 +1737,26 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "scroll" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04c565b551bafbef4157586fa379538366e4385d42082f255bfd96e4fe8519da" +dependencies = [ + "scroll_derive", +] + +[[package]] +name = "scroll_derive" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1db149f81d46d2deba7cd3c50772474707729550221e69588478ebf9ada425ae" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.31", +] + [[package]] name = "sct" version = "0.7.0" diff --git a/cargo-dist/Cargo.toml b/cargo-dist/Cargo.toml index 7309aa034..99cf38992 100644 --- a/cargo-dist/Cargo.toml +++ b/cargo-dist/Cargo.toml @@ -54,6 +54,7 @@ itertools = "0.11.0" cargo-wix = "0.3.6" uuid = { version = "1", features = ["v4"] } mach_object = "0.1" +goblin = "0.7.1" [dev-dependencies] insta = { version = "1.26.0", features = ["filters"] } diff --git a/cargo-dist/src/errors.rs b/cargo-dist/src/errors.rs index cf389b155..23b0a05a0 100644 --- a/cargo-dist/src/errors.rs +++ b/cargo-dist/src/errors.rs @@ -240,6 +240,10 @@ pub enum DistError { /// Linkage report can't be run for this target #[error("unable to run linkage report for this type of binary")] LinkageCheckUnsupportedBinary {}, + + /// random i/o error + #[error(transparent)] + Goblin(#[from] goblin::error::Error), } impl From for DistError { diff --git a/cargo-dist/src/lib.rs b/cargo-dist/src/lib.rs index 3d06349f0..2cfca1940 100644 --- a/cargo-dist/src/lib.rs +++ b/cargo-dist/src/lib.rs @@ -28,6 +28,7 @@ use cargo_dist_schema::{Asset, AssetKind, DistManifest, ExecutableAsset}; use config::{ ArtifactMode, ChecksumStyle, CompressionImpl, Config, DirtyMode, GenerateMode, ZipStyle, }; +use goblin::Object; use mach_object::{LoadCommand, OFile}; use semver::Version; use serde::Serialize; @@ -876,6 +877,14 @@ fn do_ldd(path: &Utf8PathBuf) -> DistResult> { Ok(libraries) } +fn do_pe(path: &Utf8PathBuf) -> DistResult> { + let buf = std::fs::read(path)?; + match Object::parse(&buf)? { + Object::PE(pe) => Ok(pe.libraries.into_iter().map(|s| s.to_owned()).collect()), + _ => Err(DistError::LinkageCheckUnsupportedBinary {}), + } +} + fn determine_linkage(path: &Utf8PathBuf, target: &str) -> DistResult { let libraries = match target { // Can be run on any OS @@ -890,6 +899,10 @@ fn determine_linkage(path: &Utf8PathBuf, target: &str) -> DistResult { } do_ldd(path)? } + // Can be run on any OS + "i686-pc-windows-msvc" | "x86_64-pc-windows-msvc" | "aarch64-pc-windows-msvc" => { + do_pe(path)? + } _ => return Err(DistError::LinkageCheckUnsupportedBinary {}), };