Skip to content

Commit

Permalink
Add Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
mistydemeo committed Sep 19, 2023
1 parent 3b7f18e commit cd37107
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
38 changes: 38 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cargo-dist/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
4 changes: 4 additions & 0 deletions cargo-dist/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<minijinja::Error> for DistError {
Expand Down
13 changes: 13 additions & 0 deletions cargo-dist/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -876,6 +877,14 @@ fn do_ldd(path: &Utf8PathBuf) -> DistResult<Vec<String>> {
Ok(libraries)
}

fn do_pe(path: &Utf8PathBuf) -> DistResult<Vec<String>> {
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<Linkage> {
let libraries = match target {
// Can be run on any OS
Expand All @@ -890,6 +899,10 @@ fn determine_linkage(path: &Utf8PathBuf, target: &str) -> DistResult<Linkage> {
}
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 {}),
};

Expand Down

0 comments on commit cd37107

Please sign in to comment.