diff --git a/Cargo.lock b/Cargo.lock index 381bcedb15..353f0add0c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3687,6 +3687,15 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "winres" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b68db261ef59e9e52806f688020631e987592bd83619edccda9c47d42cde4f6c" +dependencies = [ + "toml", +] + [[package]] name = "ws" version = "0.9.1" @@ -3784,7 +3793,9 @@ dependencies = [ "search", "site", "termcolor", + "time 0.3.7", "tokio", "utils", + "winres", "ws", ] diff --git a/Cargo.toml b/Cargo.toml index 7e14095b23..316c5f0c4e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,8 @@ include = ["src/**/*", "LICENSE", "README.md"] [build-dependencies] clap = "3" clap_complete = "3" +winres = "0.1" +time = "0.3" [[bin]] name = "zola" @@ -64,3 +66,7 @@ codegen-units = 1 # Disabling debug info speeds up builds a bunch, # and we don't rely on it for debugging that much. debug = 0 + +[package.metadata.winres] +OriginalFilename = "zola.exe" +InternalName = "zola" diff --git a/build.rs b/build.rs index f6e897786b..7df44f1f90 100644 --- a/build.rs +++ b/build.rs @@ -2,6 +2,21 @@ include!("src/cli.rs"); +fn generate_pe_header() { + use time::OffsetDateTime; + + let today = OffsetDateTime::now_utc(); + let copyright = format!("Copyright © 2017-{} Vincent Prouillet", today.year()); + let mut res = winres::WindowsResource::new(); + // needed for MinGW cross-compiling + if cfg!(unix) { + res.set_windres_path("x86_64-w64-mingw32-windres"); + } + res.set_icon("docs/static/favicon.ico"); + res.set("LegalCopyright", ©right); + res.compile().expect("Failed to compile Windows resources!"); +} + fn main() { // disabled below as it fails in CI // let mut app = build_cli(); @@ -9,4 +24,10 @@ fn main() { // app.gen_completions("zola", Shell::Fish, "completions/"); // app.gen_completions("zola", Shell::Zsh, "completions/"); // app.gen_completions("zola", Shell::PowerShell, "completions/"); + if std::env::var("CARGO_CFG_TARGET_OS").unwrap() != "windows" + && std::env::var("PROFILE").unwrap() != "release" + { + return; + } + generate_pe_header(); }