| author | |
| committer | |
| log | 3aa802090436a1882fc2093cf0ff8e906340bfcb |
| tree | ef3de677dec0c30bad5f094d8701aba80b86a6ea |
| parent | faafeb51afb9edf5a1f11cb3ab1f9091f07344c7 |
| signature |
4 files changed, 68 insertions(+), 57 deletions(-)
lib/std/Build.zig+12-12| ... | ... | @@ -719,7 +719,7 @@ pub const ExecutableOptions = struct { |
| 719 | 719 | pub fn addExecutable(b: *Build, options: ExecutableOptions) *Step.Compile { |
| 720 | 720 | return Step.Compile.create(b, .{ |
| 721 | 721 | .name = options.name, |
| 722 | .root_module = .{ | |
| 722 | .root_module = b.createModule(.{ | |
| 723 | 723 | .root_source_file = options.root_source_file, |
| 724 | 724 | .target = options.target, |
| 725 | 725 | .optimize = options.optimize, |
| ... | ... | @@ -732,7 +732,7 @@ pub fn addExecutable(b: *Build, options: ExecutableOptions) *Step.Compile { |
| 732 | 732 | .sanitize_thread = options.sanitize_thread, |
| 733 | 733 | .error_tracing = options.error_tracing, |
| 734 | 734 | .code_model = options.code_model, |
| 735 | }, | |
| 735 | }), | |
| 736 | 736 | .version = options.version, |
| 737 | 737 | .kind = .exe, |
| 738 | 738 | .linkage = options.linkage, |
| ... | ... | @@ -769,7 +769,7 @@ pub const ObjectOptions = struct { |
| 769 | 769 | pub fn addObject(b: *Build, options: ObjectOptions) *Step.Compile { |
| 770 | 770 | return Step.Compile.create(b, .{ |
| 771 | 771 | .name = options.name, |
| 772 | .root_module = .{ | |
| 772 | .root_module = b.createModule(.{ | |
| 773 | 773 | .root_source_file = options.root_source_file, |
| 774 | 774 | .target = options.target, |
| 775 | 775 | .optimize = options.optimize, |
| ... | ... | @@ -782,7 +782,7 @@ pub fn addObject(b: *Build, options: ObjectOptions) *Step.Compile { |
| 782 | 782 | .sanitize_thread = options.sanitize_thread, |
| 783 | 783 | .error_tracing = options.error_tracing, |
| 784 | 784 | .code_model = options.code_model, |
| 785 | }, | |
| 785 | }), | |
| 786 | 786 | .kind = .obj, |
| 787 | 787 | .max_rss = options.max_rss, |
| 788 | 788 | .use_llvm = options.use_llvm, |
| ... | ... | @@ -823,7 +823,7 @@ pub const SharedLibraryOptions = struct { |
| 823 | 823 | pub fn addSharedLibrary(b: *Build, options: SharedLibraryOptions) *Step.Compile { |
| 824 | 824 | return Step.Compile.create(b, .{ |
| 825 | 825 | .name = options.name, |
| 826 | .root_module = .{ | |
| 826 | .root_module = b.createModule(.{ | |
| 827 | 827 | .target = options.target, |
| 828 | 828 | .optimize = options.optimize, |
| 829 | 829 | .root_source_file = options.root_source_file, |
| ... | ... | @@ -836,7 +836,7 @@ pub fn addSharedLibrary(b: *Build, options: SharedLibraryOptions) *Step.Compile |
| 836 | 836 | .sanitize_thread = options.sanitize_thread, |
| 837 | 837 | .error_tracing = options.error_tracing, |
| 838 | 838 | .code_model = options.code_model, |
| 839 | }, | |
| 839 | }), | |
| 840 | 840 | .kind = .lib, |
| 841 | 841 | .linkage = .dynamic, |
| 842 | 842 | .version = options.version, |
| ... | ... | @@ -874,7 +874,7 @@ pub const StaticLibraryOptions = struct { |
| 874 | 874 | pub fn addStaticLibrary(b: *Build, options: StaticLibraryOptions) *Step.Compile { |
| 875 | 875 | return Step.Compile.create(b, .{ |
| 876 | 876 | .name = options.name, |
| 877 | .root_module = .{ | |
| 877 | .root_module = b.createModule(.{ | |
| 878 | 878 | .target = options.target, |
| 879 | 879 | .optimize = options.optimize, |
| 880 | 880 | .root_source_file = options.root_source_file, |
| ... | ... | @@ -887,7 +887,7 @@ pub fn addStaticLibrary(b: *Build, options: StaticLibraryOptions) *Step.Compile |
| 887 | 887 | .sanitize_thread = options.sanitize_thread, |
| 888 | 888 | .error_tracing = options.error_tracing, |
| 889 | 889 | .code_model = options.code_model, |
| 890 | }, | |
| 890 | }), | |
| 891 | 891 | .kind = .lib, |
| 892 | 892 | .linkage = .static, |
| 893 | 893 | .version = options.version, |
| ... | ... | @@ -935,7 +935,7 @@ pub fn addTest(b: *Build, options: TestOptions) *Step.Compile { |
| 935 | 935 | return Step.Compile.create(b, .{ |
| 936 | 936 | .name = options.name, |
| 937 | 937 | .kind = .@"test", |
| 938 | .root_module = .{ | |
| 938 | .root_module = b.createModule(.{ | |
| 939 | 939 | .root_source_file = options.root_source_file, |
| 940 | 940 | .target = options.target orelse b.graph.host, |
| 941 | 941 | .optimize = options.optimize, |
| ... | ... | @@ -948,7 +948,7 @@ pub fn addTest(b: *Build, options: TestOptions) *Step.Compile { |
| 948 | 948 | .omit_frame_pointer = options.omit_frame_pointer, |
| 949 | 949 | .sanitize_thread = options.sanitize_thread, |
| 950 | 950 | .error_tracing = options.error_tracing, |
| 951 | }, | |
| 951 | }), | |
| 952 | 952 | .max_rss = options.max_rss, |
| 953 | 953 | .filters = if (options.filter != null and options.filters.len > 0) filters: { |
| 954 | 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 | 978 | const obj_step = Step.Compile.create(b, .{ |
| 979 | 979 | .name = options.name, |
| 980 | 980 | .kind = .obj, |
| 981 | .root_module = .{ | |
| 981 | .root_module = b.createModule(.{ | |
| 982 | 982 | .target = options.target, |
| 983 | 983 | .optimize = options.optimize, |
| 984 | }, | |
| 984 | }), | |
| 985 | 985 | .max_rss = options.max_rss, |
| 986 | 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 | 242 | module: *Module, |
| 243 | 243 | }; |
| 244 | 244 | |
| 245 | pub fn init(m: *Module, owner: *std.Build, options: CreateOptions, compile: ?*Step.Compile) void { | |
| 245 | pub 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 | 251 | const allocator = owner.allocator; |
| 247 | 252 | |
| 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 | }; | |
| 280 | 287 | |
| 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 | }, | |
| 284 | 296 | } |
| 285 | 297 | |
| 286 | 298 | if (compile) |c| { |
| ... | ... | @@ -294,7 +306,7 @@ pub fn init(m: *Module, owner: *std.Build, options: CreateOptions, compile: ?*St |
| 294 | 306 | |
| 295 | 307 | pub fn create(owner: *std.Build, options: CreateOptions) *Module { |
| 296 | 308 | const m = owner.allocator.create(Module) catch @panic("OOM"); |
| 297 | m.init(owner, options, null); | |
| 309 | m.init(owner, .{ .options = options }, null); | |
| 298 | 310 | return m; |
| 299 | 311 | } |
| 300 | 312 |
lib/std/Build/Step/Compile.zig+5-6| ... | ... | @@ -262,7 +262,7 @@ pub const Entry = union(enum) { |
| 262 | 262 | |
| 263 | 263 | pub const Options = struct { |
| 264 | 264 | name: []const u8, |
| 265 | root_module: Module.CreateOptions, | |
| 265 | root_module: *Module, | |
| 266 | 266 | kind: Kind, |
| 267 | 267 | linkage: ?std.builtin.LinkMode = null, |
| 268 | 268 | version: ?std.SemanticVersion = null, |
| ... | ... | @@ -359,7 +359,8 @@ pub fn create(owner: *std.Build, options: Options) *Compile { |
| 359 | 359 | else |
| 360 | 360 | owner.fmt("{s} ", .{name}); |
| 361 | 361 | |
| 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 | 364 | const target = resolved_target.result; |
| 364 | 365 | |
| 365 | 366 | const step_name = owner.fmt("{s} {s}{s} {s}", .{ |
| ... | ... | @@ -431,10 +432,8 @@ pub fn create(owner: *std.Build, options: Options) *Compile { |
| 431 | 432 | |
| 432 | 433 | .zig_process = null, |
| 433 | 434 | }; |
| 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; | |
| 438 | 437 | |
| 439 | 438 | if (options.zig_lib_dir) |lp| { |
| 440 | 439 | compile.zig_lib_dir = lp.dupe(compile.step.owner); |
test/link/link.zig+2-2| ... | ... | @@ -70,7 +70,7 @@ fn addCompileStep( |
| 70 | 70 | ) *Compile { |
| 71 | 71 | const compile_step = Compile.create(b, .{ |
| 72 | 72 | .name = overlay.name, |
| 73 | .root_module = .{ | |
| 73 | .root_module = b.createModule(.{ | |
| 74 | 74 | .target = base.target, |
| 75 | 75 | .optimize = base.optimize, |
| 76 | 76 | .root_source_file = rsf: { |
| ... | ... | @@ -80,7 +80,7 @@ fn addCompileStep( |
| 80 | 80 | }, |
| 81 | 81 | .pic = overlay.pic, |
| 82 | 82 | .strip = if (base.strip) |s| s else overlay.strip, |
| 83 | }, | |
| 83 | }), | |
| 84 | 84 | .use_llvm = base.use_llvm, |
| 85 | 85 | .use_lld = base.use_lld, |
| 86 | 86 | .kind = switch (kind) { |