mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-10 13:01:29 +00:00
The pdfcraft-print unit-test executable imported windows.data.pdf.dll and prntvpt.dll at load time (the windows crate binds them with raw-dylib), so on a Windows installation without them it could not start, and the tests of the missing-DLL guard never ran there. crates/print/build.rs now passes /DELAYLOAD for both and delayimp.lib on MSVC, as the applications' build scripts do. Link arguments from a build script reach only this package's own executables, so dependents are unaffected. dumpbin /imports: before, both DLLs under "the following imports"; after, under "the following delay load imports". A copy of each test binary with prntvpt.dll renamed to a DLL that doesn't exist: the old one exits with 0xC0000135 (STATUS_DLL_NOT_FOUND) before main, the new one starts and runs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Pq7HyCfwzyRXj4VfQAVVdv
42 lines
2.1 KiB
Rust
42 lines
2.1 KiB
Rust
//! Windows only: embed version info (VERSIONINFO) into `pdfcraft-cli.exe`, so Explorer's
|
|
//! Details tab, `(Get-Item pdfcraft-cli.exe).VersionInfo` and inventory tools can read the version
|
|
//! and publisher, as they can for `pdfcraft.exe` (`apps/pdfcraft/build.rs`).
|
|
//!
|
|
//! On every other target this does nothing. A missing resource compiler is a warning, so a
|
|
//! cross-compile from macOS or Linux still links, unless `PDFCRAFT_REQUIRE_WINRES=1` turns it
|
|
//! into an error (for release builds).
|
|
|
|
/// The in-box DLLs only printing uses (Windows.Data.Pdf draws the job, prntvpt reads the
|
|
/// driver's print capabilities). Trimmed Windows installations (NTLite) can lack them, and a
|
|
/// load-time import of a missing DLL stops the program before `main` (#2630). Delay-loaded, they
|
|
/// load on the first print; `pdfcraft_print::spool` checks they exist before calling in.
|
|
/// Same list in `apps/pdfcraft{,-cli}/build.rs`, `crates/print/build.rs` and `crates/print/src/spool.rs`.
|
|
const DELAY_LOADED: [&str; 2] = ["windows.data.pdf.dll", "prntvpt.dll"];
|
|
|
|
fn main() {
|
|
println!("cargo:rerun-if-changed=build.rs");
|
|
println!("cargo:rerun-if-env-changed=PDFCRAFT_REQUIRE_WINRES");
|
|
if std::env::var("CARGO_CFG_TARGET_OS").as_deref() != Ok("windows") {
|
|
return;
|
|
}
|
|
if std::env::var("CARGO_CFG_TARGET_ENV").as_deref() == Ok("msvc") {
|
|
for dll in DELAY_LOADED {
|
|
println!("cargo:rustc-link-arg-bins=/DELAYLOAD:{dll}");
|
|
}
|
|
println!("cargo:rustc-link-arg-bins=delayimp.lib");
|
|
}
|
|
let mut res = winresource::WindowsResource::new();
|
|
res.set("ProductName", "PdfCraft")
|
|
.set("FileDescription", "PdfCraft command-line tool")
|
|
.set("LegalCopyright", "Copyright (c) the PdfCraft contributors. MIT OR Apache-2.0.")
|
|
.set("OriginalFilename", "pdfcraft-cli.exe")
|
|
.set("InternalName", "pdfcraft-cli");
|
|
if let Err(e) = res.compile() {
|
|
if std::env::var_os("PDFCRAFT_REQUIRE_WINRES").is_some() {
|
|
println!("cargo::error=embedding Windows resources failed: {e}");
|
|
return;
|
|
}
|
|
println!("cargo:warning=pdfcraft-cli.exe built without version resources: {e}");
|
|
}
|
|
}
|