Skip to content

Commit

Permalink
build: include metadata in Windows binary (#1735)
Browse files Browse the repository at this point in the history
  • Loading branch information
liushuyu authored and Keats committed Feb 14, 2022
1 parent a5890a9 commit 821fa38
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

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

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
21 changes: 21 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,32 @@

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();
// app.gen_completions("zola", Shell::Bash, "completions/");
// 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();
}

0 comments on commit 821fa38

Please sign in to comment.