authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-03-03 16:17:23-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-03-04 05:39:14-05:00
log653814f76ba5d678ebad91f140417cd5829c6aad
treeb7095c22881f5100405c118a96006ca3aef3a73b
parent18e6d1e81929964e9f1d9780e3d8e8f8ae4fcff0

std.Build.addModule: return the created module


1 files changed, 10 insertions(+), 13 deletions(-)

lib/std/Build.zig+10-13
...@@ -550,17 +550,13 @@ pub fn addAssembly(b: *Build, options: AssemblyOptions) *CompileStep {...@@ -550,17 +550,13 @@ pub fn addAssembly(b: *Build, options: AssemblyOptions) *CompileStep {
550 return obj_step;550 return obj_step;
551}551}
552552
553pub const AddModuleOptions = struct {553/// This function creates a module and adds it to the package's module set, making
554 name: []const u8,554/// it available to other packages which depend on this one.
555 source_file: FileSource,555/// `createModule` can be used instead to create a private module.
556 dependencies: []const ModuleDependency = &.{},556pub fn addModule(b: *Build, name: []const u8, options: CreateModuleOptions) *Module {
557};557 const module = b.createModule(options);
558558 b.modules.put(b.dupe(name), module) catch @panic("OOM");
559pub fn addModule(b: *Build, options: AddModuleOptions) void {559 return module;
560 b.modules.put(b.dupe(options.name), b.createModule(.{
561 .source_file = options.source_file,
562 .dependencies = options.dependencies,
563 })) catch @panic("OOM");
564}560}
565561
566pub const ModuleDependency = struct {562pub const ModuleDependency = struct {
...@@ -573,8 +569,9 @@ pub const CreateModuleOptions = struct {...@@ -573,8 +569,9 @@ pub const CreateModuleOptions = struct {
573 dependencies: []const ModuleDependency = &.{},569 dependencies: []const ModuleDependency = &.{},
574};570};
575571
576/// Prefer to use `addModule` which will make the module available to other572/// This function creates a private module, to be used by the current package,
577/// packages which depend on this package.573/// but not exposed to other packages depending on this one.
574/// `addModule` can be used instead to create a public module.
578pub fn createModule(b: *Build, options: CreateModuleOptions) *Module {575pub fn createModule(b: *Build, options: CreateModuleOptions) *Module {
579 const module = b.allocator.create(Module) catch @panic("OOM");576 const module = b.allocator.create(Module) catch @panic("OOM");
580 module.* = .{577 module.* = .{