From c9a1b3392973ee30e6a9a532f1da8605619b5b06 Mon Sep 17 00:00:00 2001 From: Sam Atman Date: Fri, 23 May 2025 18:46:30 -0400 Subject: Make offset size configurable Hopefully I can talk users out of taking advantage of this configuration but I'll have better luck with that if it's available. --- build.zig | 54 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 22 deletions(-) (limited to 'build.zig') diff --git a/build.zig b/build.zig index 8cfa039..648571b 100644 --- a/build.zig +++ b/build.zig @@ -11,7 +11,34 @@ pub fn build(b: *std.Build) void { .optimize = optimize, }); - // Code generation + //| Options + + // Display width + const cjk = b.option(bool, "cjk", "Ambiguous code points are wide (display width: 2).") orelse false; + const dwp_options = b.addOptions(); + dwp_options.addOption(bool, "cjk", cjk); + + // Visible Controls + const c0_width = b.option( + i4, + "c0_width", + "C0 controls have this width (default: 0, default -1)", + ); + dwp_options.addOption(?i4, "c0_width", c0_width); + const c1_width = b.option( + i4, + "c1_width", + "C1 controls have this width (default: 0)", + ); + dwp_options.addOption(?i4, "c1_width", c1_width); + + //| Offset size + const fat_offset = b.option(bool, "fat_offset", "Offsets in Iterators and data structures will be u64") orelse false; + const size_config = b.addOptions(); + size_config.addOption(bool, "fat_offset", fat_offset); + + //| Code generation + // Grapheme break const gbp_gen_exe = b.addExecutable(.{ .name = "gbp", @@ -31,32 +58,13 @@ pub fn build(b: *std.Build) void { const run_wbp_gen_exe = b.addRunArtifact(wbp_gen_exe); const wbp_gen_out = run_wbp_gen_exe.addOutputFileArg("wbp.bin.z"); - // Display width - const cjk = b.option(bool, "cjk", "Ambiguous code points are wide (display width: 2).") orelse false; - const options = b.addOptions(); - options.addOption(bool, "cjk", cjk); - - // Visible Controls - const c0_width = b.option( - i4, - "c0_width", - "C0 controls have this width (default: 0, default -1)", - ); - options.addOption(?i4, "c0_width", c0_width); - const c1_width = b.option( - i4, - "c1_width", - "C1 controls have this width (default: 0)", - ); - options.addOption(?i4, "c1_width", c1_width); - const dwp_gen_exe = b.addExecutable(.{ .name = "dwp", .root_source_file = b.path("codegen/dwp.zig"), .target = b.graph.host, .optimize = .Debug, }); - dwp_gen_exe.root_module.addOptions("options", options); + dwp_gen_exe.root_module.addOptions("options", dwp_options); const run_dwp_gen_exe = b.addRunArtifact(dwp_gen_exe); const dwp_gen_out = run_dwp_gen_exe.addOutputFileArg("dwp.bin.z"); @@ -199,6 +207,7 @@ pub fn build(b: *std.Build) void { .target = target, .optimize = optimize, }); + code_point.addOptions("config", size_config); const code_point_t = b.addTest(.{ .name = "code_point", @@ -216,6 +225,7 @@ pub fn build(b: *std.Build) void { }); graphemes.addAnonymousImport("gbp", .{ .root_source_file = gbp_gen_out }); graphemes.addImport("code_point", code_point); + graphemes.addOptions("config", size_config); const grapheme_t = b.addTest(.{ .name = "Graphemes", @@ -267,7 +277,7 @@ pub fn build(b: *std.Build) void { display_width.addImport("ascii", ascii); display_width.addImport("code_point", code_point); display_width.addImport("Graphemes", graphemes); - display_width.addOptions("options", options); // For testing + display_width.addOptions("options", dwp_options); // For testing const display_width_t = b.addTest(.{ .name = "display_width", -- cgit v1.2.3