Windows and Linux build environments; check clean on both (E-01)

MuPDF builds with MSBuild on Windows (/MT, OpenSSL from vcpkg);
Git for Windows' MinGit stands in for the source build there. CEF
loads from where libcef lives and sets its API version first on
every platform. File identity on Windows compares volume and index.
The checkout and reference/ keep LF on Windows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ZacharyZhang-NYandClaude Opus 5.5 committed 2026-10-10 03:53:56 -04:00
1 parent d59159cea2
commit 68b5af76e0
40 files changed
+380 -82

No files matched your search

+36 -9
View File
@@ -57,7 +57,11 @@ fn main() {
}
println!("cargo:rustc-env=ELY_PDF_BUILD={stamp:016x}");
println!("cargo:rerun-if-env-changed=ELY_MUPDF_DIR");
for lib in ["libmupdf.a", "libmupdf-third.a", "libmupdf-pkcs7.a"] {
let windows = std::env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("windows");
// MSVC's libmupdf.lib holds its third parties and PKCS#7.
let libs: &[&str] =
if windows { &["libmupdf.lib"] } else { &["libmupdf-pkcs7.a", "libmupdf.a", "libmupdf-third.a"] };
for lib in libs {
println!("cargo:rerun-if-changed={}", mupdf.join(lib).display());
if !mupdf.join(lib).is_file() {
panic!("no {lib} in {} (run scripts/build-mupdf.sh or set ELY_MUPDF_DIR)", mupdf.display());
@@ -83,26 +87,49 @@ fn main() {
.file("shim/ely_sign.c")
.file("shim/ely_output.c")
.include(root.join("reference/mupdf/include"))
.include(openssl("includedir"))
.include(openssl(&root, "includedir"))
.warnings(true)
.cargo_metadata(false)
.compile("ely_mupdf");
let out = PathBuf::from(std::env::var("OUT_DIR").expect("set by cargo"));
let bin = "ely-pdf-worker";
println!("cargo:rustc-link-arg-bin={bin}={}", out.join("libely_mupdf.a").display());
println!("cargo:rustc-link-arg-bin={bin}={}", mupdf.join("libmupdf-pkcs7.a").display());
println!("cargo:rustc-link-arg-bin={bin}={}", mupdf.join("libmupdf.a").display());
println!("cargo:rustc-link-arg-bin={bin}={}", mupdf.join("libmupdf-third.a").display());
let shim = if windows { "ely_mupdf.lib" } else { "libely_mupdf.a" };
println!("cargo:rustc-link-arg-bin={bin}={}", out.join(shim).display());
for lib in libs {
println!("cargo:rustc-link-arg-bin={bin}={}", mupdf.join(lib).display());
}
// Signing and checking need OpenSSL, linked in whole.
println!("cargo:rustc-link-arg-bin={bin}={}", PathBuf::from(openssl("libdir")).join("libcrypto.a").display());
let crypto = if windows { "libcrypto.lib" } else { "libcrypto.a" };
println!("cargo:rustc-link-arg-bin={bin}={}", PathBuf::from(openssl(&root, "libdir")).join(crypto).display());
if windows {
for lib in ["crypt32.lib", "ws2_32.lib", "advapi32.lib", "user32.lib"] {
println!("cargo:rustc-link-arg-bin={bin}={lib}");
}
return;
}
// What a static libcrypto needs, as its pkg-config says.
let needs = std::process::Command::new("pkg-config")
.args(["--static", "--libs-only-l", "libcrypto"])
.output()
.expect("pkg-config, to find OpenSSL");
assert!(needs.status.success(), "pkg-config knows no static libcrypto");
for lib in String::from_utf8(needs.stdout).expect("UTF-8 flags").split_whitespace().filter(|lib| *lib != "-lcrypto") {
println!("cargo:rustc-link-arg-bin={bin}={lib}");
}
println!("cargo:rustc-link-arg-bin={bin}=-lm");
// Tesseract inside MuPDF is C++.
let cxx = if std::env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("macos") { "-lc++" } else { "-lstdc++" };
println!("cargo:rustc-link-arg-bin={bin}={cxx}");
}
/// An OpenSSL directory, from pkg-config.
fn openssl(variable: &str) -> String {
/// An OpenSSL directory: vcpkg's static build on Windows, else pkg-config's.
fn openssl(root: &std::path::Path, variable: &str) -> String {
if std::env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("windows") {
let dir = root.join("engines/vcpkg/installed/x64-windows-static");
let sub = if variable == "includedir" { "include" } else { "lib" };
assert!(dir.join("lib/libcrypto.lib").is_file(), "no static OpenSSL in {}", dir.display());
return dir.join(sub).display().to_string();
}
let out = std::process::Command::new("pkg-config")
.args([&format!("--variable={variable}"), "libcrypto"])
.output()