|
| 1 | +const std = @import("std"); |
| 2 | + |
| 3 | +pub fn build(b: *std.Build) !void { |
| 4 | + const target = b.standardTargetOptions(.{}); |
| 5 | + const optimize = b.standardOptimizeOption(.{}); |
| 6 | + const pcre2_dep = b.dependency("pcre2", .{ |
| 7 | + .target = target, |
| 8 | + .optimize = optimize, |
| 9 | + }); |
| 10 | + // Exe |
| 11 | + const exe = b.addExecutable(.{ |
| 12 | + .name = "tokenizer_exe", |
| 13 | + .root_source_file = b.path("src/tokenizer.zig"), |
| 14 | + .target = target, |
| 15 | + .optimize = .ReleaseFast, |
| 16 | + }); |
| 17 | + exe.linkLibrary(pcre2_dep.artifact("pcre2-8")); |
| 18 | + const exe_install = b.addInstallArtifact(exe, .{}); |
| 19 | + const exe_step = b.step("exe", "Install executable"); |
| 20 | + exe_step.dependOn(&exe_install.step); |
| 21 | + // Run exe |
| 22 | + const exe_run = b.addRunArtifact(exe); |
| 23 | + if (b.args) |args| exe_run.addArgs(args); |
| 24 | + const run_step = b.step("run", "Run tokenizer app"); |
| 25 | + run_step.dependOn(&exe_run.step); |
| 26 | + // Tests |
| 27 | + const tst = b.addTest(.{ |
| 28 | + .root_source_file = b.path("src/tokenizer.zig"), |
| 29 | + .target = target, |
| 30 | + .optimize = optimize, |
| 31 | + }); |
| 32 | + tst.linkLibrary(pcre2_dep.artifact("pcre2-8")); |
| 33 | + // Run test |
| 34 | + const run_test = b.addRunArtifact(tst); |
| 35 | + const test_step = b.step("test", "Run tests"); |
| 36 | + test_step.dependOn(&run_test.step); |
| 37 | + // Lib |
| 38 | + const lib = b.addSharedLibrary(.{ |
| 39 | + .name = "tokenizer", |
| 40 | + .root_source_file = b.path("src/tokenizer.zig"), |
| 41 | + .target = target, |
| 42 | + .optimize = optimize, |
| 43 | + }); |
| 44 | + lib.linkLibrary(pcre2_dep.artifact("pcre2-8")); |
| 45 | + const lib_install = b.addInstallArtifact(lib, .{}); |
| 46 | + const lib_step = b.step("lib", "Install library only"); |
| 47 | + lib_step.dependOn(&lib_install.step); |
| 48 | + b.getInstallStep().dependOn(&lib_install.step); |
| 49 | +} |
0 commit comments