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:
1 parent
d59159cea2
commit
68b5af76e0
40 files changed
+380
-82
No files matched your search
@@ -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()
|
||||
|
||||
@@ -146,7 +146,7 @@ static void write_file(fz_context *ctx, fz_output *out, const char *key, const c
|
||||
fz_write_string(ctx, out, ",\"name\":");
|
||||
ely_json_string(ctx, out, name);
|
||||
fz_write_printf(ctx, out, ",\"page\":%d,\"size\":%ld,\"created\":%ld,\"modified\":%ld,\"type\":", page,
|
||||
(long)file_size(ctx, fs), (long)params.created, (long)params.modified);
|
||||
file_size(ctx, fs), (int64_t)params.created, (int64_t)params.modified);
|
||||
ely_json_string(ctx, out, params.mimetype ? params.mimetype : "");
|
||||
fz_write_string(ctx, out, ",\"note\":");
|
||||
ely_json_string(ctx, out, pdf_dict_get_text_string(ctx, fs, PDF_NAME(Desc)));
|
||||
|
||||
@@ -255,7 +255,7 @@ int ely_text_layer(fz_context *ctx, fz_document *doc, const char *json, int repl
|
||||
{
|
||||
if (!font)
|
||||
font = glyphless(ctx, pdf);
|
||||
ely_add_resource(ctx, pdf, page->obj, PDF_NAME(Font), "ElyOCR", font, name, sizeof name);
|
||||
ely_add_resource(ctx, page->obj, PDF_NAME(Font), "ElyOCR", font, name, sizeof name);
|
||||
buf = fz_new_buffer(ctx, 1024);
|
||||
/* Its own state, so later text stays seen. */
|
||||
fz_append_string(ctx, buf, "q\n");
|
||||
|
||||
@@ -132,7 +132,7 @@ const char *ely_pen_resource(fz_context *ctx, pdf_document *pdf, pdf_page *page,
|
||||
p->ref = pdf_add_cjk_font(ctx, pdf, p->font, p->ordering, 0, 0);
|
||||
break;
|
||||
}
|
||||
return ely_add_resource(ctx, pdf, page->obj, PDF_NAME(Font), "ElyF", p->ref, name, room);
|
||||
return ely_add_resource(ctx, page->obj, PDF_NAME(Font), "ElyF", p->ref, name, room);
|
||||
}
|
||||
|
||||
/* The own font's code for `u`, or -1. */
|
||||
|
||||
@@ -38,6 +38,7 @@ static void inv_q(fz_context *ctx, pdf_processor *proc)
|
||||
static void inv_Q(fz_context *ctx, pdf_processor *proc)
|
||||
{
|
||||
inventory *inv = (inventory *)proc;
|
||||
(void)ctx;
|
||||
if (inv->depth > 0)
|
||||
inv->ctm = inv->stack[--inv->depth];
|
||||
}
|
||||
@@ -45,6 +46,7 @@ static void inv_Q(fz_context *ctx, pdf_processor *proc)
|
||||
static void inv_cm(fz_context *ctx, pdf_processor *proc, float a, float b, float c, float d, float e, float f)
|
||||
{
|
||||
inventory *inv = (inventory *)proc;
|
||||
(void)ctx;
|
||||
inv->ctm = fz_concat(fz_make_matrix(a, b, c, d, e, f), inv->ctm);
|
||||
}
|
||||
|
||||
@@ -62,12 +64,15 @@ static void found(fz_context *ctx, inventory *inv, int form, fz_rect box)
|
||||
|
||||
static void inv_image(fz_context *ctx, pdf_processor *proc, const char *name, fz_image *image)
|
||||
{
|
||||
(void)name;
|
||||
(void)image;
|
||||
found(ctx, (inventory *)proc, 0, fz_unit_rect);
|
||||
}
|
||||
|
||||
static void inv_form(fz_context *ctx, pdf_processor *proc, const char *name, pdf_obj *form)
|
||||
{
|
||||
fz_rect box = fz_transform_rect(pdf_xobject_bbox(ctx, form), pdf_xobject_matrix(ctx, form));
|
||||
(void)name;
|
||||
found(ctx, (inventory *)proc, 1, box);
|
||||
}
|
||||
|
||||
@@ -269,7 +274,7 @@ int ely_place(fz_context *ctx, fz_document *doc, int number, int index, const fl
|
||||
own = (float)image->w / image->h;
|
||||
change = fz_concat(fz_concat(fz_translate(-cx, -cy), fz_scale(fminf(1, own / box), fminf(1, box / own))), fz_translate(cx, cy));
|
||||
ref = pdf_add_image(ctx, pdf, image);
|
||||
h.rename = ely_add_resource(ctx, pdf, page->obj, PDF_NAME(XObject), "ElyIm", ref, name, sizeof name);
|
||||
h.rename = ely_add_resource(ctx, page->obj, PDF_NAME(XObject), "ElyIm", ref, name, sizeof name);
|
||||
}
|
||||
if (fz_matrix_expansion(change) < 0.001f)
|
||||
fz_throw(ctx, FZ_ERROR_ARGUMENT, "a change that leaves nothing");
|
||||
@@ -315,7 +320,7 @@ int ely_add_image(fz_context *ctx, fz_document *doc, int number, const char *pat
|
||||
pdf_begin_operation(ctx, pdf, "Add an image");
|
||||
begun = 1;
|
||||
ref = pdf_add_image(ctx, pdf, image);
|
||||
ely_add_resource(ctx, pdf, page->obj, PDF_NAME(XObject), "ElyIm", ref, name, sizeof name);
|
||||
ely_add_resource(ctx, page->obj, PDF_NAME(XObject), "ElyIm", ref, name, sizeof name);
|
||||
/* The unit square, bottom left first, onto the box. */
|
||||
m = fz_concat(fz_make_matrix(rect[2] - rect[0], 0, 0, rect[1] - rect[3], rect[0], rect[3]), ely_to_user(ctx, page));
|
||||
buf = fz_new_buffer(ctx, 128);
|
||||
|
||||
@@ -38,7 +38,7 @@ void ely_read_block(fz_context *ctx, fz_document *doc, pdf_page *page, int numbe
|
||||
void ely_remove_block(fz_context *ctx, pdf_document *pdf, pdf_page *page, ely_shape *shape);
|
||||
void ely_drop_shape(fz_context *ctx, ely_shape *shape);
|
||||
pdf_obj *ely_append_content(fz_context *ctx, pdf_document *pdf, pdf_obj *page, fz_buffer *buf);
|
||||
const char *ely_add_resource(fz_context *ctx, pdf_document *pdf, pdf_obj *page, pdf_obj *type, const char *stem,
|
||||
const char *ely_add_resource(fz_context *ctx, pdf_obj *page, pdf_obj *type, const char *stem,
|
||||
pdf_obj *ref, char *name, size_t room);
|
||||
void ely_json_string(fz_context *ctx, fz_output *out, const char *s);
|
||||
fz_json *ely_member(fz_context *ctx, fz_json *obj, const char *key, int type);
|
||||
|
||||
@@ -97,6 +97,10 @@ static int take_glyph(fz_context *ctx, void *opaque, int *ucs, int ucslen, fz_ma
|
||||
fz_rect bbox, int tr, float ca, float CA)
|
||||
{
|
||||
targets *t = opaque;
|
||||
(void)bbox;
|
||||
(void)tr;
|
||||
(void)ca;
|
||||
(void)CA;
|
||||
fz_point at = fz_transform_point(fz_transform_point(fz_make_point(0, 0), trm), ctm);
|
||||
/* MuPDF gives at most PDF_MRANGE_CAP; each spells to 18. */
|
||||
int i, k, found = 0, spelt[18 * PDF_MRANGE_CAP], n = 0;
|
||||
|
||||
@@ -68,7 +68,7 @@ static int lay_out(fz_context *ctx, ely_pen *p, const int *u, int n, float size,
|
||||
}
|
||||
|
||||
/* A resource name in `type` that is free, given `ref`. */
|
||||
const char *ely_add_resource(fz_context *ctx, pdf_document *pdf, pdf_obj *page, pdf_obj *type, const char *stem,
|
||||
const char *ely_add_resource(fz_context *ctx, pdf_obj *page, pdf_obj *type, const char *stem,
|
||||
pdf_obj *ref, char *name, size_t room)
|
||||
{
|
||||
pdf_obj *res = pdf_dict_get_inheritable(ctx, page, PDF_NAME(Resources));
|
||||
|
||||
@@ -186,6 +186,7 @@ fn a_reply_to_another_request_is_refused() {
|
||||
}
|
||||
|
||||
/// A noisy RGB PNG, stored uncompressed: large on disk.
|
||||
#[cfg(unix)]
|
||||
fn big_png(path: &Path, side: u32) {
|
||||
let crc = |bytes: &[u8]| {
|
||||
let mut crc = 0xffff_ffffu32;
|
||||
|
||||
Reference in new issue
Block a user