const std = @import("std"); pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); // Dependencies const ziglyph = b.dependency("ziglyph", .{}); // Code generation // Grapheme break const gbp_gen_exe = b.addExecutable(.{ .name = "gbp", .root_source_file = .{ .path = "codegen/gbp.zig" }, .target = b.host, .optimize = .Debug, }); const run_gbp_gen_exe = b.addRunArtifact(gbp_gen_exe); const gbp_gen_out = run_gbp_gen_exe.addOutputFileArg("gbp.bin.z"); // Display width const cjk = b.option(bool, "cjk", "Ambiguouse code points are wide (display width: 2).") orelse false; const options = b.addOptions(); options.addOption(bool, "cjk", cjk); const dwp_gen_exe = b.addExecutable(.{ .name = "dwp", .root_source_file = .{ .path = "codegen/dwp.zig" }, .target = b.host, .optimize = .Debug, }); dwp_gen_exe.root_module.addOptions("options", options); const run_dwp_gen_exe = b.addRunArtifact(dwp_gen_exe); const dwp_gen_out = run_dwp_gen_exe.addOutputFileArg("dwp.bin.z"); // Normalization properties const canon_gen_exe = b.addExecutable(.{ .name = "canon", .root_source_file = .{ .path = "codegen/canon.zig" }, .target = b.host, .optimize = .Debug, }); const run_canon_gen_exe = b.addRunArtifact(canon_gen_exe); const canon_gen_out = run_canon_gen_exe.addOutputFileArg("canon.bin.z"); const ccc_gen_exe = b.addExecutable(.{ .name = "ccc", .root_source_file = .{ .path = "codegen/ccc.zig" }, .target = b.host, .optimize = .Debug, }); const run_ccc_gen_exe = b.addRunArtifact(ccc_gen_exe); const ccc_gen_out = run_ccc_gen_exe.addOutputFileArg("ccc.bin.z"); // Modules we provide // Code points const code_point = b.addModule("code_point", .{ .root_source_file = .{ .path = "src/code_point.zig" }, .target = target, .optimize = optimize, }); // Grapheme clusters const grapheme_data = b.createModule(.{ .root_source_file = .{ .path = "src/GraphemeData.zig" }, .target = target, .optimize = optimize, }); grapheme_data.addAnonymousImport("gbp", .{ .root_source_file = gbp_gen_out }); const grapheme = b.addModule("grapheme", .{ .root_source_file = .{ .path = "src/grapheme.zig" }, .target = target, .optimize = optimize, }); grapheme.addImport("code_point", code_point); grapheme.addImport("GraphemeData", grapheme_data); // ASCII utilities const ascii = b.addModule("ascii", .{ .root_source_file = .{ .path = "src/ascii.zig" }, .target = target, .optimize = optimize, }); // Fixed pitch font display width const dw_data = b.createModule(.{ .root_source_file = .{ .path = "src/DisplayWidthData.zig" }, .target = target, .optimize = optimize, }); dw_data.addAnonymousImport("dwp", .{ .root_source_file = dwp_gen_out }); dw_data.addImport("GraphemeData", grapheme_data); const display_width = b.addModule("DisplayWidth", .{ .root_source_file = .{ .path = "src/DisplayWidth.zig" }, .target = target, .optimize = optimize, }); display_width.addImport("ascii", ascii); display_width.addImport("code_point", code_point); display_width.addImport("grapheme", grapheme); display_width.addImport("DisplayWidthData", dw_data); // Normalization const ccc_data = b.createModule(.{ .root_source_file = .{ .path = "src/CombiningClassData.zig" }, .target = target, .optimize = optimize, }); ccc_data.addAnonymousImport("ccc", .{ .root_source_file = ccc_gen_out }); const canon_data = b.createModule(.{ .root_source_file = .{ .path = "src/Canonical.zig" }, .target = target, .optimize = optimize, }); canon_data.addAnonymousImport("canon", .{ .root_source_file = canon_gen_out }); const norm_data = b.createModule(.{ .root_source_file = .{ .path = "src/NormData.zig" }, .target = target, .optimize = optimize, }); norm_data.addImport("CanonicalData", canon_data); norm_data.addImport("CombiningClassData", ccc_data); const norm = b.addModule("Normalizer", .{ .root_source_file = .{ .path = "src/Normalizer.zig" }, .target = target, .optimize = optimize, }); norm.addImport("code_point", code_point); norm.addImport("ziglyph", ziglyph.module("ziglyph")); norm.addImport("NormData", norm_data); // Benchmark rig const exe = b.addExecutable(.{ .name = "zg", .root_source_file = .{ .path = "src/main.zig" }, .target = target, .optimize = optimize, }); // exe.root_module.addImport("ziglyph", ziglyph.module("ziglyph")); // exe.root_module.addImport("ascii", ascii); // exe.root_module.addImport("code_point", code_point); // exe.root_module.addImport("grapheme", grapheme); // exe.root_module.addImport("DisplayWidth", display_width); exe.root_module.addImport("Normalizer", norm); b.installArtifact(exe); const run_cmd = b.addRunArtifact(exe); run_cmd.step.dependOn(b.getInstallStep()); if (b.args) |args| run_cmd.addArgs(args); const run_step = b.step("run", "Run the app"); run_step.dependOn(&run_cmd.step); // Tests const exe_unit_tests = b.addTest(.{ .root_source_file = .{ .path = "src/Normalizer.zig" }, .target = target, .optimize = optimize, }); // exe_unit_tests.root_module.addImport("ascii", ascii); exe_unit_tests.root_module.addImport("code_point", code_point); // exe_unit_tests.root_module.addImport("GraphemeData", grapheme_data); // exe_unit_tests.root_module.addImport("grapheme", grapheme); exe_unit_tests.root_module.addImport("ziglyph", ziglyph.module("ziglyph")); // exe_unit_tests.root_module.addAnonymousImport("normp", .{ .root_source_file = normp_gen_out }); // exe_unit_tests.root_module.addImport("DisplayWidthData", dw_data); exe_unit_tests.root_module.addImport("NormData", norm_data); const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests); const test_step = b.step("test", "Run unit tests"); test_step.dependOn(&run_exe_unit_tests.step); }