From 3c111184906d4db3eaef77d1fa952132ca67b979 Mon Sep 17 00:00:00 2001 From: TimeToBuildBob Date: Sat, 14 Nov 2026 16:54:15 +0000 Subject: [PATCH 1/2] build(windows): embed PE version resource in aw-server and aw-sync Code-signing services (SignPath Foundation, ActivityWatch/activitywatch#632) require product name/version metadata on each signed executable. The Rust binaries in the Windows bundle currently ship without a VERSIONINFO resource. Generate the resource script in OUT_DIR and link it via embed-resource's compile_for, which scopes it to the named binary target only: the aw-server library (used by aw-tauri) gets no resource, so no duplicate VERSIONINFO. No-op for non-Windows targets, including Android. AW_VERSION, when set, overrides the product version so all bundled exes report the release version. CI asserts the resource on the windows-latest build. Git-Session-Id: 8ff886b3-a994-4b4f-9425-e72784bd3d1c --- .github/workflows/build.yml | 12 ++++ Cargo.lock | 96 +++++++++++++++++++++++++++++-- aw-server/Cargo.toml | 3 + aw-server/build.rs | 4 ++ aw-sync/Cargo.toml | 3 + aw-sync/build.rs | 5 ++ build-support/windows_resource.rs | 85 +++++++++++++++++++++++++++ 7 files changed, 203 insertions(+), 5 deletions(-) create mode 100644 aw-sync/build.rs create mode 100644 build-support/windows_resource.rs diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 008cee326..e39898cd9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -40,6 +40,18 @@ jobs: ${{ runner.os }}-${{ env.cache-name }}-${{ steps.toolchain.outputs.cachekey }}- - name: Build run: cargo build --workspace --verbose + # Code-signing services require product name/version metadata on each exe. + - name: Check Windows version resources + if: runner.os == 'Windows' + shell: pwsh + run: | + foreach ($exe in 'aw-server', 'aw-sync') { + $info = (Get-Item "target/debug/$exe.exe").VersionInfo + "${exe}: $($info.ProductName) $($info.ProductVersion) (file $($info.FileVersion))" + if ($info.ProductName -ne 'ActivityWatch' -or $info.OriginalFilename -ne "$exe.exe") { + throw "$exe.exe has no ActivityWatch version resource" + } + } # Known Folder APIs ignore env-var overrides, so the recovery matrix needs a # disposable native profile. This proves that seam before any fixture work. # It runs before the test suite on purpose: the existing tests already create diff --git a/Cargo.lock b/Cargo.lock index 21f64650d..471e6e9ea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -271,6 +271,7 @@ dependencies = [ "clap", "criterion", "dirs", + "embed-resource", "fern", "gethostname", "jemallocator", @@ -310,6 +311,7 @@ dependencies = [ "clap", "ctrlc", "dirs", + "embed-resource", "gethostname", "jni 0.21.1", "log", @@ -827,7 +829,7 @@ dependencies = [ "libc", "option-ext", "redox_users", - "windows-sys 0.59.0", + "windows-sys 0.61.2", ] [[package]] @@ -853,6 +855,20 @@ version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" +[[package]] +name = "embed-resource" +version = "3.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6168487b5e7eb2673e6efe1200b1848016e436a6ca0b8031bf04bd9d493a249f" +dependencies = [ + "cc", + "memchr", + "rustc_version", + "toml 1.1.8+spec-1.1.0", + "vswhom", + "winreg", +] + [[package]] name = "encoding_rs" version = "0.8.35" @@ -1542,13 +1558,14 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.10.0" +version = "2.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe4cd85333e22411419a0bcae1297d25e58c9443848b11dc6a86fefe8c78a661" +checksum = "cc4e190f5d26ca7051642629da2c52fc03bde85a03197c99408dcd291734c855" dependencies = [ "equivalent", - "hashbrown 0.15.4", + "hashbrown 0.17.1", "serde", + "serde_core", ] [[package]] @@ -1893,7 +1910,7 @@ version = "0.50.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" dependencies = [ - "windows-sys 0.59.0", + "windows-sys 0.61.2", ] [[package]] @@ -2712,6 +2729,15 @@ version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94300abf3f1ae2e2b8ffb7b58043de3d399c73fa6f4b73826402a5c457614dbe" +[[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver", +] + [[package]] name = "rustix" version = "1.0.8" @@ -2896,6 +2922,12 @@ dependencies = [ "libc", ] +[[package]] +name = "semver" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd" + [[package]] name = "serde" version = "1.0.228" @@ -3405,6 +3437,21 @@ dependencies = [ "winnow 0.7.12", ] +[[package]] +name = "toml" +version = "1.1.8+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20489e00e4d8741d6be680764cc12e270655e375a20d1011e844a9c3379e678d" +dependencies = [ + "indexmap", + "serde_core", + "serde_spanned 1.1.2", + "toml_datetime 1.1.3+spec-1.1.0", + "toml_parser", + "toml_writer", + "winnow 1.0.4", +] + [[package]] name = "toml_datetime" version = "0.6.11" @@ -3423,6 +3470,15 @@ dependencies = [ "serde_core", ] +[[package]] +name = "toml_datetime" +version = "1.1.3+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "173f25c883cd2176a2d8212155638c0a60d484a9d84546d270866f40f56b6e49" +dependencies = [ + "serde_core", +] + [[package]] name = "toml_edit" version = "0.22.27" @@ -3688,6 +3744,26 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" +[[package]] +name = "vswhom" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be979b7f07507105799e854203b470ff7c78a1639e330a58f183b5fea574608b" +dependencies = [ + "libc", + "vswhom-sys", +] + +[[package]] +name = "vswhom-sys" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb067e4cbd1ff067d1df46c9194b5de0e98efd2810bbc95c5d5e5f25a3231150" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "wait-timeout" version = "0.2.1" @@ -4185,6 +4261,16 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23b97319f7b8343df12cc98938e5c3eb436064524c8d2b4e30a1d3a36eecdf81" +[[package]] +name = "winreg" +version = "0.56.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d6f32a0ff4a9f6f01231eb2059cc85479330739333e0e58cadf03b6af2cca10" +dependencies = [ + "cfg-if", + "windows-sys 0.61.2", +] + [[package]] name = "wit-bindgen-rt" version = "0.39.0" diff --git a/aw-server/Cargo.toml b/aw-server/Cargo.toml index 23f69d34d..81e0c4f78 100644 --- a/aw-server/Cargo.toml +++ b/aw-server/Cargo.toml @@ -23,6 +23,9 @@ encryption = ["aw-datastore/encryption"] # Enable SQLCipher encryption with vendored OpenSSL (fully self-contained) encryption-vendored = ["aw-datastore/encryption-vendored"] +[build-dependencies] +embed-resource = "3" + [dependencies] rocket = { version = "0.5.0", features = ["json"] } rocket_cors = { version = "0.6.0" } diff --git a/aw-server/build.rs b/aw-server/build.rs index 7146eee72..7e082235b 100644 --- a/aw-server/build.rs +++ b/aw-server/build.rs @@ -1,5 +1,7 @@ use std::error::Error; +include!("../build-support/windows_resource.rs"); + fn main() -> Result<(), Box> { let webui_var = std::env::var("AW_WEBUI_DIR"); let path = if let Ok(var_path) = &webui_var { @@ -26,5 +28,7 @@ fn main() -> Result<(), Box> { println!("cargo:rerun-if-changed={dir}"); } + embed_windows_version_resource("aw-server", "ActivityWatch server"); + Ok(()) } diff --git a/aw-sync/Cargo.toml b/aw-sync/Cargo.toml index 8712c3ac2..5bafc7588 100644 --- a/aw-sync/Cargo.toml +++ b/aw-sync/Cargo.toml @@ -13,6 +13,9 @@ crate-type = ["cdylib", "rlib"] name = "aw-sync" path = "src/main.rs" +[build-dependencies] +embed-resource = "3" + [dependencies] log = "0.4" toml = "0.9" diff --git a/aw-sync/build.rs b/aw-sync/build.rs new file mode 100644 index 000000000..d574fd9d0 --- /dev/null +++ b/aw-sync/build.rs @@ -0,0 +1,5 @@ +include!("../build-support/windows_resource.rs"); + +fn main() { + embed_windows_version_resource("aw-sync", "ActivityWatch sync"); +} diff --git a/build-support/windows_resource.rs b/build-support/windows_resource.rs new file mode 100644 index 000000000..88f672506 --- /dev/null +++ b/build-support/windows_resource.rs @@ -0,0 +1,85 @@ +// Shared by the aw-server and aw-sync build scripts via `include!`. +// +// Embeds a PE version resource (VS_VERSION_INFO) in the Windows executables. +// Code-signing services (e.g. SignPath Foundation) require consistent product +// name/version metadata on every signed binary. +// +// The resource is linked only into the named binary target, never into the +// library, so crates that depend on aw-server (e.g. aw-tauri) do not pick up a +// second VERSIONINFO resource. Does nothing when the target is not Windows. + +/// `AW_VERSION` (the ActivityWatch release version, e.g. "0.14.2") overrides +/// the crate version as the product version, so all bundled executables agree. +fn embed_windows_version_resource(bin: &str, description: &str) { + println!("cargo:rerun-if-env-changed=AW_VERSION"); + if std::env::var("CARGO_CFG_TARGET_OS").as_deref() != Ok("windows") { + return; + } + + let file_version = std::env::var("CARGO_PKG_VERSION").unwrap(); + let product_version = std::env::var("AW_VERSION") + .ok() + .map(|v| v.trim().trim_start_matches('v').to_string()) + .filter(|v| !v.is_empty()) + .unwrap_or_else(|| file_version.clone()); + + let rc = format!( + r#"#include + +VS_VERSION_INFO VERSIONINFO +FILEVERSION {file_nums} +PRODUCTVERSION {product_nums} +FILEFLAGSMASK VS_FFI_FILEFLAGSMASK +FILEFLAGS 0 +FILEOS VOS_NT_WINDOWS32 +FILETYPE VFT_APP +FILESUBTYPE VFT2_UNKNOWN +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904B0" + BEGIN + VALUE "CompanyName", "ActivityWatch Contributors" + VALUE "FileDescription", "{description}" + VALUE "FileVersion", "{file_version}" + VALUE "InternalName", "{bin}" + VALUE "OriginalFilename", "{bin}.exe" + VALUE "ProductName", "ActivityWatch" + VALUE "ProductVersion", "{product_version}" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END +"#, + file_nums = version_numbers(&file_version), + product_nums = version_numbers(&product_version), + ); + + let out_dir = std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap()); + let rc_path = out_dir.join(format!("{bin}-version.rc")); + std::fs::write(&rc_path, rc).expect("failed to write version resource script"); + embed_resource::compile_for(&rc_path, [bin], embed_resource::NONE) + .manifest_optional() + .expect("failed to compile Windows version resource"); +} + +/// Leading numeric part as four comma-separated numbers: "0.14.0b5" -> "0,14,0,0". +fn version_numbers(version: &str) -> String { + let prefix: String = version + .chars() + .take_while(|c| c.is_ascii_digit() || *c == '.') + .collect(); + let mut nums: Vec = prefix + .split('.') + .filter_map(|n| n.parse().ok()) + .take(4) + .collect(); + nums.resize(4, 0); + nums.iter() + .map(u16::to_string) + .collect::>() + .join(",") +} From fa816992ba0421571d9fae5ab81279e460da2bdf Mon Sep 17 00:00:00 2001 From: TimeToBuildBob Date: Sat, 14 Nov 2026 17:33:40 +0000 Subject: [PATCH 2/2] fix(windows): require resource compiler and verify version overrides Git-Session-Id: 7e20fb0e-1567-5ea7-bba7-499e7eeeafa8 --- .github/workflows/build.yml | 34 ++++++++++++++++++++++++++----- build-support/windows_resource.rs | 2 +- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e39898cd9..b2a9850c5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -45,13 +45,37 @@ jobs: if: runner.os == 'Windows' shell: pwsh run: | - foreach ($exe in 'aw-server', 'aw-sync') { - $info = (Get-Item "target/debug/$exe.exe").VersionInfo - "${exe}: $($info.ProductName) $($info.ProductVersion) (file $($info.FileVersion))" - if ($info.ProductName -ne 'ActivityWatch' -or $info.OriginalFilename -ne "$exe.exe") { - throw "$exe.exe has no ActivityWatch version resource" + $metadataJson = cargo metadata --no-deps --format-version 1 + if ($LASTEXITCODE -ne 0) { throw 'cargo metadata failed' } + $packages = ($metadataJson | ConvertFrom-Json).packages + function Assert-VersionResources([string]$ProductVersion = '') { + foreach ($exe in 'aw-server', 'aw-sync') { + $crateVersion = ($packages | Where-Object name -eq $exe).version + if (-not $crateVersion) { throw "missing crate version for $exe" } + $expectedProduct = if ($ProductVersion) { $ProductVersion } else { $crateVersion } + $info = (Get-Item "target/debug/$exe.exe").VersionInfo + "${exe}: $($info.ProductName) $($info.ProductVersion) (file $($info.FileVersion))" + if ($info.ProductName -ne 'ActivityWatch' -or $info.OriginalFilename -ne "$exe.exe" -or + $info.FileVersion -ne $crateVersion -or $info.ProductVersion -ne $expectedProduct) { + throw "$exe.exe: expected ActivityWatch, $exe.exe, FileVersion=$crateVersion, ProductVersion=$expectedProduct" + } } } + # Check the initial build's crate-version fallback, then prove changing + # AW_VERSION alone rebuilds both resources without changing FileVersion. + Assert-VersionResources + try { + $env:AW_VERSION = 'v9.8.7' + cargo build -p aw-server -p aw-sync --verbose + if ($LASTEXITCODE -ne 0) { throw 'AW_VERSION override build failed' } + Assert-VersionResources -ProductVersion '9.8.7' + } finally { + Remove-Item Env:AW_VERSION -ErrorAction SilentlyContinue + } + # Do not upload binaries carrying the synthetic test product version. + cargo build -p aw-server -p aw-sync --verbose + if ($LASTEXITCODE -ne 0) { throw 'crate-version fallback rebuild failed' } + Assert-VersionResources # Known Folder APIs ignore env-var overrides, so the recovery matrix needs a # disposable native profile. This proves that seam before any fixture work. # It runs before the test suite on purpose: the existing tests already create diff --git a/build-support/windows_resource.rs b/build-support/windows_resource.rs index 88f672506..17736ab37 100644 --- a/build-support/windows_resource.rs +++ b/build-support/windows_resource.rs @@ -62,7 +62,7 @@ END let rc_path = out_dir.join(format!("{bin}-version.rc")); std::fs::write(&rc_path, rc).expect("failed to write version resource script"); embed_resource::compile_for(&rc_path, [bin], embed_resource::NONE) - .manifest_optional() + .manifest_required() .expect("failed to compile Windows version resource"); }