aboutsummaryrefslogtreecommitdiff
path: root/lib/std/Build/Module.zig
diff options
context:
space:
mode:
Diffstat (limited to 'lib/std/Build/Module.zig')
-rw-r--r--lib/std/Build/Module.zig86
1 files changed, 49 insertions, 37 deletions
diff --git a/lib/std/Build/Module.zig b/lib/std/Build/Module.zig
index cc7c5a65c0..629d90dd0f 100644
--- a/lib/std/Build/Module.zig
+++ b/lib/std/Build/Module.zig
@@ -242,45 +242,57 @@ pub const Import = struct {
module: *Module,
};
-pub fn init(m: *Module, owner: *std.Build, options: CreateOptions, compile: ?*Step.Compile) void {
+pub fn init(
+ m: *Module,
+ owner: *std.Build,
+ value: union(enum) { options: CreateOptions, existing: *const Module },
+ compile: ?*Step.Compile,
+) void {
const allocator = owner.allocator;
- m.* = .{
- .owner = owner,
- .depending_steps = .{},
- .root_source_file = if (options.root_source_file) |lp| lp.dupe(owner) else null,
- .import_table = .{},
- .resolved_target = options.target,
- .optimize = options.optimize,
- .link_libc = options.link_libc,
- .link_libcpp = options.link_libcpp,
- .dwarf_format = options.dwarf_format,
- .c_macros = .{},
- .include_dirs = .{},
- .lib_paths = .{},
- .rpaths = .{},
- .frameworks = .{},
- .link_objects = .{},
- .strip = options.strip,
- .unwind_tables = options.unwind_tables,
- .single_threaded = options.single_threaded,
- .stack_protector = options.stack_protector,
- .stack_check = options.stack_check,
- .sanitize_c = options.sanitize_c,
- .sanitize_thread = options.sanitize_thread,
- .fuzz = options.fuzz,
- .code_model = options.code_model,
- .valgrind = options.valgrind,
- .pic = options.pic,
- .red_zone = options.red_zone,
- .omit_frame_pointer = options.omit_frame_pointer,
- .error_tracing = options.error_tracing,
- .export_symbol_names = &.{},
- };
+ switch (value) {
+ .options => |options| {
+ m.* = .{
+ .owner = owner,
+ .depending_steps = .{},
+ .root_source_file = if (options.root_source_file) |lp| lp.dupe(owner) else null,
+ .import_table = .{},
+ .resolved_target = options.target,
+ .optimize = options.optimize,
+ .link_libc = options.link_libc,
+ .link_libcpp = options.link_libcpp,
+ .dwarf_format = options.dwarf_format,
+ .c_macros = .{},
+ .include_dirs = .{},
+ .lib_paths = .{},
+ .rpaths = .{},
+ .frameworks = .{},
+ .link_objects = .{},
+ .strip = options.strip,
+ .unwind_tables = options.unwind_tables,
+ .single_threaded = options.single_threaded,
+ .stack_protector = options.stack_protector,
+ .stack_check = options.stack_check,
+ .sanitize_c = options.sanitize_c,
+ .sanitize_thread = options.sanitize_thread,
+ .fuzz = options.fuzz,
+ .code_model = options.code_model,
+ .valgrind = options.valgrind,
+ .pic = options.pic,
+ .red_zone = options.red_zone,
+ .omit_frame_pointer = options.omit_frame_pointer,
+ .error_tracing = options.error_tracing,
+ .export_symbol_names = &.{},
+ };
- m.import_table.ensureUnusedCapacity(allocator, options.imports.len) catch @panic("OOM");
- for (options.imports) |dep| {
- m.import_table.putAssumeCapacity(dep.name, dep.module);
+ m.import_table.ensureUnusedCapacity(allocator, options.imports.len) catch @panic("OOM");
+ for (options.imports) |dep| {
+ m.import_table.putAssumeCapacity(dep.name, dep.module);
+ }
+ },
+ .existing => |existing| {
+ m.* = existing.*;
+ },
}
if (compile) |c| {
@@ -294,7 +306,7 @@ pub fn init(m: *Module, owner: *std.Build, options: CreateOptions, compile: ?*St
pub fn create(owner: *std.Build, options: CreateOptions) *Module {
const m = owner.allocator.create(Module) catch @panic("OOM");
- m.init(owner, options, null);
+ m.init(owner, .{ .options = options }, null);
return m;
}