Skip to content

Commit

Permalink
refactor(cli&bundler): avoid renaming main executable and preserve ca…
Browse files Browse the repository at this point in the history
…rgo name (#9375)

* refactor(cli&bundler): avoid renaming main executable and reserve cargo name

closes #8109
closes #8349

* fix bundler

* fix test

* Discard changes to core/tauri-build/Cargo.toml

* revert Cargo.toml changes

* Discard changes to Cargo.lock

* Discard changes to tooling/cli/Cargo.lock

* lock file

* use product name for installers

* only warn for sign on windows

---------

Co-authored-by: Lucas Nogueira <[email protected]>
Co-authored-by: Lucas Fernandes Nogueira <[email protected]>
  • Loading branch information
3 people committed May 28, 2024
1 parent e8f6eb5 commit 265c238
Show file tree
Hide file tree
Showing 22 changed files with 116 additions and 241 deletions.
7 changes: 7 additions & 0 deletions .changes/cli-perserve-cargo-bin-name.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"tauri-cli": "patch:breaking"
"@tauri-apps/cli": "patch:breaking"
---

Avoid renaming main binary to product name and perserve the name generated by cargo.

6 changes: 6 additions & 0 deletions .changes/tauri-utils-package-name-removed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"tauri-utils": "patch:breaking"
---

Removed `Config::binary_name` and `PackageInfo::package_name`

1 change: 0 additions & 1 deletion Cargo.lock

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

3 changes: 0 additions & 3 deletions core/tauri-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ dunce = "1"
log = "0.4.21"
cargo_metadata = { version = "0.18", optional = true }

[target."cfg(target_os = \"linux\")".dependencies]
heck = "0.5"

[target."cfg(target_os = \"macos\")".dependencies]
swift-rs = { version = "1.0.6", optional = true, features = [ "build" ] }

Expand Down
17 changes: 0 additions & 17 deletions core/tauri-utils/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
//! This is a core functionality that is not considered part of the stable API.
//! If you use it, note that it may include breaking changes in the future.

#[cfg(target_os = "linux")]
use heck::ToKebabCase;
#[cfg(feature = "schema")]
use schemars::JsonSchema;
use semver::Version;
Expand Down Expand Up @@ -2115,21 +2113,6 @@ pub struct Config {
pub plugins: PluginConfig,
}

impl Config {
/// The binary name. Returns the product name as kebab-case on Linux,
/// and returns it as is on all other platforms.
pub fn binary_name(&self) -> Option<String> {
#[cfg(target_os = "linux")]
{
self.product_name.as_ref().map(|n| n.to_kebab_case())
}
#[cfg(not(target_os = "linux"))]
{
self.product_name.clone()
}
}
}

/// The plugin configs holds a HashMap mapping a plugin name to its configuration object.
///
/// See more: <https://tauri.app/v1/api/config#pluginconfig>
Expand Down
14 changes: 0 additions & 14 deletions core/tauri-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,6 @@ pub struct PackageInfo {
pub crate_name: &'static str,
}

impl PackageInfo {
/// Returns the application package name.
/// On macOS and Windows it's the `name` field, and on Linux it's the `name` in `kebab-case`.
pub fn package_name(&self) -> String {
#[cfg(target_os = "linux")]
{
use heck::ToKebabCase;
self.name.clone().to_kebab_case()
}
#[cfg(not(target_os = "linux"))]
self.name.clone()
}
}

#[allow(deprecated)]
mod window_effects {
use super::*;
Expand Down
8 changes: 4 additions & 4 deletions core/tauri-utils/src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,21 +292,21 @@ fn resource_dir_from<P: AsRef<Path>>(
res = if curr_dir.ends_with("/data/usr/bin") {
// running from the deb bundle dir
exe_dir
.join(format!("../lib/{}", package_info.package_name()))
.join(format!("../lib/{}", package_info.crate_name))
.canonicalize()
.map_err(Into::into)
} else if let Some(appdir) = &env.appdir {
let appdir: &std::path::Path = appdir.as_ref();
Ok(PathBuf::from(format!(
"{}/usr/lib/{}",
appdir.display(),
package_info.package_name()
package_info.crate_name
)))
} else {
// running bundle
Ok(PathBuf::from(format!(
"/usr/lib/{}",
package_info.package_name()
package_info.crate_name
)))
};
}
Expand Down Expand Up @@ -357,7 +357,7 @@ mod tests {
version: "1.0.0".parse().unwrap(),
authors: "",
description: "",
crate_name: "",
crate_name: "my-app",
};
let env = Env::default();

Expand Down
11 changes: 1 addition & 10 deletions core/tauri/src/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1991,16 +1991,7 @@ tauri::Builder::default()
.set_progress_bar(crate::runtime::ProgressBarState {
status: progress_state.status,
progress: progress_state.progress,
desktop_filename: Some(format!(
"{}.desktop",
heck::AsKebabCase(
self
.config()
.product_name
.as_deref()
.unwrap_or_else(|| self.package_info().crate_name)
)
)),
desktop_filename: Some(format!("{}.desktop", self.package_info().crate_name)),
})
.map_err(Into::into)
}
Expand Down
1 change: 0 additions & 1 deletion examples/api/src-tauri/Cargo.lock

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

53 changes: 28 additions & 25 deletions tooling/bundler/src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,35 +63,38 @@ pub fn bundle_project(settings: Settings) -> crate::Result<Vec<Bundle>> {
log::warn!("Cross-platform compilation is experimental and does not support all features. Please use a matching host system for full compatibility.");
}

if settings.can_sign() {
// Sign windows binaries before the bundling step in case neither wix and nsis bundles are enabled
for bin in settings.binaries() {
let bin_path = settings.binary_path(bin);
windows::sign::try_sign(&bin_path, &settings)?;
}

// Sign the sidecar binaries
for bin in settings.external_binaries() {
let path = bin?;
let skip = std::env::var("TAURI_SKIP_SIDECAR_SIGNATURE_CHECK").map_or(false, |v| v == "true");
if skip {
continue;
// Sign windows binaries before the bundling step in case neither wix and nsis bundles are enabled
if target_os == "windows" {
if settings.can_sign() {
for bin in settings.binaries() {
let bin_path = settings.binary_path(bin);
windows::sign::try_sign(&bin_path, &settings)?;
}

#[cfg(windows)]
if windows::sign::verify(&path)? {
log::info!(
"sidecar at \"{}\" already signed. Skipping...",
path.display()
);
continue;
}
// Sign the sidecar binaries
for bin in settings.external_binaries() {
let path = bin?;
let skip =
std::env::var("TAURI_SKIP_SIDECAR_SIGNATURE_CHECK").map_or(false, |v| v == "true");
if skip {
continue;
}

windows::sign::try_sign(&path, &settings)?;
#[cfg(windows)]
if windows::sign::verify(&path)? {
log::info!(
"sidecar at \"{}\" already signed. Skipping...",
path.display()
);
continue;
}

windows::sign::try_sign(&path, &settings)?;
}
} else {
#[cfg(not(target_os = "windows"))]
log::warn!("Signing, by default, is only supported on Windows hosts, but you can specify a custom signing command in `bundler > windows > sign_command`, for now, skipping signing the installer...");
}
} else {
#[cfg(not(target_os = "windows"))]
log::warn!("Signing, by default, is only supported on Windows hosts, but you can specify a custom signing command in `bundler > windows > sign_command`, for now, skipping signing the installer...");
}

for package_type in &package_types {
Expand Down
8 changes: 4 additions & 4 deletions tooling/bundler/src/bundle/linux/appimage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,22 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
remove_dir_all(&output_path)?;
}
std::fs::create_dir_all(output_path.clone())?;
let app_dir_path = output_path.join(format!("{}.AppDir", settings.main_binary_name()));
let app_dir_path = output_path.join(format!("{}.AppDir", settings.product_name()));
let appimage_filename = format!(
"{}_{}_{}.AppImage",
settings.main_binary_name(),
settings.product_name(),
settings.version_string(),
arch
);
let appimage_path = output_path.join(&appimage_filename);
path_utils::create(app_dir_path, true)?;

let upcase_app_name = settings.main_binary_name().to_uppercase();
let upcase_app_name = settings.product_name().to_uppercase();

// setup data to insert into shell script
let mut sh_map = BTreeMap::new();
sh_map.insert("arch", settings.target().split('-').next().unwrap());
sh_map.insert("app_name", settings.main_binary_name());
sh_map.insert("app_name", settings.product_name());
sh_map.insert("app_name_uppercase", &upcase_app_name);
sh_map.insert("appimage_filename", &appimage_filename);
let tauri_tools_path = dirs_next::cache_dir().map_or_else(
Expand Down
6 changes: 3 additions & 3 deletions tooling/bundler/src/bundle/linux/debian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use super::{super::common, freedesktop};
use crate::Settings;
use anyhow::Context;
use flate2::{write::GzEncoder, Compression};
use heck::AsKebabCase;
use tar::HeaderMode;
use walkdir::WalkDir;

Expand All @@ -51,7 +50,7 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
};
let package_base_name = format!(
"{}_{}_{}",
settings.main_binary_name(),
settings.product_name(),
settings.version_string(),
arch
);
Expand Down Expand Up @@ -158,7 +157,8 @@ fn generate_control_file(
// https://www.debian.org/doc/debian-policy/ch-controlfields.html
let dest_path = control_dir.join("control");
let mut file = common::create_file(&dest_path)?;
writeln!(file, "Package: {}", AsKebabCase(settings.product_name()))?;
let package = heck::AsKebabCase(settings.product_name());
writeln!(file, "Package: {}", package)?;
writeln!(file, "Version: {}", settings.version_string())?;
writeln!(file, "Architecture: {arch}")?;
// Installed-Size must be divided by 1024, see https://www.debian.org/doc/debian-policy/ch-controlfields.html#installed-size
Expand Down
2 changes: 1 addition & 1 deletion tooling/bundler/src/bundle/linux/freedesktop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub fn list_icon_files(

/// Generate the icon files and store them under the `data_dir`.
pub fn copy_icon_files(settings: &Settings, data_dir: &Path) -> crate::Result<Vec<Icon>> {
let icons = self::list_icon_files(settings, data_dir)?;
let icons = list_icon_files(settings, data_dir)?;
for (icon, src) in &icons {
common::copy_file(src, &icon.path)?;
}
Expand Down
4 changes: 2 additions & 2 deletions tooling/bundler/src/bundle/macos/dmg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub fn bundle_project(settings: &Settings, bundles: &[Bundle]) -> crate::Result<
let output_path = settings.project_out_directory().join("bundle/dmg");
let package_base_name = format!(
"{}_{}_{}",
settings.main_binary_name(),
settings.product_name(),
settings.version_string(),
match settings.binary_arch() {
"x86_64" => "x64",
Expand All @@ -50,7 +50,7 @@ pub fn bundle_project(settings: &Settings, bundles: &[Bundle]) -> crate::Result<
let dmg_name = format!("{}.dmg", &package_base_name);
let dmg_path = output_path.join(&dmg_name);

let product_name = settings.main_binary_name();
let product_name = settings.product_name();
let bundle_file_name = format!("{}.app", product_name);
let bundle_dir = settings.project_out_directory().join("bundle/macos");

Expand Down
9 changes: 9 additions & 0 deletions tooling/bundler/src/bundle/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,15 @@ impl BundleBinary {
}
}

/// Creates a new bundle binary with path.
pub fn with_path(name: String, main: bool, src_path: Option<String>) -> Self {
Self {
name,
src_path,
main,
}
}

/// Sets the src path of the binary.
#[must_use]
pub fn set_src_path(mut self, src_path: Option<String>) -> Self {
Expand Down
Loading

0 comments on commit 265c238

Please sign in to comment.