Skip to content

Commit

Permalink
std.Build: Add methods for creating modules from a TranslateC object.
Browse files Browse the repository at this point in the history
  • Loading branch information
mibu138 authored and andrewrk committed Jul 11, 2023
1 parent 7a8002a commit 6bc9c4f
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/std/Build/Step/TranslateC.zig
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,30 @@ pub fn addExecutable(self: *TranslateC, options: AddExecutableOptions) *Step.Com
});
}

/// Creates a module from the translated source and adds it to the package's
/// module set making it available to other packages which depend on this one.
/// `createModule` can be used instead to create a private module.
pub fn addModule(self: *TranslateC, name: []const u8) *std.Build.Module {
return self.step.owner.addModule(name, .{
.source_file = .{ .generated = &self.output_file },
});
}

/// Creates a private module from the translated source to be used by the
/// current package, but not exposed to other packages depending on this one.
/// `addModule` can be used instead to create a public module.
pub fn createModule(self: *TranslateC) *std.Build.Module {
const b = self.step.owner;
const module = b.allocator.create(std.Build.Module) catch @panic("OOM");

module.* = .{
.builder = b,
.source_file = .{ .generated = &self.output_file },
.dependencies = std.StringArrayHashMap(*std.Build.Module).init(b.allocator),
};
return module;
}

pub fn addIncludeDir(self: *TranslateC, include_dir: []const u8) void {
self.include_dirs.append(self.step.owner.dupePath(include_dir)) catch @panic("OOM");
}
Expand Down

0 comments on commit 6bc9c4f

Please sign in to comment.