all: cache module() returns to avoid duplicate modules

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2023-03-15 21:20:28 -07:00
parent 033ebb8551
commit 6bd4d91932
14 changed files with 75 additions and 17 deletions

View file

@ -8,8 +8,14 @@ pub fn build(b: *std.Build) !void {
test_step.dependOn(&testStep(b, optimize, target).step);
}
pub fn module(b: *std.build.Builder) *std.build.Module {
return b.createModule(.{ .source_file = .{ .path = sdkPath("/src/main.zig") } });
var _module: ?*std.build.Module = null;
pub fn module(b: *std.Build) *std.build.Module {
if (_module) |m| return m;
_module = b.createModule(.{
.source_file = .{ .path = sdkPath("/src/main.zig") },
});
return _module.?;
}
pub fn testStep(b: *std.Build, optimize: std.builtin.OptimizeMode, target: std.zig.CrossTarget) *std.build.RunStep {