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
36 changes: 36 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,42 @@ 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: |
$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
Expand Down
96 changes: 91 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions aw-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
4 changes: 4 additions & 0 deletions aw-server/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::error::Error;

include!("../build-support/windows_resource.rs");

fn main() -> Result<(), Box<dyn Error>> {
let webui_var = std::env::var("AW_WEBUI_DIR");
let path = if let Ok(var_path) = &webui_var {
Expand All @@ -26,5 +28,7 @@ fn main() -> Result<(), Box<dyn Error>> {
println!("cargo:rerun-if-changed={dir}");
}

embed_windows_version_resource("aw-server", "ActivityWatch server");

Ok(())
}
3 changes: 3 additions & 0 deletions aw-sync/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions aw-sync/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include!("../build-support/windows_resource.rs");

fn main() {
embed_windows_version_resource("aw-sync", "ActivityWatch sync");
}
85 changes: 85 additions & 0 deletions build-support/windows_resource.rs
Original file line number Diff line number Diff line change
@@ -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 <winver.h>

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_required()
.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<u16> = prefix
.split('.')
.filter_map(|n| n.parse().ok())
.take(4)
.collect();
nums.resize(4, 0);
nums.iter()
.map(u16::to_string)
.collect::<Vec<_>>()
.join(",")
}
Loading