diff options
| author | 2024-02-15 12:25:33 -0400 | |
|---|---|---|
| committer | 2024-02-15 12:25:33 -0400 | |
| commit | 2436eeb57143108decfd37fe531cf87ca8d56cf8 (patch) | |
| tree | 76eb67fd0ab4c1af3e7d2ab20949f5f9be2901ff | |
| parent | Removed inline from fns (diff) | |
| download | zg-2436eeb57143108decfd37fe531cf87ca8d56cf8.tar.gz zg-2436eeb57143108decfd37fe531cf87ca8d56cf8.tar.xz zg-2436eeb57143108decfd37fe531cf87ca8d56cf8.zip | |
build.zig module reorg
| -rw-r--r-- | build.zig | 23 | ||||
| -rw-r--r-- | src/Grapheme.zig | 3 | ||||
| -rw-r--r-- | src/main.zig | 7 |
3 files changed, 23 insertions, 10 deletions
| @@ -4,8 +4,10 @@ pub fn build(b: *std.Build) void { | |||
| 4 | const target = b.standardTargetOptions(.{}); | 4 | const target = b.standardTargetOptions(.{}); |
| 5 | const optimize = b.standardOptimizeOption(.{}); | 5 | const optimize = b.standardOptimizeOption(.{}); |
| 6 | 6 | ||
| 7 | // Dependencies | ||
| 7 | const ziglyph = b.dependency("ziglyph", .{}); | 8 | const ziglyph = b.dependency("ziglyph", .{}); |
| 8 | 9 | ||
| 10 | // Code generation | ||
| 9 | const gbp_gen_exe = b.addExecutable(.{ | 11 | const gbp_gen_exe = b.addExecutable(.{ |
| 10 | .name = "gbp", | 12 | .name = "gbp", |
| 11 | .root_source_file = .{ .path = "codegen/gbp.zig" }, | 13 | .root_source_file = .{ .path = "codegen/gbp.zig" }, |
| @@ -15,6 +17,22 @@ pub fn build(b: *std.Build) void { | |||
| 15 | const run_gbp_gen_exe = b.addRunArtifact(gbp_gen_exe); | 17 | const run_gbp_gen_exe = b.addRunArtifact(gbp_gen_exe); |
| 16 | const gbp_gen_out = run_gbp_gen_exe.addOutputFileArg("gbp.zig"); | 18 | const gbp_gen_out = run_gbp_gen_exe.addOutputFileArg("gbp.zig"); |
| 17 | 19 | ||
| 20 | // Modules we provide | ||
| 21 | const code_point = b.addModule("CodePoint", .{ | ||
| 22 | .root_source_file = .{ .path = "src/CodePoint.zig" }, | ||
| 23 | .target = target, | ||
| 24 | .optimize = optimize, | ||
| 25 | }); | ||
| 26 | |||
| 27 | const grapheme = b.addModule("Grapheme", .{ | ||
| 28 | .root_source_file = .{ .path = "src/Grapheme.zig" }, | ||
| 29 | .target = target, | ||
| 30 | .optimize = optimize, | ||
| 31 | }); | ||
| 32 | grapheme.addImport("CodePoint", code_point); | ||
| 33 | grapheme.addAnonymousImport("gbp", .{ .root_source_file = gbp_gen_out }); | ||
| 34 | |||
| 35 | // Benchmark rig | ||
| 18 | const exe = b.addExecutable(.{ | 36 | const exe = b.addExecutable(.{ |
| 19 | .name = "zgbench", | 37 | .name = "zgbench", |
| 20 | .root_source_file = .{ .path = "src/main.zig" }, | 38 | .root_source_file = .{ .path = "src/main.zig" }, |
| @@ -22,7 +40,7 @@ pub fn build(b: *std.Build) void { | |||
| 22 | .optimize = optimize, | 40 | .optimize = optimize, |
| 23 | }); | 41 | }); |
| 24 | exe.root_module.addImport("ziglyph", ziglyph.module("ziglyph")); | 42 | exe.root_module.addImport("ziglyph", ziglyph.module("ziglyph")); |
| 25 | exe.root_module.addAnonymousImport("gbp", .{ .root_source_file = gbp_gen_out }); | 43 | exe.root_module.addImport("Grapheme", grapheme); |
| 26 | b.installArtifact(exe); | 44 | b.installArtifact(exe); |
| 27 | 45 | ||
| 28 | const run_cmd = b.addRunArtifact(exe); | 46 | const run_cmd = b.addRunArtifact(exe); |
| @@ -32,13 +50,14 @@ pub fn build(b: *std.Build) void { | |||
| 32 | const run_step = b.step("run", "Run the app"); | 50 | const run_step = b.step("run", "Run the app"); |
| 33 | run_step.dependOn(&run_cmd.step); | 51 | run_step.dependOn(&run_cmd.step); |
| 34 | 52 | ||
| 53 | // Tests | ||
| 35 | const exe_unit_tests = b.addTest(.{ | 54 | const exe_unit_tests = b.addTest(.{ |
| 36 | .root_source_file = .{ .path = "src/main.zig" }, | 55 | .root_source_file = .{ .path = "src/main.zig" }, |
| 37 | .target = target, | 56 | .target = target, |
| 38 | .optimize = optimize, | 57 | .optimize = optimize, |
| 39 | }); | 58 | }); |
| 40 | exe_unit_tests.root_module.addImport("ziglyph", ziglyph.module("ziglyph")); | 59 | exe_unit_tests.root_module.addImport("ziglyph", ziglyph.module("ziglyph")); |
| 41 | exe_unit_tests.root_module.addAnonymousImport("gbp", .{ .root_source_file = gbp_gen_out }); | 60 | exe_unit_tests.root_module.addImport("Grapheme", grapheme); |
| 42 | 61 | ||
| 43 | const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests); | 62 | const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests); |
| 44 | 63 | ||
diff --git a/src/Grapheme.zig b/src/Grapheme.zig index 41f3e16..888fcd4 100644 --- a/src/Grapheme.zig +++ b/src/Grapheme.zig | |||
| @@ -3,8 +3,7 @@ | |||
| 3 | const std = @import("std"); | 3 | const std = @import("std"); |
| 4 | const unicode = std.unicode; | 4 | const unicode = std.unicode; |
| 5 | 5 | ||
| 6 | const ziglyph = @import("ziglyph"); | 6 | const CodePoint = @import("CodePoint"); |
| 7 | const CodePoint = @import("CodePoint.zig"); | ||
| 8 | const CodePointIterator = CodePoint.CodePointIterator; | 7 | const CodePointIterator = CodePoint.CodePointIterator; |
| 9 | const gbp = @import("gbp"); | 8 | const gbp = @import("gbp"); |
| 10 | 9 | ||
diff --git a/src/main.zig b/src/main.zig index a78c1dc..fe49300 100644 --- a/src/main.zig +++ b/src/main.zig | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | 2 | ||
| 3 | // const GraphemeIterator = @import("ziglyph").GraphemeIterator; | 3 | // const GraphemeIterator = @import("ziglyph").GraphemeIterator; |
| 4 | const GraphemeIterator = @import("Grapheme.zig").GraphemeIterator; | 4 | const GraphemeIterator = @import("Grapheme").GraphemeIterator; |
| 5 | 5 | ||
| 6 | pub fn main() !void { | 6 | pub fn main() !void { |
| 7 | var gpa = std.heap.GeneralPurposeAllocator(.{}){}; | 7 | var gpa = std.heap.GeneralPurposeAllocator(.{}){}; |
| @@ -23,8 +23,3 @@ pub fn main() !void { | |||
| 23 | 23 | ||
| 24 | std.debug.print("result: {}, took: {}\n", .{ result, timer.lap() / std.time.ns_per_ms }); | 24 | std.debug.print("result: {}, took: {}\n", .{ result, timer.lap() / std.time.ns_per_ms }); |
| 25 | } | 25 | } |
| 26 | |||
| 27 | test { | ||
| 28 | _ = @import("CodePoint.zig"); | ||
| 29 | _ = @import("Grapheme.zig"); | ||
| 30 | } | ||