Skip to content

Commit

Permalink
feat: implement deb
Browse files Browse the repository at this point in the history
  • Loading branch information
amr-crabnebula committed Sep 8, 2023
1 parent 783603b commit 7e6620b
Show file tree
Hide file tree
Showing 15 changed files with 1,357 additions and 204 deletions.
294 changes: 293 additions & 1 deletion Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions crates/config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ clap = ["dep:clap"]
serde.workspace = true
schemars.workspace = true
clap = { workspace = true, optional = true }
strsim = "0.10"
465 changes: 465 additions & 0 deletions crates/config/src/category.rs

Large diffs are not rendered by default.

60 changes: 4 additions & 56 deletions crates/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ use std::{collections::HashMap, fmt::Display, path::PathBuf};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

/// The type of the package we're bundling.
mod category;
pub use category::AppCategory;

/// The type of the package we're packaging.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Deserialize, Serialize, JsonSchema)]
#[cfg_attr(feature = "clap", derive(clap::ValueEnum))]
#[non_exhaustive]
Expand Down Expand Up @@ -108,58 +111,6 @@ const ALL_PACKAGE_TYPES: &[PackageFormat] = &[
PackageFormat::AppImage,
];

// TODO: Right now, these categories correspond to LSApplicationCategoryType
// values for OS X. There are also some additional GNOME registered categories
// that don't fit these; we should add those here too.
/// The possible app categories.
/// Corresponds to `LSApplicationCategoryType` on macOS and the GNOME desktop categories on Debian.
#[allow(missing_docs)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, Deserialize, Serialize, JsonSchema)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[non_exhaustive]
pub enum AppCategory {
Business,
DeveloperTool,
Education,
Entertainment,
Finance,
Game,
ActionGame,
AdventureGame,
ArcadeGame,
BoardGame,
CardGame,
CasinoGame,
DiceGame,
EducationalGame,
FamilyGame,
KidsGame,
MusicGame,
PuzzleGame,
RacingGame,
RolePlayingGame,
SimulationGame,
SportsGame,
StrategyGame,
TriviaGame,
WordGame,
GraphicsAndDesign,
HealthcareAndFitness,
Lifestyle,
Medical,
Music,
News,
Photography,
Productivity,
Reference,
SocialNetworking,
Sports,
Travel,
Utility,
Video,
Weather,
}

