authorgravatar for mokchira@gmail.comMichael Buckley <mokchira@gmail.com> 2023-07-08 21:38:27-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-07-11 01:38:04-07:00
log6bc9c4f716afbb15465f79f84f61221f394fa5b6
treeb4a0bf63d5fad0e2d1b8ddac52e22a6dc8b02ef2
parent7a8002a5cf8e6607c1a2bfbd12fec3e60390fc71

std.Build: Add methods for creating modules from a TranslateC object.


1 files changed, 24 insertions(+), 0 deletions(-)

lib/std/Build/Step/TranslateC.zig+24
......@@ -65,6 +65,30 @@ pub fn addExecutable(self: *TranslateC, options: AddExecutableOptions) *Step.Com
6565 });
6666}
6767
68/// Creates a module from the translated source and adds it to the package's
69/// module set making it available to other packages which depend on this one.
70/// `createModule` can be used instead to create a private module.
71pub fn addModule(self: *TranslateC, name: []const u8) *std.Build.Module {
72 return self.step.owner.addModule(name, .{
73 .source_file = .{ .generated = &self.output_file },
74 });
75}
76
77/// Creates a private module from the translated source to be used by the
78/// current package, but not exposed to other packages depending on this one.
79/// `addModule` can be used instead to create a public module.
80pub fn createModule(self: *TranslateC) *std.Build.Module {
81 const b = self.step.owner;
82 const module = b.allocator.create(std.Build.Module) catch @panic("OOM");
83
84 module.* = .{
85 .builder = b,
86 .source_file = .{ .generated = &self.output_file },
87 .dependencies = std.StringArrayHashMap(*std.Build.Module).init(b.allocator),
88 };
89 return module;
90}
91
6892pub fn addIncludeDir(self: *TranslateC, include_dir: []const u8) void {
6993 self.include_dirs.append(self.step.owner.dupePath(include_dir)) catch @panic("OOM");
7094}