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

refactor(bundler): output file name consistency, closes #10465 #10577

Closed
wants to merge 9 commits into from
30 changes: 30 additions & 0 deletions .changes/refactor-bundle-file-names.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
'tauri-bundler': 'patch:breaking'
'tauri-cli': 'patch:breaking'
'@tauri-apps/cli': 'patch:breaking'
---

Change bundle file names to a consistent `productName-version-arch.ext` format.
- AppImage
- productName_version_i386.AppImage => productName-version-x86.AppImage
- productName_version_amd64.AppImage => productName-version-x86_64.AppImage
- Debian
- productName_version_i386.deb => productName-version-x86.deb
- productName_version_amd64.deb => productName-version-x86_64.deb
- productName_version_armhf.deb => productName-version-arm.deb
- productName_version.arm64.deb => productName-version-aarch64.deb
- RPM
- productName-version-$release.arch.rpm => productName-version-aarch64-$release.rpm
- DMG
- productName_version_x64.dmg => productName-version-x86_64.dmg
- productName_version_aarch64.dmg => productName-version-aarch64.dmg
- macOS
- still keeps the productName.app format as that is the name of the file that is actually installed on user machines.
- MSI
- productName_version_x86_$language.msi => productName-version-x86-$language.msi
- productName_version_x64_$language.msi => productName-version-x86_64-$language.msi
- productName_version_arm64_$language.msi => productName-version-aarch64-$language.msi
- NSIS
- productName_version_x86_setup.exe => productName-version-x86-setup.exe
- productName_version_x64_setup.exe => productName-version-x86_64-setup.exe
- productName_version_arm64_setup.exe => productName-version-aarch64-setup.exe
20 changes: 20 additions & 0 deletions tooling/bundler/src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,23 @@ pub fn check_icons(settings: &Settings) -> crate::Result<bool> {
Ok(true)
}
}

#[inline]
pub(crate) fn bundle_name(settings: &Settings, ext: &str) -> String {
lucasfernog marked this conversation as resolved.
Show resolved Hide resolved
format!(
"{}-{}-{}.{ext}",
settings.product_name(),
settings.version_string(),
settings.binary_arch()
)
}

#[inline]
pub(crate) fn bundle_name_with_suffix(settings: &Settings, suffix: &str, ext: &str) -> String {
lucasfernog marked this conversation as resolved.
Show resolved Hide resolved
format!(
"{}-{}-{}-{suffix}.{ext}",
settings.product_name(),
settings.version_string(),
settings.binary_arch()
)
}
19 changes: 4 additions & 15 deletions tooling/bundler/src/bundle/linux/appimage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ use std::{
/// Bundles the project.
/// Returns a vector of PathBuf that shows where the AppImage was created.
pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
// generate the deb binary name
let arch = match settings.binary_arch() {
"x86" => "i386",
"x86_64" => "amd64",
other => other,
};
let package_dir = settings.project_out_directory().join("bundle/appimage_deb");

// generate deb_folder structure
Expand All @@ -43,20 +37,15 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
}
std::fs::create_dir_all(output_path.clone())?;
let app_dir_path = output_path.join(format!("{}.AppDir", settings.product_name()));
let appimage_filename = format!(
"{}_{}_{}.AppImage",
settings.product_name(),
settings.version_string(),
arch
);
let appimage_path = output_path.join(&appimage_filename);
let appimage_name = crate::bundle::bundle_name(settings, "AppImage");
let appimage_path = output_path.join(&appimage_name);
path_utils::create(app_dir_path, true)?;

