aboutsummaryrefslogtreecommitdiff
path: root/build.zig
diff options
context:
space:
mode:
Diffstat (limited to 'build.zig')
-rw-r--r--build.zig58
1 files changed, 35 insertions, 23 deletions
diff --git a/build.zig b/build.zig
index 0af4927..cf4493c 100644
--- a/build.zig
+++ b/build.zig
@@ -8,6 +8,10 @@ pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
+ const short = b.option(bool, "short", "skip long tests") orelse false;
+ const options = b.addOptions();
+ options.addOption(bool, "short", short);
+
const install = b.getInstallStep();
// build typst module
@@ -17,44 +21,58 @@ pub fn build(b: *std.Build) void {
build_typst.setCwd(b.path(TYPST));
if (optimize != .Debug) build_typst.addArg("--release");
+ const typst = b.addTranslateC(.{
+ .root_source_file = b.path(TYPST ++ "/typdown_typst.h"),
+ .link_libc = true,
+ .target = target,
+ .optimize = optimize,
+ });
+
const mod = b.addModule("typdown", .{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
+ .imports = &.{
+ .{ .name = "typst", .module = typst.createModule() },
+ },
});
if (!target.result.isWasiLibC()) mod.link_libc = true;
if (optimize != .Debug) mod.strip = true;
+ mod.addOptions("config", options);
// find typst module
- mod.addIncludePath(b.path(TYPST));
+ mod.linkSystemLibrary("typdown_typst", .{ .preferred_link_mode = .static });
mod.addLibraryPath(if (optimize == .Debug) b.path(TYPST_DEBUG) else b.path(TYPST_RELEASE));
const lib = b.addLibrary(.{
.name = "typdown",
- .linkage = .static,
+ .linkage = .dynamic,
.root_module = mod,
.use_llvm = true, // zig internal backend crashes during linking (for 0.15.2)
});
- // link typst module
- lib.linkSystemLibrary("typdown_typst");
const installed_lib = b.addInstallArtifact(lib, .{});
installed_lib.step.dependOn(&build_typst.step);
// when emitting headers will be fixed
//installed_lib.emitted_h = lib.getEmittedH();
- const example = b.addExecutable(.{
- .name = "example",
- .root_module = b.createModule(.{
- .target = target,
- .optimize = optimize,
- .link_libc = true,
- }),
+ const example_mod = b.createModule(.{
+ .target = target,
+ .optimize = optimize,
+ .link_libc = true,
});
- example.root_module.addCSourceFile(.{
+ example_mod.addCSourceFile(.{
.file = b.path("examples/main.c"),
});
- example.root_module.linkLibrary(lib);
- example.root_module.addIncludePath(b.path("include"));
+ example_mod.linkLibrary(lib);
+ example_mod.addIncludePath(b.path("include"));
+ example_mod.linkSystemLibrary("typdown_typst", .{ .preferred_link_mode = .static });
+ example_mod.addLibraryPath(if (optimize == .Debug) b.path(TYPST_DEBUG) else b.path(TYPST_RELEASE));
+
+ const example = b.addExecutable(.{
+ .name = "example",
+ .root_module = example_mod,
+ });
+ example.step.dependOn(install);
install.dependOn(&installed_lib.step);
@@ -68,24 +86,18 @@ pub fn build(b: *std.Build) void {
install.dependOn(&fmt.step);
const test_step = b.step("test", "Run tests");
- const mod_tests = b.addTest(.{
+ const exe_tests = b.addTest(.{
.root_module = mod,
.use_llvm = true, // zig internal backend crashes during linking (for 0.15.2)
});
+ exe_tests.step.dependOn(install);
- const options = b.addOptions();
- const short = b.option(bool, "short", "skip long tests") orelse false;
- options.addOption(bool, "short", short);
- mod_tests.root_module.addOptions("config", options);
-
- const run_mod_tests = b.addRunArtifact(mod_tests);
+ const run_mod_tests = b.addRunArtifact(exe_tests);
generateSVG(b, &run_mod_tests.step) catch |err| run_mod_tests.step.addError("{}\n", .{err}) catch unreachable;
- run_mod_tests.step.dependOn(install);
test_step.dependOn(&run_mod_tests.step);
const examples_step = b.step("examples", "Run examples");
const example_run = b.addRunArtifact(example);
- example_run.step.dependOn(install);
examples_step.dependOn(&example_run.step);
const check = b.step("check", "Check if foo compiles");