@@ -207,6 +207,8 @@ use_lld: ?bool,
207207/// otherwise.
208208expect_errors : []const []const u8 = &.{},
209209
210+ force_build : bool ,
211+
210212emit_directory : GeneratedFile ,
211213
212214generated_docs : ? * GeneratedFile ,
@@ -374,6 +376,17 @@ pub const Kind = enum {
374376
375377pub const Linkage = enum { dynamic , static };
376378
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+
377390pub fn create (owner : * std.Build , options : Options ) * Compile {
378391 const name = owner .dupe (options .name );
379392 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 {
468481 .installed_path = null ,
469482 .force_undefined_symbols = StringHashMap (void ).init (owner .allocator ),
470483
484+ .force_build = false ,
485+
471486 .emit_directory = GeneratedFile { .step = & self .step },
472487
473488 .generated_docs = null ,
@@ -972,6 +987,26 @@ fn getEmittedFileGeneric(self: *Compile, output_file: *?*GeneratedFile) LazyPath
972987 return .{ .generated = generated_file };
973988}
974989
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+
9751010pub const getOutputDirectorySource = getEmitDirectory ; // DEPRECATED, use getEmitDirectory
9761011
9771012/// Returns the path to the output directory.
@@ -1163,7 +1198,7 @@ pub fn setExecCmd(self: *Compile, args: []const ?[]const u8) void {
11631198}
11641199
11651200fn linkLibraryOrObject (self : * Compile , other : * Compile ) void {
1166- _ = other .getEmittedBin (); // Force emission of the binary
1201+ other .forceEmit ( .bin );
11671202
11681203 if (other .kind == .lib and other .target .isWindows ()) { // TODO(xq): Is this the correct logic here?
11691204 _ = other .getEmittedImplib (); // Force emission of the binary
@@ -1568,11 +1603,11 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
15681603 if (file .ptr != null ) any_emitted_file = true ;
15691604 }
15701605
1571- if (! any_emitted_file ) {
1606+ if (! any_emitted_file and ! self . force_build ) {
15721607 std .debug .getStderrMutex ().lock ();
15731608 const stderr = std .io .getStdErr ();
15741609 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 });
15761611 }
15771612
15781613 try addFlag (& zig_args , "strip" , self .strip );
0 commit comments