Skip to content

Commit

Permalink
Fix MacOS code signing, RPM + DEB, MSI/NSIS
Browse files Browse the repository at this point in the history
  • Loading branch information
Geometrically committed Sep 10, 2024
1 parent 5b26cbf commit 2ca0657
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 48 deletions.
54 changes: 27 additions & 27 deletions crates/tauri-bundler/src/bundle/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,44 +135,44 @@ pub(crate) fn use_v1_bin_name() -> bool {
env_var.as_deref() == Ok("true") || env_var.as_deref() == Ok("1")
}

pub(crate) fn get_bin_name(settings: &Settings) -> &str {
pub(crate) fn get_bin_name(settings: &Settings) -> String {
if use_v1_bin_name() {
settings.product_name()
let target_os = settings
.target()
.split('-')
.nth(2)
.unwrap_or(std::env::consts::OS)
.replace("darwin", "macos");

if target_os == "linux" {
settings.product_name().to_kebab_case()
} else {
settings.product_name().to_string()
}
} else {
settings.main_binary_name()
settings.main_binary_name().to_string()
}
}

pub(crate) fn rename_app(
target: &str,
bin_path: &Path,
product_name: &str,
) -> crate::Result<PathBuf> {
let target_os = target
.split('-')
.nth(2)
.unwrap_or(std::env::consts::OS)
.replace("darwin", "macos");

let product_name = if target_os == "linux" {
product_name.to_kebab_case()
} else {
product_name.into()
};
pub(crate) fn rename_app(settings: &Settings, bin_path: &Path) -> crate::Result<PathBuf> {
let bin_name = get_bin_name(settings);

let product_path = bin_path
.parent()
.unwrap()
.join(product_name)
.join(bin_name)
.with_extension(bin_path.extension().unwrap_or_default());

fs::rename(bin_path, &product_path).with_context(|| {
format!(
"failed to rename `{}` to `{}`",
display_path(bin_path),
display_path(&product_path),
)
})?;
if !product_path.exists() {
fs::rename(bin_path, &product_path).with_context(|| {
format!(
"failed to rename `{}` to `{}`",
display_path(bin_path),
display_path(&product_path),
)
})?;
}

Ok(product_path)
}

Expand Down
10 changes: 5 additions & 5 deletions crates/tauri-bundler/src/bundle/linux/debian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ pub fn generate_data(

for bin in settings.binaries() {
let bin_path = settings.binary_path(bin);
let dest_path = bin_dir.join(bin.name());
let dest_path = if use_v1_bin_name() && bin.name() == settings.main_binary_name() {
bin_dir.join(get_bin_name(settings))
} else {
bin_dir.join(bin.name())
};
common::copy_file(&bin_path, &dest_path)
.with_context(|| format!("Failed to copy binary from {bin_path:?}"))?;

if use_v1_bin_name() && bin.name() == settings.main_binary_name() {
rename_app(settings.target(), &dest_path, settings.product_name())?;
}
}

copy_resource_files(settings, &data_dir).with_context(|| "Failed to copy resource files")?;
Expand Down
14 changes: 6 additions & 8 deletions crates/tauri-bundler/src/bundle/linux/rpm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,15 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {

// Add binaries
for bin in settings.binaries() {
let src = if use_v1_bin_name() && bin.name() == settings.main_binary_name() {
rename_app(
settings.target(),
&settings.binary_path(bin),
settings.product_name(),
)?
let src = settings.binary_path(bin);

let dest_name = if bin.name() == settings.main_binary_name() {
get_bin_name(settings)
} else {
settings.binary_path(bin)
bin.name().to_string()
};

let dest = Path::new("/usr/bin").join(bin.name());
let dest = Path::new("/usr/bin").join(dest_name);
builder = builder.with_file(src, FileOptions::new(dest.to_string_lossy()))?;
}

Expand Down
12 changes: 7 additions & 5 deletions crates/tauri-bundler/src/bundle/macos/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use crate::Settings;

use anyhow::Context;

use crate::bundle::common::{get_bin_name, rename_app, use_v1_bin_name};
use crate::bundle::common::get_bin_name;
use std::{
ffi::OsStr,
fs,
Expand Down Expand Up @@ -157,12 +157,14 @@ fn copy_binaries_to_bundle(
let dest_dir = bundle_directory.join("MacOS");
for bin in settings.binaries() {
let bin_path = settings.binary_path(bin);
let dest_path = dest_dir.join(bin.name());
let dest_path = if bin.name() == settings.main_binary_name() {
dest_dir.join(get_bin_name(settings))
} else {
dest_dir.join(bin.name())
};

common::copy_file(&bin_path, &dest_path)
.with_context(|| format!("Failed to copy binary from {:?}", bin_path))?;
if use_v1_bin_name() && bin.name() == settings.main_binary_name() {
rename_app(settings.target(), &dest_path, settings.product_name())?;
}
paths.push(dest_path);
}
Ok(paths)
Expand Down
2 changes: 1 addition & 1 deletion crates/tauri-bundler/src/bundle/windows/msi/wix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ pub fn build_wix_app_installer(
.ok_or_else(|| anyhow::anyhow!("Failed to get main binary"))?;
let old_binary_path = settings.binary_path(main_binary);
let app_exe_source = if use_v1_bin_name() {
rename_app(settings.target(), &old_binary_path, settings.product_name())?
rename_app(settings, &old_binary_path)?
} else {
old_binary_path
};
Expand Down
4 changes: 2 additions & 2 deletions crates/tauri-bundler/src/bundle/windows/nsis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ fn build_nsis_app_installer(

let old_binary_path = settings.binary_path(main_binary).with_extension("exe");
let main_binary_path = if use_v1_bin_name() {
rename_app(settings.target(), &old_binary_path, settings.product_name())?
rename_app(settings, &old_binary_path)?
} else {
old_binary_path
};
Expand All @@ -356,7 +356,7 @@ fn build_nsis_app_installer(
main_binary_path
.file_stem()
.and_then(|file_name| file_name.to_str())
.unwrap_or_else(|| get_bin_name(settings)),
.unwrap_or(get_bin_name(settings).as_str()),
),
);
data.insert("main_binary_path", to_json(&main_binary_path));
Expand Down

0 comments on commit 2ca0657

Please sign in to comment.