diff options
| author | Gabriel Schneider <[email protected]> | 2026-09-24 13:02:06 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-01 00:12:14 -0300 |
| commit | 1ba82eedb79d6c9fbc9b80dcac9315645d141f25 (patch) | |
| tree | abb84617b7caeef02d0842eb06f0b0fd5e39824b | |
| parent | 7fdf5ed9d1dd433e4657b670b7831cec6e3d41ca (diff) | |
| download | pardes-1ba82eedb79d6c9fbc9b80dcac9315645d141f25.tar.gz pardes-1ba82eedb79d6c9fbc9b80dcac9315645d141f25.zip | |
Inflate MuPDF's streams with the zlib FreeType links
MuPDF compiled its bundled zlib 1.3.1 (ZLIB_SRC) into libmupdf.a, and the
freetype package links the zlib package, 1.3.2, for its gzip module: 68
symbols defined twice, with the linker keeping one of each. MuPDF now links
that same zlib artifact and stops compiling its own. build.zig asks
FreeType's build for zlib with the options FreeType asks with, which the
build's dependency cache answers with the very artifact FreeType links, so
the tty and the gui each carry exactly one zlib.
MuPDF hands zlib its own allocation functions on every stream, so nothing
about where the memory comes from changes. Every page of the three PDFs in
docs/ still renders bit for bit as before, at 144 and at 300 dpi.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
| -rw-r--r-- | build.zig | 13 | ||||
| -rw-r--r-- | mupdf.zig | 13 |
2 files changed, 17 insertions, 9 deletions
@@ -421,11 +421,19 @@ pub fn build(b: *std.Build) void { // One FreeType in a binary: the gui's glyph atlas links it and MuPDF is // built against it (see mupdf.zig). At c_optimize with the rest of the // vendored C, since MuPDF rasterizes a PDF's text through it. - const freetype: ?*std.Build.Step.Compile = if (freestanding_core) null else b.dependency("freetype", .{ + const freetype_dep: ?*std.Build.Dependency = if (freestanding_core) null else b.dependency("freetype", .{ .target = target, .optimize = c_optimize, .@"enable-libpng" = false, - }).artifact("freetype"); + }); + const freetype: ?*std.Build.Step.Compile = if (freetype_dep) |dep| dep.artifact("freetype") else null; + // ...and one zlib, the one FreeType links for its gzip module. Asked of + // FreeType's build with the options it asks with, the dependency cache + // hands back that same artifact rather than a second copy. + const zlib: ?*std.Build.Step.Compile = if (freetype_dep) |dep| + dep.builder.dependency("zlib", .{ .target = target, .optimize = c_optimize }).artifact("z") + else + null; if (enable_mupdf) { if (b.lazyDependency("mupdf", .{})) |mupdf_dep| { @@ -434,6 +442,7 @@ pub fn build(b: *std.Build) void { .optimize = c_optimize, .jpx = enable_jpx, .freetype = freetype.?, + .zlib = zlib.?, }); const mupdf_mod = b.createModule(.{ .target = target, @@ -41,6 +41,10 @@ pub fn add(b: *std.Build, io: std.Io, dependency: *std.Build.Dependency, options /// ran the slim one. MuPDF asks nothing of FreeType the full /// configuration lacks. freetype: *std.Build.Step.Compile, + /// The zlib FreeType links, which MuPDF links instead of compiling the + /// one it bundles (ZLIB_SRC): the two define the same symbols, as the + /// FreeTypes do. + zlib: *std.Build.Step.Compile, }) Result { const module = b.createModule(.{ .target = options.target, @@ -53,8 +57,9 @@ pub fn add(b: *std.Build, io: std.Io, dependency: *std.Build.Dependency, options // debug-locking/assertion paths. linkTo applies the same public-header // contract to consumers; keeping it here also covers every archive source. module.addCMacro("NDEBUG", "1"); - // The build's own FreeType, headers and all; see `freetype` above. + // The build's own FreeType and zlib, headers and all; see above. module.linkLibrary(options.freetype); + module.linkLibrary(options.zlib); // MuPDF itself uses wildcards for these two directories. The dependency // is immutable and content-addressed, so discovering the flat C lists at @@ -97,11 +102,6 @@ pub fn add(b: *std.Build, io: std.Io, dependency: *std.Build.Dependency, options }); module.addCSourceFiles(.{ .root = dependency.path(""), - .files = makeSources(b, makelists, "ZLIB_SRC"), - .flags = &.{ "-std=gnu11", "-DHAVE_UNISTD_H", "-DHAVE_STDARG_H" }, - }); - module.addCSourceFiles(.{ - .root = dependency.path(""), .files = makeSources(b, makelists, "JBIG2DEC_SRC"), .flags = &.{ "-std=gnu11", @@ -252,7 +252,6 @@ fn configureModule(module: *std.Build.Module, dependency: *std.Build.Dependency, module.addIncludePath(dependency.path("source/pdf")); module.addIncludePath(dependency.path("thirdparty/libjpeg")); module.addIncludePath(dependency.path("scripts/libjpeg")); - module.addIncludePath(dependency.path("thirdparty/zlib")); module.addIncludePath(dependency.path("thirdparty/jbig2dec")); // encode-jpx.c includes this header before its FZ_ENABLE_JPX guard. module.addIncludePath(dependency.path("thirdparty/openjpeg/src/lib/openjp2")); |
