summaryrefslogtreecommitdiff
path: root/mupdf.zig
diff options
context:
space:
mode:
Diffstat (limited to 'mupdf.zig')
-rw-r--r--mupdf.zig47
1 files changed, 25 insertions, 22 deletions
diff --git a/mupdf.zig b/mupdf.zig
index 400e5ee3..761fef92 100644
--- a/mupdf.zig
+++ b/mupdf.zig
@@ -33,6 +33,18 @@ pub fn add(b: *std.Build, io: std.Io, dependency: *std.Build.Dependency, options
/// Compile openjpeg and let MuPDF decode JPEG 2000. See the OPENJPEG
/// block below for why this is a switch rather than always-on.
jpx: bool = true,
+ /// The FreeType the rest of the build links, which MuPDF is compiled
+ /// against and links instead of the slim one it bundles (FREETYPE_SRC,
+ /// configured by scripts/freetype). Both define the same symbols and a
+ /// linker handed two keeps one of each, so the gui's MuPDF ran the full
+ /// FreeType's code compiled against the slim one's headers, while the tty
+ /// 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,
@@ -45,6 +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 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
@@ -82,29 +97,20 @@ pub fn add(b: *std.Build, io: std.Io, dependency: *std.Build.Dependency, options
const makelists = readMakelists(b, io, dependency);
module.addCSourceFiles(.{
.root = dependency.path(""),
- .files = makeSources(b, makelists, "FREETYPE_SRC"),
- .flags = &.{
- "-std=gnu11",
- "-DFT_CONFIG_MODULES_H=\"slimftmodules.h\"",
- "-DFT_CONFIG_OPTIONS_H=\"slimftoptions.h\"",
- "-DFT2_BUILD_LIBRARY",
- },
- });
- module.addCSourceFiles(.{
- .root = dependency.path(""),
.files = makeSources(b, makelists, "LIBJPEG_SRC"),
- .flags = &.{"-std=gnu11"},
- });
- module.addCSourceFiles(.{
- .root = dependency.path(""),
- .files = makeSources(b, makelists, "ZLIB_SRC"),
- .flags = &.{ "-std=gnu11", "-DHAVE_UNISTD_H", "-DHAVE_STDARG_H" },
+ // libjpeg calls back into source/fitz (filter-dct.c's source
+ // manager), which is built without UBSan: -fsanitize=function at
+ // such a call finds no type hash on the callee and traps, so any
+ // PDF with a DCT image crashed ReleaseSafe and Debug builds in
+ // jpeg_fill_bit_buffer. The same holds for jbig2dec below.
+ .flags = &.{ "-std=gnu11", "-fno-sanitize=undefined" },
});
module.addCSourceFiles(.{
.root = dependency.path(""),
.files = makeSources(b, makelists, "JBIG2DEC_SRC"),
.flags = &.{
"-std=gnu11",
+ "-fno-sanitize=undefined",
"-DHAVE_STDINT_H",
"-DJBIG_EXTERNAL_MEMENTO_H=\"mupdf/memento.h\"",
},
@@ -250,11 +256,8 @@ fn configureModule(module: *std.Build.Module, dependency: *std.Build.Dependency,
module.addIncludePath(dependency.path("include"));
module.addIncludePath(dependency.path("source/fitz"));
module.addIncludePath(dependency.path("source/pdf"));
- module.addIncludePath(dependency.path("thirdparty/freetype/include"));
- module.addIncludePath(dependency.path("scripts/freetype"));
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"));
@@ -290,7 +293,7 @@ fn configureModule(module: *std.Build.Module, dependency: *std.Build.Dependency,
}
fn flatCSources(b: *std.Build, io: std.Io, dependency: *std.Build.Dependency, relative_dir: []const u8) []const []const u8 {
- var dir = std.Io.Dir.cwd().openDir(io, dependency.path(relative_dir).getPath(b), .{ .iterate = true }) catch
+ var dir = dependency.builder.root.root_dir.handle.openDir(io, relative_dir, .{ .iterate = true }) catch
std.debug.panic("MuPDF source directory is missing: {s}", .{relative_dir});
defer dir.close(io);
@@ -314,9 +317,9 @@ fn flatCSources(b: *std.Build, io: std.Io, dependency: *std.Build.Dependency, re
}
fn readMakelists(b: *std.Build, io: std.Io, dependency: *std.Build.Dependency) []const u8 {
- return std.Io.Dir.cwd().readFileAlloc(
+ return dependency.builder.root.root_dir.handle.readFileAlloc(
io,
- dependency.path("Makelists").getPath(b),
+ "Makelists",
b.allocator,
.limited(1024 * 1024),
) catch @panic("read MuPDF Makelists");