// 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("crate_name", settings.main_binary_name());
sh_map.insert("appimage_filename", &appimage_filename);
sh_map.insert("appimage_filename", &appimage_name);
let tauri_tools_path = dirs::cache_dir().map_or_else(
|| output_path.to_path_buf(),
|mut p| {
Expand Down Expand Up @@ -91,7 +80,7 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
// create the shell script file in the target/ folder.
let sh_file = output_path.join("build_appimage.sh");

log::info!(action = "Bundling"; "{} ({})", appimage_filename, appimage_path.display());
log::info!(action = "Bundling"; "{} ({})", appimage_name, appimage_path.display());

write(&sh_file, temp)?;

Expand Down
30 changes: 12 additions & 18 deletions tooling/bundler/src/bundle/linux/debian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// usr/share/icons/hicolor/... # Icon files (for apps)
// usr/lib/foobar/... # Other resource files
//
// For cargo-bundle, we put bundle resource files under /usr/lib/package_name/,
// We put bundle resource files under /usr/lib/package_name/,
// and then generate the desktop file and control file from the bundle
// metadata, as well as generating the md5sums file. Currently we do not
// generate postinst or prerm files.
Expand All @@ -40,6 +40,17 @@ use std::{
/// Bundles the project.
/// Returns a vector of PathBuf that shows where the DEB was created.
pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
let deb_name = crate::bundle::bundle_name(settings, "deb");

let base_dir = settings.project_out_directory().join("bundle/deb");
let package_dir = base_dir.join(Path::new(&deb_name).file_stem().unwrap());
if package_dir.exists() {
fs::remove_dir_all(&package_dir).with_context(|| format!("Failed to remove old {deb_name}"))?;
}
let package_path = base_dir.join(&deb_name);

log::info!(action = "Bundling"; "{} ({})", deb_name, package_path.display());

let arch = match settings.binary_arch() {
"x86" => "i386",
"x86_64" => "amd64",
Expand All @@ -48,23 +59,6 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
"aarch64" => "arm64",
other => other,
};
let package_base_name = format!(
"{}_{}_{}",
settings.product_name(),
settings.version_string(),
arch
);
let package_name = format!("{package_base_name}.deb");

let base_dir = settings.project_out_directory().join("bundle/deb");
let package_dir = base_dir.join(&package_base_name);
if package_dir.exists() {
fs::remove_dir_all(&package_dir)
.with_context(|| format!("Failed to remove old {package_base_name}"))?;
}
let package_path = base_dir.join(&package_name);

log::info!(action = "Bundling"; "{} ({})", package_name, package_path.display());

let (data_dir, _) = generate_data(settings, &package_dir)
.with_context(|| "Failed to build data folders and files")?;
Expand Down
25 changes: 11 additions & 14 deletions tooling/bundler/src/bundle/linux/rpm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ use super::freedesktop;
/// Bundles the project.
/// Returns a vector of PathBuf that shows where the RPM was created.
pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
let product_name = settings.product_name();
let version = settings.version_string();
let release = settings.rpm().release.as_str();
let epoch = settings.rpm().epoch;
let arch = match settings.binary_arch() {
Expand All @@ -30,27 +28,26 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {

let summary = settings.short_description().trim();

let package_base_name = format!("{product_name}-{version}-{release}.{arch}");
let package_name = format!("{package_base_name}.rpm");
let rpm_name = crate::bundle::bundle_name_with_suffix(settings, release, "rpm");

let base_dir = settings.project_out_directory().join("bundle/rpm");
let package_dir = base_dir.join(&package_base_name);
let package_dir = base_dir.join(Path::new(&rpm_name).file_stem().unwrap());
if package_dir.exists() {
fs::remove_dir_all(&package_dir)
.with_context(|| format!("Failed to remove old {package_base_name}"))?;
fs::remove_dir_all(&package_dir).with_context(|| format!("Failed to remove old {rpm_name}"))?;
}
fs::create_dir_all(&package_dir)?;
let package_path = base_dir.join(&package_name);
let package_path = base_dir.join(&rpm_name);

log::info!(action = "Bundling"; "{} ({})", package_name, package_path.display());
log::info!(action = "Bundling"; "{} ({})", rpm_name, package_path.display());

let license = settings.license().unwrap_or_default();
let name = heck::AsKebabCase(settings.product_name()).to_string();
let mut builder = rpm::PackageBuilder::new(&name, version, &license, arch, summary)
.epoch(epoch)
.release(release)
// This matches .deb compression. On a 240MB source binary the bundle will be 100KB larger than rpm's default while reducing build times by ~25%.
.compression(rpm::CompressionWithLevel::Gzip(6));
let mut builder =
rpm::PackageBuilder::new(&name, settings.version_string(), &license, arch, summary)
.epoch(epoch)
.release(release)
// This matches .deb compression. On a 240MB source binary the bundle will be 100KB larger than rpm's default while reducing build times by ~25%.
.compression(rpm::CompressionWithLevel::Gzip(6));

if let Some(description) = settings.long_description() {
builder = builder.description(description);
Expand Down
12 changes: 2 additions & 10 deletions tooling/bundler/src/bundle/macos/dmg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,8 @@ pub fn bundle_project(settings: &Settings, bundles: &[Bundle]) -> crate::Result<

// get the target path
let output_path = settings.project_out_directory().join("bundle/dmg");
let package_base_name = format!(
"{}_{}_{}",
settings.product_name(),
settings.version_string(),
match settings.binary_arch() {
"x86_64" => "x64",
other => other,
}
);
let dmg_name = format!("{}.dmg", &package_base_name);

let dmg_name = crate::bundle::bundle_name(settings, "dmg");
let dmg_path = output_path.join(&dmg_name);

let product_name = settings.product_name();
Expand Down
64 changes: 18 additions & 46 deletions tooling/bundler/src/bundle/windows/msi/wix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,37 +176,17 @@ fn copy_icon(settings: &Settings, filename: &str, path: &Path) -> crate::Result<
fn app_installer_output_path(
settings: &Settings,
language: &str,
version: &str,
updater: bool,
) -> crate::Result<PathBuf> {
let arch = match settings.binary_arch() {
"x86" => "x86",
"x86_64" => "x64",
"aarch64" => "arm64",
target => {
return Err(crate::Error::ArchError(format!(
"Unsupported architecture: {}",
target
)))
}
};

let package_base_name = format!(
"{}_{}_{}_{}",
settings.product_name(),
version,
arch,
language,
);
let msi_name = crate::bundle::bundle_name_with_suffix(settings, language, "msi");

Ok(settings.project_out_directory().to_path_buf().join(format!(
"bundle/{}/{}.msi",
"bundle/{}/{msi_name}",
if updater {
WIX_UPDATER_OUTPUT_FOLDER_NAME
} else {
WIX_OUTPUT_FOLDER_NAME
},
package_base_name
)))
}

Expand Down Expand Up @@ -292,17 +272,7 @@ fn run_candle(
wxs_file_path: PathBuf,
extensions: Vec<PathBuf>,
) -> crate::Result<()> {
let arch = match settings.binary_arch() {
"x86_64" => "x64",
"x86" => "x86",
"aarch64" => "arm64",
target => {
return Err(crate::Error::ArchError(format!(
"unsupported target: {}",
target
)))
}
};
let arch = wix_arch(settings)?;

let main_binary = settings
.binaries()
Expand Down Expand Up @@ -377,6 +347,19 @@ fn run_light(
Ok(())
}

#[inline]
fn wix_arch(settings: &Settings) -> crate::Result<&'static str> {
lucasfernog marked this conversation as resolved.
Show resolved Hide resolved
match settings.binary_arch() {
"x86_64" => Ok("x64"),
"x86" => Ok("x86"),
"aarch64" => Ok("arm64"),
target => Err(crate::Error::ArchError(format!(
"unsupported target: {}",
target
))),
}
}

// fn get_icon_data() -> crate::Result<()> {
// Ok(())
// }
Expand All @@ -387,17 +370,7 @@ pub fn build_wix_app_installer(
wix_toolset_path: &Path,
updater: bool,
) -> crate::Result<Vec<PathBuf>> {
let arch = match settings.binary_arch() {
"x86_64" => "x64",
"x86" => "x86",
"aarch64" => "arm64",
target => {
return Err(crate::Error::ArchError(format!(
"unsupported target: {}",
target
)))
}
};
let arch = wix_arch(settings)?;

let app_version = convert_version(settings.version_string())?;

Expand Down Expand Up @@ -788,8 +761,7 @@ pub fn build_wix_app_installer(
"*.wixobj".into(),
];
let msi_output_path = output_path.join("output.msi");
let msi_path =
app_installer_output_path(settings, &language, settings.version_string(), updater)?;
let msi_path = app_installer_output_path(settings, &language, updater)?;
fs::create_dir_all(msi_path.parent().unwrap())?;

log::info!(action = "Running"; "light to produce {}", display_path(&msi_path));
Expand Down
13 changes: 4 additions & 9 deletions tooling/bundler/src/bundle/windows/nsis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ fn build_nsis_app_installer(
}
};

log::info!("Target: {}", arch);
log::info!("Target: {arch}");

let output_path = settings.project_out_directory().join("nsis").join(arch);
if output_path.exists() {
Expand Down Expand Up @@ -508,22 +508,17 @@ fn build_nsis_app_installer(
handlebars.render("installer.nsi", &data)?,
)?;

let package_base_name = format!(
"{}_{}_{}-setup",
settings.product_name(),
settings.version_string(),
arch,
);
let nsis_name = crate::bundle::bundle_name_with_suffix(settings, "setup", "exe");

let nsis_output_path = output_path.join(out_file);

let nsis_installer_path = settings.project_out_directory().to_path_buf().join(format!(
"bundle/{}/{}.exe",
"bundle/{}/{nsis_name}",
if updater {
NSIS_UPDATER_OUTPUT_FOLDER_NAME
} else {
NSIS_OUTPUT_FOLDER_NAME
},
package_base_name
));
fs::create_dir_all(nsis_installer_path.parent().unwrap())?;

Expand Down