Skip to content

Commit

Permalink
gui build: add manifest to avoid STATUS_ENTRYPOINT_NOT_FOUND error
Browse files Browse the repository at this point in the history
  • Loading branch information
eugenesvk committed Apr 22, 2024
1 parent a51fb83 commit 98f67d1
Showing 1 changed file with 59 additions and 1 deletion.
60 changes: 59 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
fn main() -> std::io::Result<()> {
#[cfg(all(target_os = "windows", feature = "win_manifest"))]
#[cfg(all(target_os = "windows", any(feature = "win_manifest",feature = "gui")))]
{
windows::build()?;
}
Expand Down Expand Up @@ -59,3 +59,61 @@ mod windows {
Ok(())
}
}

#[cfg(all(target_os = "windows", feature = "gui"))]
mod windows {
use indoc::formatdoc;
use regex::Regex;
use std::fs::File;
use std::io::Write;
extern crate embed_resource;

// println! during build
macro_rules! pb {
($($tokens:tt)*) => {println!("cargo:warning={}", format!($($tokens)*))}}

pub(super) fn build() -> std::io::Result<()> {
let manifest_path: &str = "./target/kanata.exe.manifest";

// Note about expected version format:
// MS says "Use the four-part version format: mmmmm.nnnnn.ooooo.ppppp"
// https://learn.microsoft.com/en-us/windows/win32/sbscs/application-manifests

let re_ver_build = Regex::new(r"^(?<vpre>(\d+\.){2}\d+)[-a-zA-Z]+(?<vpos>\d+)$").unwrap();
let re_version3 = Regex::new(r"^(\d+\.){2}\d+$").unwrap();
let mut version: String = env!("CARGO_PKG_VERSION").to_string();

if re_version3.find(&version).is_some() {
version = format!("{}.0", version);
} else if re_ver_build.find(&version).is_some() {
version = re_ver_build
.replace_all(&version, r"$vpre.$vpos")
.to_string();
} else {
pb!("unknown version format '{}', using '0.0.0.0'", version);
version = "0.0.0.0".to_string();
}

let manifest_str = formatdoc!(
r#"<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity name="kanata.exe" version="{}" type="win32"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges><requestedExecutionLevel level="asInvoker" uiAccess="false"/></requestedPrivileges>
</security>
</trustInfo>
<dependency><dependentAssembly>
<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls"
version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*"/></dependentAssembly>
</dependency>
</assembly>
"#,
version
);
let mut manifest_f = File::create(manifest_path)?;
write!(manifest_f, "{}", manifest_str)?;
embed_resource::compile("./src/kanata.exe.manifest.rc", embed_resource::NONE);
Ok(())
}
}

0 comments on commit 98f67d1

Please sign in to comment.