diff --git a/Cargo.lock b/Cargo.lock index bb980e6eef..6375eee29f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3576,6 +3576,7 @@ dependencies = [ "photocraft-io", "serde_json", "tokio", + "winresource", ] [[package]] diff --git a/apps/photocraft-cli/Cargo.toml b/apps/photocraft-cli/Cargo.toml index 8e85e6f9c3..a6d3b49389 100644 --- a/apps/photocraft-cli/Cargo.toml +++ b/apps/photocraft-cli/Cargo.toml @@ -4,6 +4,7 @@ description = "Headless Photocraft: convert, inspect, run commands, batch, MCP s version.workspace = true edition.workspace = true license.workspace = true +build = "build.rs" [features] # Open HEIC/HEIF photos (the optional photocraft-heif crate). Not default so distributors choose @@ -30,3 +31,7 @@ photocraft-codecs = { workspace = true } serde_json = { workspace = true } tokio = { version = "1", features = ["rt-multi-thread", "macros"] } +[build-dependencies] +# Icon + VERSIONINFO for photocraft-cli.exe; build.rs only uses it when targeting Windows. +winresource = "0.1" + diff --git a/apps/photocraft-cli/build.rs b/apps/photocraft-cli/build.rs new file mode 100644 index 0000000000..c757a4a7c5 --- /dev/null +++ b/apps/photocraft-cli/build.rs @@ -0,0 +1,36 @@ +//! Windows only: embed the app icon and version info (VERSIONINFO) into `photocraft-cli.exe`. +//! +//! On every other target this does nothing, even when `PHOTOCRAFT_REQUIRE_WINRES` is set. A +//! missing resource compiler is a warning, so a cross-compile from macOS or Linux still links, +//! unless `PHOTOCRAFT_REQUIRE_WINRES=1` (set by the release packaging script) turns it into a +//! build error. + +fn main() -> std::io::Result<()> { + println!("cargo:rerun-if-changed=build.rs"); + println!("cargo:rerun-if-changed=../../assets/app-icon/photocraft.ico"); + println!("cargo:rerun-if-env-changed=PHOTOCRAFT_REQUIRE_WINRES"); + if std::env::var("CARGO_CFG_TARGET_OS").as_deref() != Ok("windows") { + return Ok(()); + } + let mut res = winresource::WindowsResource::new(); + // FileVersion / ProductVersion strings and the numeric FILEVERSION / PRODUCTVERSION are left + // to `WindowsResource::new`, which reads the Cargo package version. A pre-release such as + // `1.2.3-rc.1` stays in the strings; the numeric fields are `1.2.3.0`. + res.set_icon("../../assets/app-icon/photocraft.ico") + .set("ProductName", "PhotoCraft") + .set("FileDescription", "PhotoCraft command-line interface") + .set("CompanyName", "Learning Machines LLC") + .set("LegalCopyright", "Copyright (c) the PhotoCraft authors. MIT OR Apache-2.0.") + .set("OriginalFilename", "photocraft-cli.exe") + .set("InternalName", "photocraft-cli"); + if let Err(err) = res.compile() { + if std::env::var_os("PHOTOCRAFT_REQUIRE_WINRES").is_some() { + return Err(std::io::Error::other(format!( + "embedding Windows resources into photocraft-cli.exe failed: {err}. \ + Install the Windows SDK resource compiler (rc.exe) or mingw-w64 windres and rebuild." + ))); + } + println!("cargo:warning=photocraft-cli.exe built without icon/version resources: {err}"); + } + Ok(()) +} diff --git a/docs/releasing.md b/docs/releasing.md index 1d25c04c4a..1122b5251c 100644 --- a/docs/releasing.md +++ b/docs/releasing.md @@ -116,10 +116,22 @@ The static C runtime means neither the MSI nor the portable zip needs the Visual redistributable, which matters for a standalone installer and costs only about 100 KB. The flag goes in `CARGO_TARGET__RUSTFLAGS`, so host build scripts aren't affected. -- `apps/photocraft/build.rs` embeds the icon (`assets/app-icon/photocraft.ico`) and - VERSIONINFO with the `winresource` crate. It only does this when targeting Windows. Elsewhere - it's a no-op, and the web build doesn't touch that crate. +- `apps/photocraft/build.rs` and `apps/photocraft-cli/build.rs` embed the icon + (`assets/app-icon/photocraft.ico`) and VERSIONINFO with the `winresource` crate + (build dependency `0.1`). They only do this when targeting Windows. Elsewhere each + script is a no-op, even if `PHOTOCRAFT_REQUIRE_WINRES` is set, and the web build + doesn't touch that crate. Both set ProductName to PhotoCraft, CompanyName to + Learning Machines LLC and the same copyright line. The GUI description is + "PhotoCraft image editor" (`photocraft.exe`). The CLI description is + "PhotoCraft command-line interface", with OriginalFilename `photocraft-cli.exe` + and InternalName `photocraft-cli`. Version strings are the Cargo package version, + so a pre-release tag is kept; the numeric file and product versions are + winresource's `major.minor.patch.0`. A missing resource compiler warns, so an + optional cross-compile still links. `package.ps1` sets `PHOTOCRAFT_REQUIRE_WINRES=1`. + The CLI build script then returns an error naming `rc.exe` or `windres` and does + not panic. - Release builds use the GUI subsystem, so Start Menu launches don't open a console window. + The CLI stays console subsystem 3 so its output reaches the terminal. - `photocraft.wxs` (WiX v5) is a per-machine install into Program Files with an advertised Start Menu shortcut. PhotoCraft becomes the default app for `.pcraft` and is listed under "Open with" for PSD/PSB and image files. It also registers App Paths (Win+R `photocraft`).