/// **macOS-only**. Corresponds to CFBundleTypeRole
#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
Expand Down Expand Up @@ -206,9 +157,6 @@ pub struct FileAssociation {
pub struct DebianConfig {
/// the list of debian dependencies.
pub depends: Option<Vec<String>>,
/// List of custom files to add to the deb package.
/// Maps the path on the debian package to the path of the file to include (relative to the current working directory).
pub files: Option<HashMap<PathBuf, PathBuf>>,
/// Path to a custom desktop file Handlebars template.
///
/// Available variables: `categories`, `comment` (optional), `exec`, `icon` and `name`.
Expand Down
9 changes: 9 additions & 0 deletions crates/packager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,12 @@ regex = "1.9"
[target."cfg(target_os = \"windows\")".dependencies.windows-sys]
version = "0.48"
features = ["Win32_System_SystemInformation", "Win32_System_Diagnostics_Debug"]

[target."cfg(any(target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"netbsd\", target_os = \"openbsd\"))".dependencies]
image = "0.24"
md5 = "0.7"
heck = "0.4"
walkdir = "2.4"
ar = "0.9"
tar = "0.4"
libflate = "1.4"
92 changes: 41 additions & 51 deletions crates/packager/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@
]
},
"PackageFormat": {
"description": "The type of the package we're bundling.",
"description": "The type of the package we're packaging.",
"oneOf": [
{
"description": "The macOS application bundle (.app).",
Expand Down Expand Up @@ -403,46 +403,46 @@
"description": "The possible app categories. Corresponds to `LSApplicationCategoryType` on macOS and the GNOME desktop categories on Debian.",
"type": "string",
"enum": [
"business",
"developerTool",
"education",
"entertainment",
"finance",
"game",
"actionGame",
"adventureGame",
"arcadeGame",
"boardGame",
"cardGame",
"casinoGame",
"diceGame",
"educationalGame",
"familyGame",
"kidsGame",
"musicGame",
"puzzleGame",
"racingGame",
"rolePlayingGame",
"simulationGame",
"sportsGame",
"strategyGame",
"triviaGame",
"wordGame",
"graphicsAndDesign",
"healthcareAndFitness",
"lifestyle",
"medical",
"music",
"news",
"photography",
"productivity",
"reference",
"socialNetworking",
"sports",
"travel",
"utility",
"video",
"weather"
"Business",
"DeveloperTool",
"Education",
"Entertainment",
"Finance",
"Game",
"ActionGame",
"AdventureGame",
"ArcadeGame",
"BoardGame",
"CardGame",
"CasinoGame",
"DiceGame",
"EducationalGame",
"FamilyGame",
"KidsGame",
"MusicGame",
"PuzzleGame",
"RacingGame",
"RolePlayingGame",
"SimulationGame",
"SportsGame",
"StrategyGame",
"TriviaGame",
"WordGame",
"GraphicsAndDesign",
"HealthcareAndFitness",
"Lifestyle",
"Medical",
"Music",
"News",
"Photography",
"Productivity",
"Reference",
"SocialNetworking",
"Sports",
"Travel",
"Utility",
"Video",
"Weather"
]
},
"Binary": {
Expand Down Expand Up @@ -600,16 +600,6 @@
"type": "string"
}
},
"files": {
"description": "List of custom files to add to the deb package. Maps the path on the debian package to the path of the file to include (relative to the current working directory).",
"type": [
"object",
"null"
],
"additionalProperties": {
"type": "string"
}
},
"desktopTemplate": {
"description": "Path to a custom desktop file Handlebars template.\n\nAvailable variables: `categories`, `comment` (optional), `exec`, `icon` and `name`.\n\nDefault file contents: ```text ```",
"type": [
Expand Down
56 changes: 55 additions & 1 deletion crates/packager/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::path::PathBuf;
use std::path::{Path, PathBuf};

pub use cargo_packager_config::*;

Expand All @@ -15,6 +15,8 @@ pub trait ConfigExt {
fn nsis(&self) -> Option<&NsisConfig>;
/// Returns the wix specific configuration
fn wix(&self) -> Option<&WixConfig>;
/// Returns the debian specific configuration
fn deb(&self) -> Option<&DebianConfig>;
/// 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 @@ -38,6 +40,10 @@ impl ConfigExt for Config {
self.wix.as_ref()
}

fn deb(&self) -> Option<&DebianConfig> {
self.deb.as_ref()
}

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

pub(crate) trait ConfigExtInternal {
fn main_binary(&self) -> crate::Result<&Binary>;
fn main_binary_name(&self) -> crate::Result<&String>;
fn resources(&self) -> Option<Vec<Resource>>;
fn find_ico(&self) -> Option<PathBuf>;
fn copy_resources(&self, path: &Path) -> crate::Result<()>;
fn copy_binaries(&self, path: &Path) -> crate::Result<()>;
}

impl ConfigExtInternal for Config {
fn main_binary(&self) -> crate::Result<&Binary> {
self.binaries
.iter()
.find(|bin| bin.main)
.ok_or_else(|| crate::Error::MainBinaryNotFound)
}

fn main_binary_name(&self) -> crate::Result<&String> {
self.binaries
.iter()
.find(|bin| bin.main)
.map(|b| &b.name)
.ok_or_else(|| crate::Error::MainBinaryNotFound)
}

fn resources(&self) -> Option<Vec<Resource>> {
self.resources.as_ref().map(|resources| {
let mut out = Vec::new();
Expand Down Expand Up @@ -134,4 +159,33 @@ impl ConfigExtInternal for Config {
})
.map(PathBuf::from)
}

fn copy_resources(&self, path: &Path) -> crate::Result<()> {
if let Some(resources) = self.resources() {
for resource in resources {
let dest = path.join(resource.target);
std::fs::create_dir_all(dest.parent().ok_or(crate::Error::ParentDirNotFound)?)?;
std::fs::copy(resource.src, dest)?;
}
}
Ok(())
}

fn copy_binaries(&self, path: &Path) -> crate::Result<()> {
if let Some(external_binaries) = &self.external_binaries {
for src in external_binaries {
let src = PathBuf::from(src);
let dest = path.join(
src.file_name()
.expect("failed to extract external binary filename")
.to_string_lossy()
.replace(&format!("-{}", self.target_triple), ""),
);
std::fs::create_dir_all(dest.parent().ok_or(crate::Error::ParentDirNotFound)?)?;
std::fs::copy(src, dest)?;
}
}

Ok(())
}
}
Loading

0 comments on commit 7e6620b

Please sign in to comment.