Skip to content

Commit b1b76f2

Browse files
feat: Synchronize bundleVersion with Info.plist
1 parent f298419 commit b1b76f2

File tree

7 files changed

+49
-27
lines changed

7 files changed

+49
-27
lines changed

.changes/ios-macos-bundleversion.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": minor:feat
3+
---
4+
5+
Added `bundleVersion` to iOS and macOS configuration to support specifying a `CFBundleVersion`.

crates/tauri-bundler/src/bundle/macos/app.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ fn create_info_plist(
220220
"CFBundleShortVersionString".into(),
221221
settings.version_string().into(),
222222
);
223-
plist.insert("CFBundleVersion".into(), settings.bundle_version().unwrap_or_else(|| settings.version_string()).into());
223+
plist.insert("CFBundleVersion".into(), settings.bundle_version().into());
224224
plist.insert("CSResourcesFileMapped".into(), true.into());
225225
if let Some(category) = settings.app_category() {
226226
plist.insert(

crates/tauri-bundler/src/bundle/macos/ios.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ fn generate_info_plist(
178178
writeln!(
179179
file,
180180
" <key>CFBundleVersion</key>\n <string>{}</string>",
181-
settings.bundle_version().unwrap_or_else(|| settings.version_string())
181+
settings.bundle_version()
182182
)?;
183183
writeln!(
184184
file,

crates/tauri-bundler/src/bundle/settings.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ pub struct PackageSettings {
146146
pub product_name: String,
147147
/// the package's version.
148148
pub version: String,
149+
/// the package's bundle version.
150+
pub bundle_version: String,
149151
/// the package's description.
150152
pub description: String,
151153
/// the package's homepage.
@@ -1105,15 +1107,8 @@ impl Settings {
11051107
}
11061108

11071109
/// Returns the bundle version.
1108-
pub fn bundle_version(&self) -> Option<&str> {
1109-
#[cfg(target_os = "ios")]
1110-
{
1111-
self.bundle_settings.ios.bundle_version.as_deref()
1112-
}
1113-
#[cfg(target_os = "macos")]
1114-
{
1115-
self.bundle_settings.macos.bundle_version.as_deref()
1116-
}
1110+
pub fn bundle_version(&self) -> &str {
1111+
&self.package.bundle_version
11171112
}
11181113

11191114
/// Returns the copyright text.

crates/tauri-cli/src/interface/rust.rs

+26-14
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ use notify_debouncer_full::new_debouncer;
2222
use serde::{Deserialize, Deserializer};
2323
use tauri_bundler::{
2424
AppCategory, AppImageSettings, BundleBinary, BundleSettings, DebianSettings, DmgSettings,
25-
IosSettings, MacOsSettings, PackageSettings, Position, RpmSettings, Size, UpdaterSettings, WindowsSettings,
25+
IosSettings, MacOsSettings, PackageSettings, Position, RpmSettings, Size, UpdaterSettings,
26+
WindowsSettings,
2627
};
2728
use tauri_utils::config::{parse::is_configuration_file, DeepLinkProtocol, Updater};
2829

@@ -1016,24 +1017,35 @@ impl RustAppSettings {
10161017
.workspace
10171018
.and_then(|v| v.package);
10181019

1020+
let version = config.version.clone().unwrap_or_else(|| {
1021+
cargo_package_settings
1022+
.version
1023+
.clone()
1024+
.expect("Cargo manifest must have the `package.version` field")
1025+
.resolve("version", || {
1026+
ws_package_settings
1027+
.as_ref()
1028+
.and_then(|p| p.version.clone())
1029+
.ok_or_else(|| anyhow::anyhow!("Couldn't inherit value for `version` from workspace"))
1030+
})
1031+
.expect("Cargo project does not have a version")
1032+
});
1033+
1034+
let bundle_version = if cfg!(target_os = "ios") {
1035+
config.bundle.ios.bundle_version.clone()
1036+
} else if cfg!(target_os = "macos") {
1037+
config.bundle.macos.bundle_version.clone()
1038+
} else {
1039+
None
1040+
};
1041+
10191042
let package_settings = PackageSettings {
10201043
product_name: config
10211044
.product_name
10221045
.clone()
10231046
.unwrap_or_else(|| cargo_package_settings.name.clone()),
1024-
version: config.version.clone().unwrap_or_else(|| {
1025-
cargo_package_settings
1026-
.version
1027-
.clone()
1028-
.expect("Cargo manifest must have the `package.version` field")
1029-
.resolve("version", || {
1030-
ws_package_settings
1031-
.as_ref()
1032-
.and_then(|p| p.version.clone())
1033-
.ok_or_else(|| anyhow::anyhow!("Couldn't inherit value for `version` from workspace"))
1034-
})
1035-
.expect("Cargo project does not have a version")
1036-
}),
1047+
version: version.clone(),
1048+
bundle_version: bundle_version.unwrap_or_else(|| version.clone()),
10371049
description: cargo_package_settings
10381050
.description
10391051
.clone()

crates/tauri-cli/src/mobile/ios/build.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,12 @@ pub fn command(options: Options, noise_level: NoiseLevel) -> Result<()> {
183183

184184
let mut plist = plist::Dictionary::new();
185185
let version = interface.app_settings().get_package_settings().version;
186+
let bundle_version = interface
187+
.app_settings()
188+
.get_package_settings()
189+
.bundle_version;
186190
plist.insert("CFBundleShortVersionString".into(), version.clone().into());
187-
plist.insert("CFBundleVersion".into(), version.into());
191+
plist.insert("CFBundleVersion".into(), bundle_version.into());
188192

189193
let info_plist_path = config
190194
.project_dir()

crates/tauri-codegen/src/context.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,13 @@ pub fn context_codegen(data: ContextData) -> EmbeddedAssetsResult<TokenStream> {
315315
if let Some(version) = &config.version {
316316
let bundle_version = &config.bundle.macos.bundle_version;
317317
plist.insert("CFBundleShortVersionString".into(), version.clone().into());
318-
plist.insert("CFBundleVersion".into(), bundle_version.clone().unwrap_or_else(|| version.clone()).into());
318+
plist.insert(
319+
"CFBundleVersion".into(),
320+
bundle_version
321+
.clone()
322+
.unwrap_or_else(|| version.clone())
323+
.into(),
324+
);
319325
}
320326
}
321327

0 commit comments

Comments
 (0)