diff options
Diffstat (limited to 'build.zig')
| -rw-r--r-- | build.zig | 40 |
1 files changed, 17 insertions, 23 deletions
@@ -469,7 +469,12 @@ pub fn build(b: *std.Build) void { // hands back that same artifact rather than a second copy. const zlib = freetype_dep.builder.dependency("zlib", .{ .target = target, .optimize = c_optimize }).artifact("z"); - // The PDF addon (addons/pdf/pdf.c over MuPDF and pdf_bridge.c), built + // The kinds' C ABI (src/kinds/pardes_addon.h), translated once: the core's + // records are the header's, never a mirror of it. + const kind_mod = b.addTranslateC(.{ .root_source_file = b.path("src/kinds/pardes_addon.h"), .target = target, .optimize = optimize }).createModule(); + // ...and what an addon in Zig imports over it (src/kinds/addon.zig). + const addon_mod = b.createModule(.{ .root_source_file = b.path("src/kinds/addon.zig"), .target = target, .optimize = optimize, .imports = &.{.{ .name = "pardes_addon", .module = kind_mod }} }); + // The PDF addon (addons/pdf/pdf.zig over MuPDF through pdf_bridge.c), built // and installed as the image addon is: compiled only for a step that // needs it (`pdf`, the tests), though fetched at the first configure, // which Zig runs alike for every step. MuPDF is compiled against the @@ -489,25 +494,19 @@ pub fn build(b: *std.Build) void { .zlib = zlib, .pic = true, }); - const lib = b.addLibrary(.{ .name = "pdf", .linkage = .dynamic, .root_module = b.createModule(.{ .target = target, .optimize = c_optimize, .link_libc = true }) }); - mupdf.linkTo(lib.root_module); - lib.root_module.addIncludePath(b.path("src/kinds")); - lib.root_module.addIncludePath(b.path("addons/pdf")); - lib.root_module.addCSourceFile(.{ .file = b.path("addons/pdf/pdf.c"), .flags = &.{ "-std=gnu11", "-Wall", "-Wextra", "-Werror" } }); - lib.root_module.addCSourceFile(.{ .file = b.path("addons/pdf/pdf_bridge.c"), .flags = &.{"-std=gnu11"} }); + // The bridge's header translated here for pdf.zig (Zig 0.17 has no + // @cImport), as the kinds' header is for the core. + const bridge_mod = b.addTranslateC(.{ .root_source_file = b.path("addons/pdf/pdf_bridge.h"), .target = target, .optimize = c_optimize }).createModule(); + const pdf_mod = b.createModule(.{ .root_source_file = b.path("addons/pdf/pdf.zig"), .target = target, .optimize = c_optimize, .link_libc = true, .imports = &.{ .{ .name = "addon", .module = addon_mod }, .{ .name = "pdf_bridge", .module = bridge_mod } } }); + mupdf.linkTo(pdf_mod); + pdf_mod.addIncludePath(b.path("addons/pdf")); + pdf_mod.addCSourceFile(.{ .file = b.path("addons/pdf/pdf_bridge.c"), .flags = &.{"-std=gnu11"} }); + const lib = b.addLibrary(.{ .name = "pdf", .linkage = .dynamic, .root_module = pdf_mod }); lib.setVersionScript(b.addWriteFiles().add("pdf.map", "{ global: pardes_addon; local: *; };\n")); pdf_addon = lib; - // ...and for a static pardes the same C compiled into it, its - // export renamed: it is one of two in a binary (Addon.zig). - if (static_mod) |m| { - const in = b.addLibrary(.{ .name = "pdf-builtin", .linkage = .static, .root_module = b.createModule(.{ .target = target, .optimize = c_optimize, .link_libc = true }) }); - mupdf.linkTo(in.root_module); - in.root_module.addIncludePath(b.path("src/kinds")); - in.root_module.addIncludePath(b.path("addons/pdf")); - in.root_module.addCSourceFile(.{ .file = b.path("addons/pdf/pdf.c"), .flags = &.{ "-std=gnu11", "-Wall", "-Wextra", "-Werror", "-Dpardes_addon=pardes_addon_pdf" } }); - in.root_module.addCSourceFile(.{ .file = b.path("addons/pdf/pdf_bridge.c"), .flags = &.{"-std=gnu11"} }); - m.linkLibrary(in); - } + // ...and for a static pardes the same module compiled into it, + // which exports nothing there (Addon.zig reads its declaration). + if (static_mod) |m| m.addImport("pdf_addon", pdf_mod); mupdf_check.dependOn(mupdf_build.addProbe(b, mupdf, .{ .target = target, .pdf = b.path("docs/design.pdf"), @@ -831,11 +830,6 @@ pub fn build(b: *std.Build) void { // One call per module instead of one line per module per dependency, and // BEFORE the fold below, which reads what these imports put in the table. - // The kinds' C ABI (src/kinds/pardes_addon.h), translated once: the core's - // records are the header's, never a mirror of it. - const kind_mod = b.addTranslateC(.{ .root_source_file = b.path("src/kinds/pardes_addon.h"), .target = target, .optimize = optimize }).createModule(); - // ...and what an addon in Zig imports over it (src/kinds/addon.zig). - const addon_mod = b.createModule(.{ .root_source_file = b.path("src/kinds/addon.zig"), .target = target, .optimize = optimize, .imports = &.{.{ .name = "pardes_addon", .module = kind_mod }} }); // The image addon (addons/image/image.zig over stb_image, stb.c), // installed by its step and handed by path to every test that opens a // picture. |
