Skip to content

Commit

Permalink
feat: implement wix
Browse files Browse the repository at this point in the history
  • Loading branch information
amr-crabnebula committed Sep 6, 2023
1 parent 06b6119 commit 8309a63
Show file tree
Hide file tree
Showing 22 changed files with 1,767 additions and 266 deletions.
10 changes: 10 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.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ serde_json = "1.0"
dunce = "1"
schemars = { version = "0.8", features = ["url", "preserve_order", "derive"] }
cargo-packager-config = { path = "crates/config", version = "0.0.0" }
clap = { version = "4.0", features = ["derive"] }
4 changes: 4 additions & 0 deletions crates/config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ description = "Config types for cargo-packager."
edition = "2021"
license = "Apache-2.0 OR MIT"

[features]
clap = ["dep:clap"]

[dependencies]
serde.workspace = true
schemars.workspace = true
clap = { workspace = true, optional = true }
23 changes: 12 additions & 11 deletions crates/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use serde::{Deserialize, Serialize};

/// The type of the package we're bundling.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Deserialize, Serialize, JsonSchema)]
#[cfg_attr(feature = "clap", derive(clap::ValueEnum))]
#[non_exhaustive]
#[serde(rename_all = "lowercase")]
pub enum PackageFormat {
Expand All @@ -14,8 +15,8 @@ pub enum PackageFormat {
Dmg,
/// The iOS app bundle.
Ios,
/// The Microsoft Software Installer (.msi).
Msi,
/// The Microsoft Software Installer (.msi) through WiX Toolset.
Wix,
/// The NSIS installer (.exe).
Nsis,
/// The Linux Debian package (.deb).
Expand All @@ -34,14 +35,14 @@ impl Display for PackageFormat {

impl PackageFormat {
/// Maps a short name to a [PackageFormat].
/// Possible values are "deb", "ios", "msi", "app", "rpm", "appimage", "dmg".
/// Possible values are "deb", "ios", "wix", "app", "rpm", "appimage", "dmg".
pub fn from_short_name(name: &str) -> Option<PackageFormat> {
// Other types we may eventually want to support: apk.
match name {
"app" => Some(PackageFormat::App),
"dmg" => Some(PackageFormat::Dmg),
"ios" => Some(PackageFormat::Ios),
"msi" => Some(PackageFormat::Msi),
"wix" => Some(PackageFormat::Wix),
"nsis" => Some(PackageFormat::Nsis),
"deb" => Some(PackageFormat::Deb),
"rpm" => Some(PackageFormat::Rpm),
Expand All @@ -56,7 +57,7 @@ impl PackageFormat {
PackageFormat::App => "app",
PackageFormat::Dmg => "dmg",
PackageFormat::Ios => "ios",
PackageFormat::Msi => "msi",
PackageFormat::Wix => "wix",
PackageFormat::Nsis => "nsis",
PackageFormat::Deb => "deb",
PackageFormat::Rpm => "rpm",
Expand All @@ -78,7 +79,7 @@ const ALL_PACKAGE_TYPES: &[PackageFormat] = &[
#[cfg(target_os = "macos")]
PackageFormat::Ios,
#[cfg(target_os = "windows")]
PackageFormat::Msi,
PackageFormat::Wix,
#[cfg(target_os = "windows")]
PackageFormat::Nsis,
#[cfg(any(
Expand Down Expand Up @@ -276,7 +277,7 @@ impl Default for WixLanguages {
}
}

/// Settings specific to the WiX implementation.
/// The wix format configuration
#[derive(Clone, Debug, Default, Deserialize, Serialize, JsonSchema)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct WixConfig {
Expand Down Expand Up @@ -359,7 +360,7 @@ impl Default for NSISInstallerMode {
}
}

/// Settings specific to the NSIS implementation.
/// The NSIS format configuration.
#[derive(Clone, Debug, Default, Deserialize, Serialize, JsonSchema)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct NsisConfig {
Expand Down Expand Up @@ -422,7 +423,7 @@ pub struct WindowsConfig {
/// use a TSP timestamp server, like e.g. SSL.com does. If so, enable TSP by setting to true.
#[serde(default)]
pub tsp: bool,
// TODO find an agnostic way to specify custom logic to install webview2
// TODO: find an agnostic way to specify custom logic to install webview2
// /// The installation mode for the Webview2 runtime.
// pub webview_install_mode: WebviewInstallMode,
// /// Path to the webview fixed runtime to use.
Expand Down Expand Up @@ -497,7 +498,7 @@ pub enum LogLevel {

impl Default for LogLevel {
fn default() -> Self {
Self::Info
Self::Error
}
}

Expand Down Expand Up @@ -568,7 +569,7 @@ pub struct Config {
/// The package types we're creating.
///
/// if not present, we'll use the PackageType list for the target OS.
pub format: Option<Vec<PackageFormat>>,
pub formats: Option<Vec<PackageFormat>>,
/// the directory where the packages will be placed.
#[serde(default, alias = "out-dir", alias = "out_dir")]
pub out_dir: PathBuf,
Expand Down
6 changes: 4 additions & 2 deletions crates/packager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license = "Apache-2.0 OR MIT"

[features]
default = ["cli"]
cli = ["env_logger", "clap"]
cli = ["env_logger", "clap", "cargo-packager-config/clap"]

[build-dependencies]
cargo-packager-config.workspace = true
Expand All @@ -24,7 +24,7 @@ serde_json.workspace = true
dunce.workspace = true
cargo_metadata = "0.17"
env_logger = { version = "0.9", optional = true }
clap = { version = "4.0", features = ["derive"], optional = true }
clap = { workspace = true, optional = true }
dirs = "5.0"
ureq = "2.7"
hex = "0.4"
Expand All @@ -39,6 +39,8 @@ relative-path = "1.9"
[target."cfg(target_os = \"windows\")".dependencies]
winreg = "0.51"
once_cell = "1.18"
uuid = { version = "1", features = ["v4", "v5"] }
regex = "1.9"

[target."cfg(target_os = \"windows\")".dependencies.windows-sys]
version = "0.48"
Expand Down
10 changes: 5 additions & 5 deletions crates/packager/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
}
]
},
"format": {
"formats": {
"description": "The package types we're creating.\n\nif not present, we'll use the PackageType list for the target OS.",
"type": [
"array",
Expand Down Expand Up @@ -363,10 +363,10 @@
]
},
{
"description": "The Microsoft Software Installer (.msi).",
"description": "The Microsoft Software Installer (.msi) through WiX Toolset.",
"type": "string",
"enum": [
"msi"
"wix"
]
},
{
Expand Down Expand Up @@ -621,7 +621,7 @@
"additionalProperties": false
},
"WixConfig": {
"description": "Settings specific to the WiX implementation.",
"description": "The wix format configuration",
"type": "object",
"properties": {
"languages": {
Expand Down Expand Up @@ -766,7 +766,7 @@
"additionalProperties": false
},
"NsisConfig": {
"description": "Settings specific to the NSIS implementation.",
"description": "The NSIS format configuration.",
"type": "object",
"properties": {
"template": {
Expand Down
31 changes: 27 additions & 4 deletions crates/packager/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ pub(crate) struct Resource {
pub target: PathBuf,
}

pub(crate) trait ConfigExtInternal {
fn resources(&self) -> Option<Vec<Resource>>;
}

pub trait ConfigExt {
/// Returns the windows specific configuration
fn windows(&self) -> Option<&WindowsConfig>;
/// Returns the nsis specific configuration
fn nsis(&self) -> Option<&NsisConfig>;
/// Returns the wix specific configuration
fn wix(&self) -> Option<&WixConfig>;
/// Returns the architecture for the binary being packaged (e.g. "arm", "x86" or "x86_64").
fn target_arch(&self) -> crate::Result<&str>;
/// Returns the path to the specified binary.
Expand All @@ -36,6 +34,10 @@ impl ConfigExt for Config {
self.nsis.as_ref()
}

fn wix(&self) -> Option<&WixConfig> {
self.wix.as_ref()
}

fn target_arch(&self) -> crate::Result<&str> {
Ok(if self.target_triple.starts_with("x86_64") {
"x86_64"
Expand Down Expand Up @@ -70,6 +72,11 @@ impl ConfigExt for Config {
}
}

pub(crate) trait ConfigExtInternal {
fn resources(&self) -> Option<Vec<Resource>>;
fn find_ico(&self) -> Option<PathBuf>;
}

impl ConfigExtInternal for Config {
fn resources(&self) -> Option<Vec<Resource>> {
self.resources.as_ref().map(|resources| {
Expand Down Expand Up @@ -111,4 +118,20 @@ impl ConfigExtInternal for Config {
out
})
}

fn find_ico(&self) -> Option<PathBuf> {
self.icons
.as_ref()
.and_then(|icons| {
icons
.iter()
.find(|i| PathBuf::from(i).extension().and_then(|s| s.to_str()) == Some("ico"))
.or_else(|| {
icons.iter().find(|i| {
PathBuf::from(i).extension().and_then(|s| s.to_str()) == Some("png")
})
})
})
.map(PathBuf::from)
}
}
17 changes: 17 additions & 0 deletions crates/packager/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,27 @@ pub enum Error {
/// Nsis error
#[error("error running makensis.exe: {0}")]
NsisFailed(String),
/// Nsis error
#[error("error running {0}: {0}")]
WixFailed(String, String),
/// Failed to get parent directory of a path
#[error("Failed to get parent directory of a path")]
ParentDirNotFound,
#[error("{0} `{1}` failed with exit code {2}")]
HookCommandFailure(String, String, i32),
/// Regex error.
#[cfg(windows)]
#[error(transparent)]
RegexError(#[from] regex::Error),
/// Glob pattern error.
#[error(transparent)]
GlobPatternError(#[from] glob::PatternError),
/// Glob error.
#[error(transparent)]
Glob(#[from] glob::GlobError),
/// Unsupported WiX language
#[error("Language {0} not found. It must be one of {1}")]
UnsupportedWixLanguage(String, String),
}

/// Convenient type alias of Result type for cargo-packager.
Expand Down
8 changes: 4 additions & 4 deletions crates/packager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ mod dmg;
mod error;
#[cfg(target_os = "macos")]
mod ios;
#[cfg(windows)]
mod msi;
mod nsis;
#[cfg(any(
target_os = "linux",
Expand All @@ -49,6 +47,8 @@ mod nsis;
mod rpm;
mod sign;
pub mod util;
#[cfg(windows)]
mod wix;

use std::{path::PathBuf, process::Command};

Expand Down Expand Up @@ -92,7 +92,7 @@ pub fn package(config: &Config) -> Result<Vec<Package>> {
let mut packages = Vec::new();

let formats = config
.format
.formats
.clone()
.unwrap_or_else(|| PackageFormat::all().to_vec());

Expand Down Expand Up @@ -161,7 +161,7 @@ pub fn package(config: &Config) -> Result<Vec<Package>> {
#[cfg(target_os = "macos")]
PackageFormat::Ios => ios::package(config),
#[cfg(target_os = "windows")]
PackageFormat::Msi => msi::package(config),
PackageFormat::Wix => wix::package(config),
PackageFormat::Nsis => nsis::package(config),
#[cfg(any(
target_os = "linux",
Expand Down
Loading

0 comments on commit 8309a63

Please sign in to comment.