Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changes/windows-fileversion-build-metadata.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri-build": "patch:enhance"
---

Preserve a numeric semver build identifier such as `1.2.3+42` in the 4th segment of the Windows `FILEVERSION` fixed field when it fits in the Windows version format.
53 changes: 52 additions & 1 deletion crates/tauri-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ pub fn try_build(attributes: Attributes) -> Result<()> {

if let Some(version_str) = &config.version {
if let Ok(v) = Version::parse(version_str) {
let version = (v.major << 48) | (v.minor << 32) | (v.patch << 16);
let version = to_winres_version(&v);
res.set_version_info(VersionInfo::FILEVERSION, version);
res.set_version_info(VersionInfo::PRODUCTVERSION, version);
res.set("FileVersion", version_str);
Expand Down Expand Up @@ -719,3 +719,54 @@ pub fn try_build(attributes: Attributes) -> Result<()> {

Ok(())
}

fn to_winres_version(v: &semver::Version) -> u64 {
let build = v.build.parse::<u16>().map(u64::from).unwrap_or(0);

(v.major << 48) | (v.minor << 32) | (v.patch << 16) | build
}

#[cfg(test)]
mod tests {
use semver::Version;

#[test]
fn version_uses_numeric_build_metadata() {
let version = Version::parse("1.2.3+42").unwrap();

assert_eq!(
crate::to_winres_version(&version),
(1 << 48) | (2 << 32) | (3 << 16) | 42
);
}

#[test]
fn version_ignores_non_numeric_composite_build_metadata() {
let version = Version::parse("1.2.3+42.sha").unwrap();

assert_eq!(
crate::to_winres_version(&version),
(1 << 48) | (2 << 32) | (3 << 16)
);
}

#[test]
fn version_ignores_non_numeric_build_metadata() {
let version = Version::parse("1.2.3+abc").unwrap();

assert_eq!(
crate::to_winres_version(&version),
(1 << 48) | (2 << 32) | (3 << 16)
);
}

#[test]
fn version_ignores_build_metadata_that_does_not_fit_in_u16() {
let version = Version::parse("1.2.3+70000").unwrap();

assert_eq!(
crate::to_winres_version(&version),
(1 << 48) | (2 << 32) | (3 << 16)
);
}
}
Loading