Skip to content

Commit b3f2d12

Browse files
authored
fix(tauri-build): preserve numeric semver build metadata in Windows FILEVERSION (tauri-apps#15289)
* fix(tauri-build): preserve numeric semver build metadata in Windows FILEVERSION * refactor(tauri-build): clarify PRODUCTVERSION naming * refactor(tauri-build): align fixed Windows version fields * refactor(tauri-build): rename Windows version helper * style(tauri-build): move winres helper near tests
1 parent a30dca4 commit b3f2d12

2 files changed

Lines changed: 57 additions & 1 deletion

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri-build": "patch:enhance"
3+
---
4+
5+
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.

crates/tauri-build/src/lib.rs

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
631631

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

720720
Ok(())
721721
}
722+
723+
fn to_winres_version(v: &semver::Version) -> u64 {
724+
let build = v.build.parse::<u16>().map(u64::from).unwrap_or(0);
725+
726+
(v.major << 48) | (v.minor << 32) | (v.patch << 16) | build
727+
}
728+
729+
#[cfg(test)]
730+
mod tests {
731+
use semver::Version;
732+
733+
#[test]
734+
fn version_uses_numeric_build_metadata() {
735+
let version = Version::parse("1.2.3+42").unwrap();
736+
737+
assert_eq!(
738+
crate::to_winres_version(&version),
739+
(1 << 48) | (2 << 32) | (3 << 16) | 42
740+
);
741+
}
742+
743+
#[test]
744+
fn version_ignores_non_numeric_composite_build_metadata() {
745+
let version = Version::parse("1.2.3+42.sha").unwrap();
746+
747+
assert_eq!(
748+
crate::to_winres_version(&version),
749+
(1 << 48) | (2 << 32) | (3 << 16)
750+
);
751+
}
752+
753+
#[test]
754+
fn version_ignores_non_numeric_build_metadata() {
755+
let version = Version::parse("1.2.3+abc").unwrap();
756+
757+
assert_eq!(
758+
crate::to_winres_version(&version),
759+
(1 << 48) | (2 << 32) | (3 << 16)
760+
);
761+
}
762+
763+
#[test]
764+
fn version_ignores_build_metadata_that_does_not_fit_in_u16() {
765+
let version = Version::parse("1.2.3+70000").unwrap();
766+
767+
assert_eq!(
768+
crate::to_winres_version(&version),
769+
(1 << 48) | (2 << 32) | (3 << 16)
770+
);
771+
}
772+
}

0 commit comments

Comments
 (0)