Skip to content

Commit

Permalink
feat(cli.rs): fill debian depends with tauri dependencies (#1767)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog authored May 10, 2021
1 parent 22676df commit 72b8048
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changes/debian-depends.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"cli.rs": patch
---

Automatically add Tauri dependencies to the debian package `Depends` section.
4 changes: 2 additions & 2 deletions tooling/cli.rs/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl Build {
let tauri_path = tauri_dir();
set_current_dir(&tauri_path).with_context(|| "failed to change current working directory")?;

rewrite_manifest(config.clone())?;
let manifest = rewrite_manifest(config.clone())?;

let config_guard = config.lock().unwrap();
let config_ = config_guard.as_ref().unwrap();
Expand Down Expand Up @@ -150,7 +150,7 @@ impl Build {
}
let mut settings_builder = SettingsBuilder::new()
.package_settings(app_settings.get_package_settings())
.bundle_settings(app_settings.get_bundle_settings(&config_)?)
.bundle_settings(app_settings.get_bundle_settings(&config_, &manifest)?)
.binaries(app_settings.get_binaries(&config_)?)
.project_out_directory(out_dir);

Expand Down
27 changes: 23 additions & 4 deletions tooling/cli.rs/src/build/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::{
use anyhow::Context;
use serde::Deserialize;

use crate::helpers::{app_paths::tauri_dir, config::Config};
use crate::helpers::{app_paths::tauri_dir, config::Config, manifest::Manifest};
use tauri_bundler::{
AppCategory, BundleBinary, BundleSettings, DebianSettings, MacOsSettings, PackageSettings,
UpdaterSettings, WindowsSettings,
Expand Down Expand Up @@ -163,8 +163,13 @@ impl AppSettings {
&self.cargo_package_settings
}

pub fn get_bundle_settings(&self, config: &Config) -> crate::Result<BundleSettings> {
pub fn get_bundle_settings(
&self,
config: &Config,
manifest: &Manifest,
) -> crate::Result<BundleSettings> {
tauri_config_to_bundle_settings(
manifest,
config.tauri.bundle.clone(),
config.tauri.system_tray.clone(),
config.tauri.updater.clone(),
Expand Down Expand Up @@ -336,6 +341,7 @@ pub fn get_workspace_dir(current_dir: &Path) -> PathBuf {
}

fn tauri_config_to_bundle_settings(
manifest: &Manifest,
config: crate::helpers::config::BundleConfig,
system_tray_config: Option<crate::helpers::config::SystemTrayConfig>,
updater_config: crate::helpers::config::UpdaterConfig,
Expand All @@ -353,12 +359,21 @@ fn tauri_config_to_bundle_settings(

#[allow(unused_mut)]
let mut resources = config.resources.unwrap_or_default();
#[allow(unused_mut)]
let mut depends = config.deb.depends.unwrap_or_default();

#[cfg(target_os = "linux")]
{
if let Some(system_tray_config) = &system_tray_config {
let mut icon_path = system_tray_config.icon_path.clone();
icon_path.set_extension("png");
resources.push(icon_path.to_string_lossy().to_string());
depends.push("libappindicator3-1".to_string());
}

depends.push("libwebkit2gtk-4.0".to_string());
depends.push("libgtk-3-0".to_string());
if manifest.features.contains(&"menu".into()) || system_tray_config.is_some() {
depends.push("libgtksourceview-3.0-1".to_string());
}
}

Expand All @@ -382,7 +397,11 @@ fn tauri_config_to_bundle_settings(
long_description: config.long_description,
external_bin: config.external_bin,
deb: DebianSettings {
depends: config.deb.depends,
depends: if depends.is_empty() {
None
} else {
Some(depends)
},
use_bootstrapper: Some(config.deb.use_bootstrapper),
files: config.deb.files,
},
Expand Down
39 changes: 33 additions & 6 deletions tooling/cli.rs/src/helpers/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,21 @@ use std::{
io::{Read, Write},
};

pub fn rewrite_manifest(config: ConfigHandle) -> crate::Result<()> {
pub struct Manifest {
pub features: Vec<String>,
}

fn features_to_vec(features: &Array) -> Vec<String> {
let mut string_features = Vec::new();
for feat in features.iter() {
if let Value::String(feature) = feat {
string_features.push(feature.value().to_string());
}
}
string_features
}

pub fn rewrite_manifest(config: ConfigHandle) -> crate::Result<Manifest> {
let manifest_path = tauri_dir().join("Cargo.toml");
let mut manifest_str = String::new();
let mut manifest_file = File::open(&manifest_path)
Expand Down Expand Up @@ -49,7 +63,16 @@ pub fn rewrite_manifest(config: ConfigHandle) -> crate::Result<()> {

if let Some(tauri) = tauri_entry.as_table_mut() {
let manifest_features = tauri.entry("features");
*manifest_features = Item::Value(Value::Array(features));
if let Item::Value(Value::Array(f)) = &manifest_features {
for feat in f.iter() {
if let Value::String(feature) = feat {
if feature.value() == "menu" {
features.push("menu").unwrap();
}
}
}
}
*manifest_features = Item::Value(Value::Array(features.clone()));
} else if let Some(tauri) = tauri_entry.as_value_mut() {
match tauri {
Value::InlineTable(table) => {
Expand All @@ -63,15 +86,15 @@ pub fn rewrite_manifest(config: ConfigHandle) -> crate::Result<()> {
}
}
}
*manifest_features = Value::Array(features);
*manifest_features = Value::Array(features.clone());
}
Value::String(version) => {
let mut def = InlineTable::default();
def.get_or_insert(
"version",
version.to_string().replace("\"", "").replace(" ", ""),
);
def.get_or_insert("features", Value::Array(features));
def.get_or_insert("features", Value::Array(features.clone()));
*tauri = Value::InlineTable(def);
}
_ => {
Expand All @@ -81,7 +104,9 @@ pub fn rewrite_manifest(config: ConfigHandle) -> crate::Result<()> {
}
}
} else {
return Ok(());
return Ok(Manifest {
features: features_to_vec(&features),
});
}

let mut manifest_file =
Expand All @@ -98,5 +123,7 @@ pub fn rewrite_manifest(config: ConfigHandle) -> crate::Result<()> {
)?;
manifest_file.flush()?;

Ok(())
Ok(Manifest {
features: features_to_vec(&features),
})
}

0 comments on commit 72b8048

Please sign in to comment.