Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for v1 compatible binary names in the bundler #1

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion crates/tauri-bundler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ tauri-macos-sign = { version = "0.1.1-rc.0", path = "../tauri-macos-sign" }
[target."cfg(any(target_os = \"macos\", target_os = \"windows\"))".dependencies]
regex = "1"

[target."cfg(target_os = \"linux\")".dependencies]
heck = "0.5"
ar = "0.9.0"
md5 = "0.7.0"
Expand Down
43 changes: 42 additions & 1 deletion crates/tauri-bundler/src/bundle/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

use anyhow::Context;
use heck::ToKebabCase;
use std::{
ffi::OsStr,
fs::{self, File},
io::{self, BufRead, BufReader, BufWriter},
path::Path,
path::{Path, PathBuf},
process::{Command, ExitStatus, Output, Stdio},
sync::{Arc, Mutex},
};
use tauri_utils::display_path;

/// Returns true if the path has a filename indicating that it is a high-density
/// "retina" icon. Specifically, returns true the file stem ends with
Expand Down Expand Up @@ -126,6 +129,44 @@ pub fn copy_dir(from: &Path, to: &Path) -> crate::Result<()> {
Ok(())
}

pub(crate) fn use_v1_bin_name() -> bool {
let env_var = std::env::var("V1_COMPATIBLE_BIN_NAME");
env_var.as_deref() == Ok("true") || env_var.as_deref() == Ok("1")
}

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()
};

let product_path = bin_path
.parent()
.unwrap()
.join(product_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),
)
})?;
Ok(product_path)
}

/// Copies user-defined files specified in the configuration file to the package.
///
/// The configuration object maps the path in the package to the path of the file on the filesystem,
Expand Down
12 changes: 10 additions & 2 deletions crates/tauri-bundler/src/bundle/macos/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
// files into the `Contents` directory of the bundle.

use super::{
super::common::{self, CommandExt},
super::common::{self, rename_app, use_v1_bin_name, CommandExt},
icon::create_icns_file,
sign::{notarize, notarize_auth, sign, NotarizeAuthError, SignTarget},
};
Expand Down Expand Up @@ -159,6 +159,9 @@ fn copy_binaries_to_bundle(
let dest_path = 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 Expand Up @@ -200,7 +203,12 @@ fn create_info_plist(
plist.insert("CFBundleDisplayName".into(), settings.product_name().into());
plist.insert(
"CFBundleExecutable".into(),
settings.main_binary_name().into(),
if use_v1_bin_name() {
settings.product_name()
} else {
settings.main_binary_name()
}
.into(),
);
if let Some(path) = bundle_icon_file {
plist.insert(
Expand Down
1 change: 1 addition & 0 deletions crates/tauri-cli/ENVIRONMENT_VARIABLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ These environment variables are inputs to the CLI which may have an equivalent C
- `TAURI_WEBVIEW_AUTOMATION` — Enables webview automation (Linux Only).
- `TAURI_ANDROID_PROJECT_PATH` — Path of the tauri android project, usually will be `<project>/src-tauri/gen/android`.
- `TAURI_IOS_PROJECT_PATH` — Path of the tauri iOS project, usually will be `<project>/src-tauri/gen/ios`.
- `V1_COMPATIBLE_BIN_NAME` — If set, the CLI will rename the main app binary to the `productName`, as it did in Tauri v1. This is useful for allowing users of a Tauri v1 app to update the app to a v2 version via the updater.

### Tauri CLI Hook Commands

Expand Down