build: include metadata in Windows binary (#1735)

This commit is contained in:
liushuyu 2022-02-07 04:42:23 -07:00 committed by Vincent Prouillet
parent a5890a9901
commit 821fa38bc1
3 changed files with 38 additions and 0 deletions

11
Cargo.lock generated
View File

@ -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",
]

View File

@ -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"

View File

@ -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", &copyright);
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();
}