Fail builds when required Windows resource embedding fails (#427)

The app build scripts stop the build when required Windows resources fail to embed (cargo::error instead of the ignored cargo:error). Fixes #264.
This commit is contained in:
NetterSilver
2026-11-02 17:40:59 +01:00
committed by GitHub
parent cf87e54725
commit a094ed23a9
3 changed files with 21 additions and 2 deletions
+1 -1
View File
@@ -22,7 +22,7 @@ fn main() {
res.set_manifest(MANIFEST).set("OriginalFilename", "craft-anything-cli.exe").set("InternalName", "craft-anything-cli");
if let Err(e) = res.compile() {
if std::env::var_os("CRAFT_ANYTHING_REQUIRE_WINRES").is_some() {
println!("cargo:error=embedding Windows resources failed: {e}");
println!("cargo::error=embedding Windows resources failed: {e}");
return;
}
println!("cargo:warning=craft-anything-cli.exe built without its DPI-aware manifest: {e}");
@@ -0,0 +1,19 @@
//! The app build scripts must fail the build (Cargo's `cargo::error` instruction) when Windows
//! resources are required. The single-colon `cargo:error=` form is ignored by Cargo as metadata.
use std::path::Path;
fn read(rel: &str) -> String {
let path = Path::new(env!("CARGO_MANIFEST_DIR")).join(rel);
std::fs::read_to_string(&path).unwrap_or_default()
}
#[test]
fn required_windows_resource_failure_uses_cargo_error_directive() {
for rel in ["build.rs", "../craft-anything/build.rs"] {
let src = read(rel);
assert!(!src.is_empty(), "{rel} should be readable");
assert!(!src.contains("cargo:error="), "{rel} emits the ignored single-colon error directive");
assert!(src.contains("cargo::error="), "{rel} must emit cargo::error= when resources are required");
}
}
+1 -1
View File
@@ -20,7 +20,7 @@ fn main() {
.set("InternalName", "craft-anything");
if let Err(e) = res.compile() {
if std::env::var_os("CRAFT_ANYTHING_REQUIRE_WINRES").is_some() {
println!("cargo:error=embedding Windows resources failed: {e}");
println!("cargo::error=embedding Windows resources failed: {e}");
return;
}
println!("cargo:warning=craft-anything.exe built without icon/version resources: {e}");