From eeeeb13f0ea156b90cf68d26e1fb5a4a9f66f663 Mon Sep 17 00:00:00 2001 From: Higgs32584 Date: Sun, 18 Oct 2026 18:25:22 -0400 Subject: [PATCH] Print: restore the winsafe dependency, the DLL check and its tests lost in merges (#5884) The merges from main dropped three parts of 86f6199b: - `winsafe` from crates/engine/Cargo.toml (Cargo.lock still listed it, so every `--locked` CI step failed). It now sits in the engine's existing `cfg(windows)` dependency table next to `same-file`. - the `require_windows_pdf()` call. Main moved `craft_print::submit` into `spool_job`, so the check now runs there, right before the Windows spooler route; that is the only call that reaches winprint's `WinPdfPrinter` (Windows.Data.Pdf.dll). The native RGB route, IPP, the app spooler and Save as PDF don't need the DLL and are unchanged. - the Windows load test and the no-op test for other platforms. Co-Authored-By: Claude Opus 5.5 --- crates/engine/Cargo.toml | 3 +++ crates/engine/src/print_cmds.rs | 1 + crates/engine/src/print_cmds/tests.rs | 26 ++++++++++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/crates/engine/Cargo.toml b/crates/engine/Cargo.toml index fb3bc3fbec..6b710eab93 100644 --- a/crates/engine/Cargo.toml +++ b/crates/engine/Cargo.toml @@ -47,6 +47,9 @@ tempfile = "3" # file is that file (std's `MetadataExt::file_index` is unstable). [target.'cfg(windows)'.dependencies] same-file = "1" +# `file.print` loads Windows.Data.Pdf.dll before calling into it (#5884): the safe binding +# ui-egui and craft-print already use, pinned to the same version. +winsafe = { version = "=0.0.29", default-features = false, features = ["kernel"] } # Printing on Unix: an IPP client for CUPS (pure Rust); the web build cannot print. [target.'cfg(all(not(target_arch = "wasm32"), not(target_os = "windows")))'.dependencies] diff --git a/crates/engine/src/print_cmds.rs b/crates/engine/src/print_cmds.rs index 9d84195415..e657a60521 100644 --- a/crates/engine/src/print_cmds.rs +++ b/crates/engine/src/print_cmds.rs @@ -90,6 +90,7 @@ fn spool_job(spooler: Option<&Spooler>, job: &PrintJob, lp: &craft_print::Job) - return app(sp); } if let Some(name) = system_spooler() { + require_windows_pdf()?; return craft_print::submit(&job.pdf, lp).map(|m| (m, name.to_string())).map_err(other); } } diff --git a/crates/engine/src/print_cmds/tests.rs b/crates/engine/src/print_cmds/tests.rs index c54dddf6f8..2b0f71bc14 100644 --- a/crates/engine/src/print_cmds/tests.rs +++ b/crates/engine/src/print_cmds/tests.rs @@ -772,3 +772,29 @@ mod cups { assert_eq!(jobs, 2, "both prints reached the fake CUPS"); } } + +#[cfg(target_os = "windows")] +#[test] +fn windows_pdf_component_is_detected_by_loading_its_dll() { + // #5884: a Windows image without a loadable Windows.Data.Pdf.dll reports an error instead of + // aborting at the delay-load stub. + let dir = tempfile::tempdir().unwrap(); + let dll = windows_pdf_dll(dir.path()); + assert!(!windows_pdf_loads(&dll)); + // Present but not loadable counts as missing. + std::fs::create_dir(dir.path().join("System32")).unwrap(); + std::fs::write(&dll, b"MZ").unwrap(); + assert!(!windows_pdf_loads(&dll)); + let root = std::env::var_os("SystemRoot").unwrap(); + let system = windows_pdf_dll(std::path::Path::new(&root)); + if system.is_file() { + assert!(windows_pdf_loads(&system)); + assert!(require_windows_pdf().is_ok()); + } +} + +#[cfg(not(target_os = "windows"))] +#[test] +fn the_windows_pdf_check_is_a_no_op_elsewhere() { + assert!(require_windows_pdf().is_ok()); +}