authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-06-19 00:21:22+05:00
committergravatar for bratishkaerik@landless-city.netEric Joldasov <bratishkaerik@landless-city.net> 2024-12-18 01:47:51+05:00
log3aa802090436a1882fc2093cf0ff8e906340bfcb
treeef3de677dec0c30bad5f094d8701aba80b86a6ea
parentfaafeb51afb9edf5a1f11cb3ab1f9091f07344c7
signaturelock-open Commit is signed but in an unrecognized format.

std.Build.Step.Compile.Options: change `root_module` field type to `*Module`


4 files changed, 68 insertions(+), 57 deletions(-)

lib/std/Build.zig+12-12
......@@ -719,7 +719,7 @@ pub const ExecutableOptions = struct {
719719pub fn addExecutable(b: *Build, options: ExecutableOptions) *Step.Compile {
720720 return Step.Compile.create(b, .{
721721 .name = options.name,
722 .root_module = .{
722 .root_module = b.createModule(.{
723723 .root_source_file = options.root_source_file,
724724 .target = options.target,
725725 .optimize = options.optimize,
......@@ -732,7 +732,7 @@ pub fn addExecutable(b: *Build, options: ExecutableOptions) *Step.Compile {
732732 .sanitize_thread = options.sanitize_thread,
733733 .error_tracing = options.error_tracing,
734734 .code_model = options.code_model,
735 },
735 }),
736736 .version = options.version,
737737 .kind = .exe,
738738 .linkage = options.linkage,
......@@ -769,7 +769,7 @@ pub const ObjectOptions = struct {
769769pub fn addObject(b: *Build, options: ObjectOptions) *Step.Compile {
770770 return Step.Compile.create(b, .{
771771 .name = options.name,
772 .root_module = .{
772 .root_module = b.createModule(.{
773773 .root_source_file = options.root_source_file,
774774 .target = options.target,
775775 .optimize = options.optimize,
......@@ -782,7 +782,7 @@ pub fn addObject(b: *Build, options: ObjectOptions) *Step.Compile {
782782 .sanitize_thread = options.sanitize_thread,
783783 .error_tracing = options.error_tracing,
784784 .code_model = options.code_model,
785 },
785 }),
786786 .kind = .obj,
787787 .max_rss = options.max_rss,
788788 .use_llvm = options.use_llvm,
......@@ -823,7 +823,7 @@ pub const SharedLibraryOptions = struct {
823823pub fn addSharedLibrary(b: *Build, options: SharedLibraryOptions) *Step.Compile {
824824 return Step.Compile.create(b, .{
825825 .name = options.name,
826 .root_module = .{
826 .root_module = b.createModule(.{
827827 .target = options.target,
828828 .optimize = options.optimize,
829829 .root_source_file = options.root_source_file,
......@@ -836,7 +836,7 @@ pub fn addSharedLibrary(b: *Build, options: SharedLibraryOptions) *Step.Compile
836836 .sanitize_thread = options.sanitize_thread,
837837 .error_tracing = options.error_tracing,
838838 .code_model = options.code_model,
839 },
839 }),
840840 .kind = .lib,
841841 .linkage = .dynamic,
842842 .version = options.version,
......@@ -874,7 +874,7 @@ pub const StaticLibraryOptions = struct {
874874pub fn addStaticLibrary(b: *Build, options: StaticLibraryOptions) *Step.Compile {
875875 return Step.Compile.create(b, .{
876876 .name = options.name,
877 .root_module = .{
877 .root_module = b.createModule(.{
878878 .target = options.target,
879879 .optimize = options.optimize,
880880 .root_source_file = options.root_source_file,
......@@ -887,7 +887,7 @@ pub fn addStaticLibrary(b: *Build, options: StaticLibraryOptions) *Step.Compile
887887 .sanitize_thread = options.sanitize_thread,
888888 .error_tracing = options.error_tracing,
889889 .code_model = options.code_model,
890 },
890 }),
891891 .kind = .lib,
892892 .linkage = .static,
893893 .version = options.version,
......@@ -935,7 +935,7 @@ pub fn addTest(b: *Build, options: TestOptions) *Step.Compile {
935935 return Step.Compile.create(b, .{
936936 .name = options.name,
937937 .kind = .@"test",
938 .root_module = .{
938 .root_module = b.createModule(.{
939939 .root_source_file = options.root_source_file,
940940 .target = options.target orelse b.graph.host,
941941 .optimize = options.optimize,
......@@ -948,7 +948,7 @@ pub fn addTest(b: *Build, options: TestOptions) *Step.Compile {
948948 .omit_frame_pointer = options.omit_frame_pointer,
949949 .sanitize_thread = options.sanitize_thread,
950950 .error_tracing = options.error_tracing,
951 },
951 }),
952952 .max_rss = options.max_rss,
953953 .filters = if (options.filter != null and options.filters.len > 0) filters: {
954954 const filters = b.allocator.alloc([]const u8, 1 + options.filters.len) catch @panic("OOM");
......@@ -978,10 +978,10 @@ pub fn addAssembly(b: *Build, options: AssemblyOptions) *Step.Compile {
978978 const obj_step = Step.Compile.create(b, .{
979979 .name = options.name,
980980 .kind = .obj,
981 .root_module = .{
981 .root_module = b.createModule(.{
982982 .target = options.target,
983983 .optimize = options.optimize,
984 },
984 }),
985985 .max_rss = options.max_rss,
986986 .zig_lib_dir = options.zig_lib_dir,
987987 });
lib/std/Build/Module.zig+49-37
......@@ -242,45 +242,57 @@ pub const Import = struct {
242242 module: *Module,
243243};
244244
245pub fn init(m: *Module, owner: *std.Build, options: CreateOptions, compile: ?*Step.Compile) void {
245pub fn init(
246 m: *Module,
247 owner: *std.Build,
248 value: union(enum) { options: CreateOptions, existing: *const Module },
249 compile: ?*Step.Compile,
250) void {
246251 const allocator = owner.allocator;
247252
248 m.* = .{
249 .owner = owner,
250 .depending_steps = .{},
251 .root_source_file = if (options.root_source_file) |lp| lp.dupe(owner) else null,
252 .import_table = .{},
253 .resolved_target = options.target,
254 .optimize = options.optimize,
255 .link_libc = options.link_libc,
256 .link_libcpp = options.link_libcpp,
257 .dwarf_format = options.dwarf_format,
258 .c_macros = .{},
259 .include_dirs = .{},
260 .lib_paths = .{},
261 .rpaths = .{},
262 .frameworks = .{},
263 .link_objects = .{},
264 .strip = options.strip,
265 .unwind_tables = options.unwind_tables,
266 .single_threaded = options.single_threaded,
267 .stack_protector = options.stack_protector,
268 .stack_check = options.stack_check,
269 .sanitize_c = options.sanitize_c,
270 .sanitize_thread = options.sanitize_thread,
271 .fuzz = options.fuzz,
272 .code_model = options.code_model,
273 .valgrind = options.valgrind,
274 .pic = options.pic,
275 .red_zone = options.red_zone,
276 .omit_frame_pointer = options.omit_frame_pointer,
277 .error_tracing = options.error_tracing,
278 .export_symbol_names = &.{},
279 };
253 switch (value) {
254 .options => |options| {
255 m.* = .{
256 .owner = owner,
257 .depending_steps = .{},
258 .root_source_file = if (options.root_source_file) |lp| lp.dupe(owner) else null,
259 .import_table = .{},
260 .resolved_target = options.target,
261 .optimize = options.optimize,
262 .link_libc = options.link_libc,
263 .link_libcpp = options.link_libcpp,
264 .dwarf_format = options.dwarf_format,
265 .c_macros = .{},
266 .include_dirs = .{},
267 .lib_paths = .{},
268 .rpaths = .{},
269 .frameworks = .{},
270 .link_objects = .{},
271 .strip = options.strip,
272 .unwind_tables = options.unwind_tables,
273 .single_threaded = options.single_threaded,
274 .stack_protector = options.stack_protector,
275 .stack_check = options.stack_check,
276 .sanitize_c = options.sanitize_c,
277 .sanitize_thread = options.sanitize_thread,
278 .fuzz = options.fuzz,
279 .code_model = options.code_model,
280 .valgrind = options.valgrind,
281 .pic = options.pic,
282 .red_zone = options.red_zone,
283 .omit_frame_pointer = options.omit_frame_pointer,
284 .error_tracing = options.error_tracing,
285 .export_symbol_names = &.{},
286 };
280287
281 m.import_table.ensureUnusedCapacity(allocator, options.imports.len) catch @panic("OOM");
282 for (options.imports) |dep| {
283 m.import_table.putAssumeCapacity(dep.name, dep.module);
288 m.import_table.ensureUnusedCapacity(allocator, options.imports.len) catch @panic("OOM");
289 for (options.imports) |dep| {
290 m.import_table.putAssumeCapacity(dep.name, dep.module);
291 }
292 },
293 .existing => |existing| {
294 m.* = existing.*;
295 },
284296 }
285297
286298 if (compile) |c| {
......@@ -294,7 +306,7 @@ pub fn init(m: *Module, owner: *std.Build, options: CreateOptions, compile: ?*St
294306
295307pub fn create(owner: *std.Build, options: CreateOptions) *Module {
296308 const m = owner.allocator.create(Module) catch @panic("OOM");
297 m.init(owner, options, null);
309 m.init(owner, .{ .options = options }, null);
298310 return m;
299311}
300312
lib/std/Build/Step/Compile.zig+5-6
......@@ -262,7 +262,7 @@ pub const Entry = union(enum) {
262262
263263pub const Options = struct {
264264 name: []const u8,
265 root_module: Module.CreateOptions,
265 root_module: *Module,
266266 kind: Kind,
267267 linkage: ?std.builtin.LinkMode = null,
268268 version: ?std.SemanticVersion = null,
......@@ -359,7 +359,8 @@ pub fn create(owner: *std.Build, options: Options) *Compile {
359359 else
360360 owner.fmt("{s} ", .{name});
361361
362 const resolved_target = options.root_module.target.?;
362 const resolved_target = options.root_module.resolved_target orelse
363 @panic("the root Module of a Compile step must be created with a known 'target' field");
363364 const target = resolved_target.result;
364365
365366 const step_name = owner.fmt("{s} {s}{s} {s}", .{
......@@ -431,10 +432,8 @@ pub fn create(owner: *std.Build, options: Options) *Compile {
431432
432433 .zig_process = null,
433434 };
434
435 const root_module = owner.allocator.create(Module) catch @panic("OOM");
436 root_module.init(owner, options.root_module, compile);
437 compile.root_module = root_module;
435 options.root_module.init(owner, .{ .existing = options.root_module }, compile);
436 compile.root_module = options.root_module;
438437
439438 if (options.zig_lib_dir) |lp| {
440439 compile.zig_lib_dir = lp.dupe(compile.step.owner);
test/link/link.zig+2-2
......@@ -70,7 +70,7 @@ fn addCompileStep(
7070) *Compile {
7171 const compile_step = Compile.create(b, .{
7272 .name = overlay.name,
73 .root_module = .{
73 .root_module = b.createModule(.{
7474 .target = base.target,
7575 .optimize = base.optimize,
7676 .root_source_file = rsf: {
......@@ -80,7 +80,7 @@ fn addCompileStep(
8080 },
8181 .pic = overlay.pic,
8282 .strip = if (base.strip) |s| s else overlay.strip,
83 },
83 }),
8484 .use_llvm = base.use_llvm,
8585 .use_lld = base.use_lld,
8686 .kind = switch (kind) {