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 {...@@ -719,7 +719,7 @@ pub const ExecutableOptions = struct {
719pub fn addExecutable(b: *Build, options: ExecutableOptions) *Step.Compile {719pub fn addExecutable(b: *Build, options: ExecutableOptions) *Step.Compile {
720 return Step.Compile.create(b, .{720 return Step.Compile.create(b, .{
721 .name = options.name,721 .name = options.name,
722 .root_module = .{722 .root_module = b.createModule(.{
723 .root_source_file = options.root_source_file,723 .root_source_file = options.root_source_file,
724 .target = options.target,724 .target = options.target,
725 .optimize = options.optimize,725 .optimize = options.optimize,
...@@ -732,7 +732,7 @@ pub fn addExecutable(b: *Build, options: ExecutableOptions) *Step.Compile {...@@ -732,7 +732,7 @@ pub fn addExecutable(b: *Build, options: ExecutableOptions) *Step.Compile {
732 .sanitize_thread = options.sanitize_thread,732 .sanitize_thread = options.sanitize_thread,
733 .error_tracing = options.error_tracing,733 .error_tracing = options.error_tracing,
734 .code_model = options.code_model,734 .code_model = options.code_model,
735 },735 }),
736 .version = options.version,736 .version = options.version,
737 .kind = .exe,737 .kind = .exe,
738 .linkage = options.linkage,738 .linkage = options.linkage,
...@@ -769,7 +769,7 @@ pub const ObjectOptions = struct {...@@ -769,7 +769,7 @@ pub const ObjectOptions = struct {
769pub fn addObject(b: *Build, options: ObjectOptions) *Step.Compile {769pub fn addObject(b: *Build, options: ObjectOptions) *Step.Compile {
770 return Step.Compile.create(b, .{770 return Step.Compile.create(b, .{
771 .name = options.name,771 .name = options.name,
772 .root_module = .{772 .root_module = b.createModule(.{
773 .root_source_file = options.root_source_file,773 .root_source_file = options.root_source_file,
774 .target = options.target,774 .target = options.target,
775 .optimize = options.optimize,775 .optimize = options.optimize,
...@@ -782,7 +782,7 @@ pub fn addObject(b: *Build, options: ObjectOptions) *Step.Compile {...@@ -782,7 +782,7 @@ pub fn addObject(b: *Build, options: ObjectOptions) *Step.Compile {
782 .sanitize_thread = options.sanitize_thread,782 .sanitize_thread = options.sanitize_thread,
783 .error_tracing = options.error_tracing,783 .error_tracing = options.error_tracing,
784 .code_model = options.code_model,784 .code_model = options.code_model,
785 },785 }),
786 .kind = .obj,786 .kind = .obj,
787 .max_rss = options.max_rss,787 .max_rss = options.max_rss,
788 .use_llvm = options.use_llvm,788 .use_llvm = options.use_llvm,
...@@ -823,7 +823,7 @@ pub const SharedLibraryOptions = struct {...@@ -823,7 +823,7 @@ pub const SharedLibraryOptions = struct {
823pub fn addSharedLibrary(b: *Build, options: SharedLibraryOptions) *Step.Compile {823pub fn addSharedLibrary(b: *Build, options: SharedLibraryOptions) *Step.Compile {
824 return Step.Compile.create(b, .{824 return Step.Compile.create(b, .{
825 .name = options.name,825 .name = options.name,
826 .root_module = .{826 .root_module = b.createModule(.{
827 .target = options.target,827 .target = options.target,
828 .optimize = options.optimize,828 .optimize = options.optimize,
829 .root_source_file = options.root_source_file,829 .root_source_file = options.root_source_file,
...@@ -836,7 +836,7 @@ pub fn addSharedLibrary(b: *Build, options: SharedLibraryOptions) *Step.Compile...@@ -836,7 +836,7 @@ pub fn addSharedLibrary(b: *Build, options: SharedLibraryOptions) *Step.Compile
836 .sanitize_thread = options.sanitize_thread,836 .sanitize_thread = options.sanitize_thread,
837 .error_tracing = options.error_tracing,837 .error_tracing = options.error_tracing,
838 .code_model = options.code_model,838 .code_model = options.code_model,
839 },839 }),
840 .kind = .lib,840 .kind = .lib,
841 .linkage = .dynamic,841 .linkage = .dynamic,
842 .version = options.version,842 .version = options.version,
...@@ -874,7 +874,7 @@ pub const StaticLibraryOptions = struct {...@@ -874,7 +874,7 @@ pub const StaticLibraryOptions = struct {
874pub fn addStaticLibrary(b: *Build, options: StaticLibraryOptions) *Step.Compile {874pub fn addStaticLibrary(b: *Build, options: StaticLibraryOptions) *Step.Compile {
875 return Step.Compile.create(b, .{875 return Step.Compile.create(b, .{
876 .name = options.name,876 .name = options.name,
877 .root_module = .{877 .root_module = b.createModule(.{
878 .target = options.target,878 .target = options.target,
879 .optimize = options.optimize,879 .optimize = options.optimize,
880 .root_source_file = options.root_source_file,880 .root_source_file = options.root_source_file,
...@@ -887,7 +887,7 @@ pub fn addStaticLibrary(b: *Build, options: StaticLibraryOptions) *Step.Compile...@@ -887,7 +887,7 @@ pub fn addStaticLibrary(b: *Build, options: StaticLibraryOptions) *Step.Compile
887 .sanitize_thread = options.sanitize_thread,887 .sanitize_thread = options.sanitize_thread,
888 .error_tracing = options.error_tracing,888 .error_tracing = options.error_tracing,
889 .code_model = options.code_model,889 .code_model = options.code_model,
890 },890 }),
891 .kind = .lib,891 .kind = .lib,
892 .linkage = .static,892 .linkage = .static,
893 .version = options.version,893 .version = options.version,
...@@ -935,7 +935,7 @@ pub fn addTest(b: *Build, options: TestOptions) *Step.Compile {...@@ -935,7 +935,7 @@ pub fn addTest(b: *Build, options: TestOptions) *Step.Compile {
935 return Step.Compile.create(b, .{935 return Step.Compile.create(b, .{
936 .name = options.name,936 .name = options.name,
937 .kind = .@"test",937 .kind = .@"test",
938 .root_module = .{938 .root_module = b.createModule(.{
939 .root_source_file = options.root_source_file,939 .root_source_file = options.root_source_file,
940 .target = options.target orelse b.graph.host,940 .target = options.target orelse b.graph.host,
941 .optimize = options.optimize,941 .optimize = options.optimize,
...@@ -948,7 +948,7 @@ pub fn addTest(b: *Build, options: TestOptions) *Step.Compile {...@@ -948,7 +948,7 @@ pub fn addTest(b: *Build, options: TestOptions) *Step.Compile {
948 .omit_frame_pointer = options.omit_frame_pointer,948 .omit_frame_pointer = options.omit_frame_pointer,
949 .sanitize_thread = options.sanitize_thread,949 .sanitize_thread = options.sanitize_thread,
950 .error_tracing = options.error_tracing,950 .error_tracing = options.error_tracing,
951 },951 }),
952 .max_rss = options.max_rss,952 .max_rss = options.max_rss,
953 .filters = if (options.filter != null and options.filters.len > 0) filters: {953 .filters = if (options.filter != null and options.filters.len > 0) filters: {
954 const filters = b.allocator.alloc([]const u8, 1 + options.filters.len) catch @panic("OOM");954 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 {...@@ -978,10 +978,10 @@ pub fn addAssembly(b: *Build, options: AssemblyOptions) *Step.Compile {
978 const obj_step = Step.Compile.create(b, .{978 const obj_step = Step.Compile.create(b, .{
979 .name = options.name,979 .name = options.name,
980 .kind = .obj,980 .kind = .obj,
981 .root_module = .{981 .root_module = b.createModule(.{
982 .target = options.target,982 .target = options.target,
983 .optimize = options.optimize,983 .optimize = options.optimize,
984 },984 }),
985 .max_rss = options.max_rss,985 .max_rss = options.max_rss,
986 .zig_lib_dir = options.zig_lib_dir,986 .zig_lib_dir = options.zig_lib_dir,
987 });987 });
lib/std/Build/Module.zig+49-37
...@@ -242,45 +242,57 @@ pub const Import = struct {...@@ -242,45 +242,57 @@ pub const Import = struct {
242 module: *Module,242 module: *Module,
243};243};
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 {
246 const allocator = owner.allocator;251 const allocator = owner.allocator;
247252
248 m.* = .{253 switch (value) {
249 .owner = owner,254 .options => |options| {
250 .depending_steps = .{},255 m.* = .{
251 .root_source_file = if (options.root_source_file) |lp| lp.dupe(owner) else null,256 .owner = owner,
252 .import_table = .{},257 .depending_steps = .{},
253 .resolved_target = options.target,258 .root_source_file = if (options.root_source_file) |lp| lp.dupe(owner) else null,
254 .optimize = options.optimize,259 .import_table = .{},
255 .link_libc = options.link_libc,260 .resolved_target = options.target,
256 .link_libcpp = options.link_libcpp,261 .optimize = options.optimize,
257 .dwarf_format = options.dwarf_format,262 .link_libc = options.link_libc,
258 .c_macros = .{},263 .link_libcpp = options.link_libcpp,
259 .include_dirs = .{},264 .dwarf_format = options.dwarf_format,
260 .lib_paths = .{},265 .c_macros = .{},
261 .rpaths = .{},266 .include_dirs = .{},
262 .frameworks = .{},267 .lib_paths = .{},
263 .link_objects = .{},268 .rpaths = .{},
264 .strip = options.strip,269 .frameworks = .{},
265 .unwind_tables = options.unwind_tables,270 .link_objects = .{},
266 .single_threaded = options.single_threaded,271 .strip = options.strip,
267 .stack_protector = options.stack_protector,272 .unwind_tables = options.unwind_tables,
268 .stack_check = options.stack_check,273 .single_threaded = options.single_threaded,
269 .sanitize_c = options.sanitize_c,274 .stack_protector = options.stack_protector,
270 .sanitize_thread = options.sanitize_thread,275 .stack_check = options.stack_check,
271 .fuzz = options.fuzz,276 .sanitize_c = options.sanitize_c,
272 .code_model = options.code_model,277 .sanitize_thread = options.sanitize_thread,
273 .valgrind = options.valgrind,278 .fuzz = options.fuzz,
274 .pic = options.pic,279 .code_model = options.code_model,
275 .red_zone = options.red_zone,280 .valgrind = options.valgrind,
276 .omit_frame_pointer = options.omit_frame_pointer,281 .pic = options.pic,
277 .error_tracing = options.error_tracing,282 .red_zone = options.red_zone,
278 .export_symbol_names = &.{},283 .omit_frame_pointer = options.omit_frame_pointer,
279 };284 .error_tracing = options.error_tracing,
285 .export_symbol_names = &.{},
286 };
280287
281 m.import_table.ensureUnusedCapacity(allocator, options.imports.len) catch @panic("OOM");288 m.import_table.ensureUnusedCapacity(allocator, options.imports.len) catch @panic("OOM");
282 for (options.imports) |dep| {289 for (options.imports) |dep| {
283 m.import_table.putAssumeCapacity(dep.name, dep.module);290 m.import_table.putAssumeCapacity(dep.name, dep.module);
291 }
292 },
293 .existing => |existing| {
294 m.* = existing.*;
295 },
284 }296 }
285297
286 if (compile) |c| {298 if (compile) |c| {
...@@ -294,7 +306,7 @@ pub fn init(m: *Module, owner: *std.Build, options: CreateOptions, compile: ?*St...@@ -294,7 +306,7 @@ pub fn init(m: *Module, owner: *std.Build, options: CreateOptions, compile: ?*St
294306
295pub fn create(owner: *std.Build, options: CreateOptions) *Module {307pub fn create(owner: *std.Build, options: CreateOptions) *Module {
296 const m = owner.allocator.create(Module) catch @panic("OOM");308 const m = owner.allocator.create(Module) catch @panic("OOM");
297 m.init(owner, options, null);309 m.init(owner, .{ .options = options }, null);
298 return m;310 return m;
299}311}
300312
lib/std/Build/Step/Compile.zig+5-6
...@@ -262,7 +262,7 @@ pub const Entry = union(enum) {...@@ -262,7 +262,7 @@ pub const Entry = union(enum) {
262262
263pub const Options = struct {263pub const Options = struct {
264 name: []const u8,264 name: []const u8,
265 root_module: Module.CreateOptions,265 root_module: *Module,
266 kind: Kind,266 kind: Kind,
267 linkage: ?std.builtin.LinkMode = null,267 linkage: ?std.builtin.LinkMode = null,
268 version: ?std.SemanticVersion = null,268 version: ?std.SemanticVersion = null,
...@@ -359,7 +359,8 @@ pub fn create(owner: *std.Build, options: Options) *Compile {...@@ -359,7 +359,8 @@ pub fn create(owner: *std.Build, options: Options) *Compile {
359 else359 else
360 owner.fmt("{s} ", .{name});360 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");
363 const target = resolved_target.result;364 const target = resolved_target.result;
364365
365 const step_name = owner.fmt("{s} {s}{s} {s}", .{366 const step_name = owner.fmt("{s} {s}{s} {s}", .{
...@@ -431,10 +432,8 @@ pub fn create(owner: *std.Build, options: Options) *Compile {...@@ -431,10 +432,8 @@ pub fn create(owner: *std.Build, options: Options) *Compile {
431432
432 .zig_process = null,433 .zig_process = null,
433 };434 };
434435 options.root_module.init(owner, .{ .existing = options.root_module }, compile);
435 const root_module = owner.allocator.create(Module) catch @panic("OOM");436 compile.root_module = options.root_module;
436 root_module.init(owner, options.root_module, compile);
437 compile.root_module = root_module;
438437
439 if (options.zig_lib_dir) |lp| {438 if (options.zig_lib_dir) |lp| {
440 compile.zig_lib_dir = lp.dupe(compile.step.owner);439 compile.zig_lib_dir = lp.dupe(compile.step.owner);
test/link/link.zig+2-2
...@@ -70,7 +70,7 @@ fn addCompileStep(...@@ -70,7 +70,7 @@ fn addCompileStep(
70) *Compile {70) *Compile {
71 const compile_step = Compile.create(b, .{71 const compile_step = Compile.create(b, .{
72 .name = overlay.name,72 .name = overlay.name,
73 .root_module = .{73 .root_module = b.createModule(.{
74 .target = base.target,74 .target = base.target,
75 .optimize = base.optimize,75 .optimize = base.optimize,
76 .root_source_file = rsf: {76 .root_source_file = rsf: {
...@@ -80,7 +80,7 @@ fn addCompileStep(...@@ -80,7 +80,7 @@ fn addCompileStep(
80 },80 },
81 .pic = overlay.pic,81 .pic = overlay.pic,
82 .strip = if (base.strip) |s| s else overlay.strip,82 .strip = if (base.strip) |s| s else overlay.strip,
83 },83 }),
84 .use_llvm = base.use_llvm,84 .use_llvm = base.use_llvm,
85 .use_lld = base.use_lld,85 .use_lld = base.use_lld,
86 .kind = switch (kind) {86 .kind = switch (kind) {