| author | |
| committer | |
| log | 35d0a49db911e9c459902a021a5bfa05c97ca107 |
| tree | 4c3d3c526fe4bcca50ca30fb1ec0ff1b785360f4 |
| parent | 5c0181841081170a118d8e50af2a09f5006f59e1 |
15 files changed, 69 insertions(+), 29 deletions(-)
lib/std/Build/Step/Compile.zig+38-3| ... | @@ -207,6 +207,8 @@ use_lld: ?bool, | ... | @@ -207,6 +207,8 @@ use_lld: ?bool, |
| 207 | /// otherwise. | 207 | /// otherwise. |
| 208 | expect_errors: []const []const u8 = &.{}, | 208 | expect_errors: []const []const u8 = &.{}, |
| 209 | 209 | ||
| 210 | force_build: bool, | ||
| 211 | |||
| 210 | emit_directory: GeneratedFile, | 212 | emit_directory: GeneratedFile, |
| 211 | 213 | ||
| 212 | generated_docs: ?*GeneratedFile, | 214 | generated_docs: ?*GeneratedFile, |
| ... | @@ -374,6 +376,17 @@ pub const Kind = enum { | ... | @@ -374,6 +376,17 @@ pub const Kind = enum { |
| 374 | 376 | ||
| 375 | pub const Linkage = enum { dynamic, static }; | 377 | pub const Linkage = enum { dynamic, static }; |
| 376 | 378 | ||
| 379 | pub const EmitOption = enum { | ||
| 380 | docs, | ||
| 381 | @"asm", | ||
| 382 | bin, | ||
| 383 | pdb, | ||
| 384 | implib, | ||
| 385 | llvm_bc, | ||
| 386 | llvm_ir, | ||
| 387 | h, | ||
| 388 | }; | ||
| 389 | |||
| 377 | pub fn create(owner: *std.Build, options: Options) *Compile { | 390 | pub fn create(owner: *std.Build, options: Options) *Compile { |
| 378 | const name = owner.dupe(options.name); | 391 | const name = owner.dupe(options.name); |
| 379 | const root_src: ?LazyPath = if (options.root_source_file) |rsrc| rsrc.dupe(owner) else null; | 392 | const root_src: ?LazyPath = if (options.root_source_file) |rsrc| rsrc.dupe(owner) else null; |
| ... | @@ -468,6 +481,8 @@ pub fn create(owner: *std.Build, options: Options) *Compile { | ... | @@ -468,6 +481,8 @@ pub fn create(owner: *std.Build, options: Options) *Compile { |
| 468 | .installed_path = null, | 481 | .installed_path = null, |
| 469 | .force_undefined_symbols = StringHashMap(void).init(owner.allocator), | 482 | .force_undefined_symbols = StringHashMap(void).init(owner.allocator), |
| 470 | 483 | ||
| 484 | .force_build = false, | ||
| 485 | |||
| 471 | .emit_directory = GeneratedFile{ .step = &self.step }, | 486 | .emit_directory = GeneratedFile{ .step = &self.step }, |
| 472 | 487 | ||
| 473 | .generated_docs = null, | 488 | .generated_docs = null, |
| ... | @@ -972,6 +987,26 @@ fn getEmittedFileGeneric(self: *Compile, output_file: *?*GeneratedFile) LazyPath | ... | @@ -972,6 +987,26 @@ fn getEmittedFileGeneric(self: *Compile, output_file: *?*GeneratedFile) LazyPath |
| 972 | return .{ .generated = generated_file }; | 987 | return .{ .generated = generated_file }; |
| 973 | } | 988 | } |
| 974 | 989 | ||
| 990 | /// Disables the panic in the build evaluation if nothing is emitted. | ||
| 991 | /// | ||
| 992 | /// Unless for compilation tests this is a code smell. | ||
| 993 | pub fn forceBuild(self: *Compile) void { | ||
| 994 | self.force_build = true; | ||
| 995 | } | ||
| 996 | |||
| 997 | pub fn forceEmit(self: *Compile, emit: EmitOption) void { | ||
| 998 | switch (emit) { | ||
| 999 | .docs => _ = self.getEmittedDocs(), | ||
| 1000 | .@"asm" => _ = self.getEmittedAsm(), | ||
| 1001 | .bin => _ = self.getEmittedBin(), | ||
| 1002 | .pdb => _ = self.getEmittedPdb(), | ||
| 1003 | .implib => _ = self.getEmittedImplib(), | ||
| 1004 | .llvm_bc => _ = self.getEmittedLlvmBc(), | ||
| 1005 | .llvm_ir => _ = self.getEmittedLlvmIr(), | ||
| 1006 | .h => _ = self.getEmittedH(), | ||
| 1007 | } | ||
| 1008 | } | ||
| 1009 | |||
| 975 | pub const getOutputDirectorySource = getEmitDirectory; // DEPRECATED, use getEmitDirectory | 1010 | pub const getOutputDirectorySource = getEmitDirectory; // DEPRECATED, use getEmitDirectory |
| 976 | 1011 | ||
| 977 | /// Returns the path to the output directory. | 1012 | /// Returns the path to the output directory. |
| ... | @@ -1163,7 +1198,7 @@ pub fn setExecCmd(self: *Compile, args: []const ?[]const u8) void { | ... | @@ -1163,7 +1198,7 @@ pub fn setExecCmd(self: *Compile, args: []const ?[]const u8) void { |
| 1163 | } | 1198 | } |
| 1164 | 1199 | ||
| 1165 | fn linkLibraryOrObject(self: *Compile, other: *Compile) void { | 1200 | fn linkLibraryOrObject(self: *Compile, other: *Compile) void { |
| 1166 | _ = other.getEmittedBin(); // Force emission of the binary | 1201 | other.forceEmit(.bin); |
| 1167 | 1202 | ||
| 1168 | if (other.kind == .lib and other.target.isWindows()) { // TODO(xq): Is this the correct logic here? | 1203 | if (other.kind == .lib and other.target.isWindows()) { // TODO(xq): Is this the correct logic here? |
| 1169 | _ = other.getEmittedImplib(); // Force emission of the binary | 1204 | _ = other.getEmittedImplib(); // Force emission of the binary |
| ... | @@ -1568,11 +1603,11 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -1568,11 +1603,11 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1568 | if (file.ptr != null) any_emitted_file = true; | 1603 | if (file.ptr != null) any_emitted_file = true; |
| 1569 | } | 1604 | } |
| 1570 | 1605 | ||
| 1571 | if (!any_emitted_file) { | 1606 | if (!any_emitted_file and !self.force_build) { |
| 1572 | std.debug.getStderrMutex().lock(); | 1607 | std.debug.getStderrMutex().lock(); |
| 1573 | const stderr = std.io.getStdErr(); | 1608 | const stderr = std.io.getStdErr(); |
| 1574 | build_util.dumpBadGetPathHelp(&self.step, stderr, self.step.owner, null) catch {}; | 1609 | build_util.dumpBadGetPathHelp(&self.step, stderr, self.step.owner, null) catch {}; |
| 1575 | std.debug.panic("Artifact '{s}' has no emit options set, but it is made. Did you forget to call `getEmitted*()`?.", .{self.name}); | 1610 | std.debug.panic("Artifact '{s}' has no emit options set, but it is made. Did you forget to call `.getEmitted*()`? If not, use `.forceBuild()` or `.forceEmit(…)` to make sure it builds anyways.", .{self.name}); |
| 1576 | } | 1611 | } |
| 1577 | 1612 | ||
| 1578 | try addFlag(&zig_args, "strip", self.strip); | 1613 | try addFlag(&zig_args, "strip", self.strip); |
lib/std/Build/Step/InstallArtifact.zig+2-1| ... | @@ -42,7 +42,8 @@ pub fn create(owner: *std.Build, artifact: *Step.Compile) *InstallArtifact { | ... | @@ -42,7 +42,8 @@ pub fn create(owner: *std.Build, artifact: *Step.Compile) *InstallArtifact { |
| 42 | }; | 42 | }; |
| 43 | self.step.dependOn(&artifact.step); | 43 | self.step.dependOn(&artifact.step); |
| 44 | 44 | ||
| 45 | _ = artifact.getEmittedBin(); // force creation | 45 | artifact.forceEmit(.bin); |
| 46 | |||
| 46 | owner.pushInstalledFile(self.dest_dir, artifact.out_filename); | 47 | owner.pushInstalledFile(self.dest_dir, artifact.out_filename); |
| 47 | if (self.artifact.isDynamicLibrary()) { | 48 | if (self.artifact.isDynamicLibrary()) { |
| 48 | if (artifact.major_only_filename) |name| { | 49 | if (artifact.major_only_filename) |name| { |
test/link/glibc_compat/build.zig+1-1| ... | @@ -13,7 +13,7 @@ pub fn build(b: *std.Build) void { | ... | @@ -13,7 +13,7 @@ pub fn build(b: *std.Build) void { |
| 13 | ) catch unreachable, | 13 | ) catch unreachable, |
| 14 | }); | 14 | }); |
| 15 | exe.linkLibC(); | 15 | exe.linkLibC(); |
| 16 | _ = exe.getEmittedBin(); // force emission | 16 | exe.forceBuild(); |
| 17 | test_step.dependOn(&exe.step); | 17 | test_step.dependOn(&exe.step); |
| 18 | } | 18 | } |
| 19 | } | 19 | } |
test/link/macho/needed_library/build.zig+1-1| ... | @@ -23,7 +23,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize | ... | @@ -23,7 +23,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 23 | }); | 23 | }); |
| 24 | dylib.addCSourceFile(.{ .file = .{ .path = "a.c" }, .flags = &.{} }); | 24 | dylib.addCSourceFile(.{ .file = .{ .path = "a.c" }, .flags = &.{} }); |
| 25 | dylib.linkLibC(); | 25 | dylib.linkLibC(); |
| 26 | _ = dylib.getEmittedBin(); // enforce emission | 26 | dylib.forceEmit(.bin); // enforce library creation, we import it below |
| 27 | 27 | ||
| 28 | // -dead_strip_dylibs | 28 | // -dead_strip_dylibs |
| 29 | // -needed-la | 29 | // -needed-la |
test/link/macho/search_strategy/build.zig+2-2| ... | @@ -60,7 +60,7 @@ fn createScenario( | ... | @@ -60,7 +60,7 @@ fn createScenario( |
| 60 | static.override_dest_dir = std.Build.InstallDir{ | 60 | static.override_dest_dir = std.Build.InstallDir{ |
| 61 | .custom = "static", | 61 | .custom = "static", |
| 62 | }; | 62 | }; |
| 63 | _ = static.getEmittedBin(); // enforce emission | 63 | static.forceEmit(.bin); |
| 64 | 64 | ||
| 65 | const dylib = b.addSharedLibrary(.{ | 65 | const dylib = b.addSharedLibrary(.{ |
| 66 | .name = name, | 66 | .name = name, |
| ... | @@ -73,7 +73,7 @@ fn createScenario( | ... | @@ -73,7 +73,7 @@ fn createScenario( |
| 73 | dylib.override_dest_dir = std.Build.InstallDir{ | 73 | dylib.override_dest_dir = std.Build.InstallDir{ |
| 74 | .custom = "dynamic", | 74 | .custom = "dynamic", |
| 75 | }; | 75 | }; |
| 76 | _ = dylib.getEmittedBin(); // enforce emission | 76 | dylib.forceEmit(.bin); // we want the binary to be built as we use it further below |
| 77 | 77 | ||
| 78 | const exe = b.addExecutable(.{ | 78 | const exe = b.addExecutable(.{ |
| 79 | .name = name, | 79 | .name = name, |
test/src/Cases.zig+5-4| ... | @@ -551,10 +551,11 @@ pub fn lowerToBuildSteps( | ... | @@ -551,10 +551,11 @@ pub fn lowerToBuildSteps( |
| 551 | }), | 551 | }), |
| 552 | }; | 552 | }; |
| 553 | 553 | ||
| 554 | if (case.emit_bin) | 554 | if (case.emit_bin) { |
| 555 | _ = artifact.getEmittedBin(); | 555 | artifact.forceEmit(.bin); |
| 556 | 556 | } else { | |
| 557 | _ = artifact.getEmittedBin(); // TODO(xq): The test cases break if we set all to -fno-emit-X | 557 | artifact.forceBuild(); |
| 558 | } | ||
| 558 | 559 | ||
| 559 | if (case.link_libc) artifact.linkLibC(); | 560 | if (case.link_libc) artifact.linkLibC(); |
| 560 | 561 |
test/standalone.zig+10-8| ... | @@ -140,14 +140,16 @@ pub const build_cases = [_]BuildCase{ | ... | @@ -140,14 +140,16 @@ pub const build_cases = [_]BuildCase{ |
| 140 | .build_root = "test/standalone/install_raw_hex", | 140 | .build_root = "test/standalone/install_raw_hex", |
| 141 | .import = @import("standalone/install_raw_hex/build.zig"), | 141 | .import = @import("standalone/install_raw_hex/build.zig"), |
| 142 | }, | 142 | }, |
| 143 | .{ | 143 | // TODO take away EmitOption.emit_to option and make it give a FileSource |
| 144 | .build_root = "test/standalone/emit_asm_and_bin", | 144 | // .{ |
| 145 | .import = @import("standalone/emit_asm_and_bin/build.zig"), | 145 | // .build_root = "test/standalone/emit_asm_and_bin", |
| 146 | }, | 146 | // .import = @import("standalone/emit_asm_and_bin/build.zig"), |
| 147 | .{ | 147 | // }, |
| 148 | .build_root = "test/standalone/issue_12588", | 148 | // TODO take away EmitOption.emit_to option and make it give a FileSource |
| 149 | .import = @import("standalone/issue_12588/build.zig"), | 149 | // .{ |
| 150 | }, | 150 | // .build_root = "test/standalone/issue_12588", |
| 151 | // .import = @import("standalone/issue_12588/build.zig"), | ||
| 152 | // }, | ||
| 151 | .{ | 153 | .{ |
| 152 | .build_root = "test/standalone/child_process", | 154 | .build_root = "test/standalone/child_process", |
| 153 | .import = @import("standalone/child_process/build.zig"), | 155 | .import = @import("standalone/child_process/build.zig"), |
test/standalone/coff_dwarf/build.zig+1-1| ... | @@ -23,7 +23,7 @@ pub fn build(b: *std.Build) void { | ... | @@ -23,7 +23,7 @@ pub fn build(b: *std.Build) void { |
| 23 | .optimize = optimize, | 23 | .optimize = optimize, |
| 24 | .target = target, | 24 | .target = target, |
| 25 | }); | 25 | }); |
| 26 | lib.addCSourceFile("shared_lib.c", &.{"-gdwarf"}); | 26 | lib.addCSourceFile(.{ .file = "shared_lib.c", .flags = &.{"-gdwarf"} }); |
| 27 | lib.linkLibC(); | 27 | lib.linkLibC(); |
| 28 | exe.linkLibrary(lib); | 28 | exe.linkLibrary(lib); |
| 29 | 29 |
test/standalone/embed_generated_file/build.zig+1-1| ... | @@ -22,7 +22,7 @@ pub fn build(b: *std.Build) void { | ... | @@ -22,7 +22,7 @@ pub fn build(b: *std.Build) void { |
| 22 | .source_file = bootloader.getEmittedBin(), | 22 | .source_file = bootloader.getEmittedBin(), |
| 23 | }); | 23 | }); |
| 24 | 24 | ||
| 25 | _ = exe.getEmittedBin(); // enforce emission | 25 | exe.forceBuild(); |
| 26 | 26 | ||
| 27 | test_step.dependOn(&exe.step); | 27 | test_step.dependOn(&exe.step); |
| 28 | } | 28 | } |
test/standalone/emit_asm_and_bin/build.zig+2-2| ... | @@ -8,8 +8,8 @@ pub fn build(b: *std.Build) void { | ... | @@ -8,8 +8,8 @@ pub fn build(b: *std.Build) void { |
| 8 | .root_source_file = .{ .path = "main.zig" }, | 8 | .root_source_file = .{ .path = "main.zig" }, |
| 9 | .optimize = b.standardOptimizeOption(.{}), | 9 | .optimize = b.standardOptimizeOption(.{}), |
| 10 | }); | 10 | }); |
| 11 | _ = main.getEmittedBin(); // main.emit_asm = .{ .emit_to = b.pathFromRoot("main.s") }; | 11 | main.forceEmit(.bin); |
| 12 | _ = main.getEmittedAsm(); // main.emit_bin = .{ .emit_to = b.pathFromRoot("main") }; | 12 | main.forceEmit(.@"asm"); |
| 13 | 13 | ||
| 14 | test_step.dependOn(&b.addRunArtifact(main).step); | 14 | test_step.dependOn(&b.addRunArtifact(main).step); |
| 15 | } | 15 | } |
test/standalone/issue_339/build.zig+1-1| ... | @@ -14,7 +14,7 @@ pub fn build(b: *std.Build) void { | ... | @@ -14,7 +14,7 @@ pub fn build(b: *std.Build) void { |
| 14 | .optimize = optimize, | 14 | .optimize = optimize, |
| 15 | }); | 15 | }); |
| 16 | 16 | ||
| 17 | _ = obj.getEmittedBin(); // enforce emission | 17 | obj.forceBuild(); |
| 18 | 18 | ||
| 19 | test_step.dependOn(&obj.step); | 19 | test_step.dependOn(&obj.step); |
| 20 | } | 20 | } |
test/standalone/issue_5825/build.zig+1-1| ... | @@ -27,7 +27,7 @@ pub fn build(b: *std.Build) void { | ... | @@ -27,7 +27,7 @@ pub fn build(b: *std.Build) void { |
| 27 | exe.linkSystemLibrary("ntdll"); | 27 | exe.linkSystemLibrary("ntdll"); |
| 28 | exe.addObject(obj); | 28 | exe.addObject(obj); |
| 29 | 29 | ||
| 30 | _ = exe.getEmittedBin(); // enforce emission | 30 | exe.forceBuild(); |
| 31 | 31 | ||
| 32 | test_step.dependOn(&exe.step); | 32 | test_step.dependOn(&exe.step); |
| 33 | } | 33 | } |
test/standalone/issue_794/build.zig+2-1| ... | @@ -8,7 +8,8 @@ pub fn build(b: *std.Build) void { | ... | @@ -8,7 +8,8 @@ pub fn build(b: *std.Build) void { |
| 8 | .root_source_file = .{ .path = "main.zig" }, | 8 | .root_source_file = .{ .path = "main.zig" }, |
| 9 | }); | 9 | }); |
| 10 | test_artifact.addIncludePath(.{ .path = "a_directory" }); | 10 | test_artifact.addIncludePath(.{ .path = "a_directory" }); |
| 11 | _ = test_artifact.getEmittedBin(); // enforce emission | 11 | |
| 12 | test_artifact.forceBuild(); | ||
| 12 | 13 | ||
| 13 | test_step.dependOn(&test_artifact.step); | 14 | test_step.dependOn(&test_artifact.step); |
| 14 | } | 15 | } |
test/standalone/strip_empty_loop/build.zig+1-1| ... | @@ -15,7 +15,7 @@ pub fn build(b: *std.Build) void { | ... | @@ -15,7 +15,7 @@ pub fn build(b: *std.Build) void { |
| 15 | }); | 15 | }); |
| 16 | main.strip = true; | 16 | main.strip = true; |
| 17 | 17 | ||
| 18 | _ = main.getEmittedBin(); // enforce emission | 18 | main.forceBuild(); |
| 19 | 19 | ||
| 20 | test_step.dependOn(&main.step); | 20 | test_step.dependOn(&main.step); |
| 21 | } | 21 | } |
test/tests.zig+1-1| ... | @@ -588,7 +588,7 @@ pub fn addStandaloneTests( | ... | @@ -588,7 +588,7 @@ pub fn addStandaloneTests( |
| 588 | }); | 588 | }); |
| 589 | if (case.link_libc) exe.linkLibC(); | 589 | if (case.link_libc) exe.linkLibC(); |
| 590 | 590 | ||
| 591 | _ = exe.getEmittedBin(); // Force emission | 591 | exe.forceBuild(); |
| 592 | 592 | ||
| 593 | step.dependOn(&exe.step); | 593 | step.dependOn(&exe.step); |
| 594 | } | 594 | } |