Commit 6393928d50

Andrew Kelley <andrew@ziglang.org>
2023-07-30 20:18:09
link: add more respect for -fno-emit-bin
closes #16347
1 parent 38840e2
src/link/Coff.zig
@@ -1452,6 +1452,8 @@ pub fn updateDeclExports(
         if (self.llvm_object) |llvm_object| return llvm_object.updateDeclExports(mod, decl_index, exports);
     }
 
+    if (self.base.options.emit == null) return;
+
     const gpa = self.base.allocator;
 
     const decl = mod.declPtr(decl_index);
src/link/Elf.zig
@@ -2865,6 +2865,8 @@ pub fn updateDeclExports(
         if (self.llvm_object) |llvm_object| return llvm_object.updateDeclExports(mod, decl_index, exports);
     }
 
+    if (self.base.options.emit == null) return;
+
     const tracy = trace(@src());
     defer tracy.end();
 
src/link/MachO.zig
@@ -2386,6 +2386,8 @@ pub fn updateDeclExports(
             return llvm_object.updateDeclExports(mod, decl_index, exports);
     }
 
+    if (self.base.options.emit == null) return;
+
     const tracy = trace(@src());
     defer tracy.end();
 
src/link/NvPtx.zig
@@ -106,10 +106,11 @@ pub fn flushModule(self: *NvPtx, comp: *Compilation, prog_node: *std.Progress.No
     if (build_options.skip_non_native) {
         @panic("Attempted to compile for architecture that was disabled by build configuration");
     }
+    const outfile = comp.bin_file.options.emit orelse return;
+
     const tracy = trace(@src());
     defer tracy.end();
 
-    const outfile = comp.bin_file.options.emit.?;
     // We modify 'comp' before passing it to LLVM, but restore value afterwards.
     // We tell LLVM to not try to build a .o, only an "assembly" file.
     // This is required by the LLVM PTX backend.
src/link/Wasm.zig
@@ -1712,6 +1712,8 @@ pub fn updateDeclExports(
         if (wasm.llvm_object) |llvm_object| return llvm_object.updateDeclExports(mod, decl_index, exports);
     }
 
+    if (wasm.base.options.emit == null) return;
+
     const decl = mod.declPtr(decl_index);
     const atom_index = try wasm.getOrCreateAtomForDecl(decl_index);
     const atom = wasm.getAtom(atom_index);
src/link.zig
@@ -966,6 +966,8 @@ pub const File = struct {
     }
 
     pub fn linkAsArchive(base: *File, comp: *Compilation, prog_node: *std.Progress.Node) FlushError!void {
+        const emit = base.options.emit orelse return;
+
         const tracy = trace(@src());
         defer tracy.end();
 
@@ -973,8 +975,8 @@ pub const File = struct {
         defer arena_allocator.deinit();
         const arena = arena_allocator.allocator();
 
-        const directory = base.options.emit.?.directory; // Just an alias to make it shorter to type.
-        const full_out_path = try directory.join(arena, &[_][]const u8{base.options.emit.?.sub_path});
+        const directory = emit.directory; // Just an alias to make it shorter to type.
+        const full_out_path = try directory.join(arena, &[_][]const u8{emit.sub_path});
         const full_out_path_z = try arena.dupeZ(u8, full_out_path);
 
         // If there is no Zig code to compile, then we should skip flushing the output file