authorgravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2026-03-25 00:58:37-04:00
committergravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2026-03-25 00:58:37-04:00
log4e3fcbea84de17afdf391293dc143a1fcc7b2ef7
tree5afa0213d212bbfd13ce8d4ec786bab8ebbca3a2
parent0ee6a79da5a134a57d178edbe1acdd289470c909

- Build: support installing the compiler_rt.dll

This is an extension of the existing hack used for the x86_64 backend combined with the Coff linker

3 files changed, 38 insertions(+), 0 deletions(-)

lib/std/Build/Step/Compile.zig+16
......@@ -219,6 +219,8 @@ generated_docs: ?*GeneratedFile,
219219generated_asm: ?*GeneratedFile,
220220generated_bin: ?*GeneratedFile,
221221generated_pdb: ?*GeneratedFile,
222// hack for stage2_x86_64 + coff
223generated_compiler_rt_dyn_lib: ?*GeneratedFile,
222224generated_implib: ?*GeneratedFile,
223225generated_llvm_bc: ?*GeneratedFile,
224226generated_llvm_ir: ?*GeneratedFile,
......@@ -441,6 +443,7 @@ pub fn create(owner: *std.Build, options: Options) *Compile {
441443 .generated_asm = null,
442444 .generated_bin = null,
443445 .generated_pdb = null,
446 .generated_compiler_rt_dyn_lib = null,
444447 .generated_implib = null,
445448 .generated_llvm_bc = null,
446449 .generated_llvm_ir = null,
......@@ -691,6 +694,11 @@ pub fn producesPdbFile(compile: *Compile) bool {
691694 return compile.isDynamicLibrary() or compile.kind == .exe or compile.kind == .@"test";
692695}
693696
697pub fn producesCompilerRtDynLib(compile: *Compile) bool {
698 if (compile.rootModuleTarget().ofmt != .coff) return false;
699 return compile.use_llvm == false;
700}
701
694702pub fn producesImplib(compile: *Compile) bool {
695703 return compile.isDll();
696704}
......@@ -869,6 +877,12 @@ pub fn getEmittedPdb(compile: *Compile) LazyPath {
869877 return compile.getEmittedFileGeneric(&compile.generated_pdb);
870878}
871879
880/// Returns the generated compiler_rt dynamic library.
881/// This is a hack for stage2_x86_64 + coff.
882pub fn getEmittedCompilerRtDynLib(compile: *Compile) ?LazyPath {
883 return compile.getEmittedFileGeneric(&compile.generated_compiler_rt_dyn_lib);
884}
885
872886/// Returns the path to the generated documentation directory.
873887pub fn getEmittedDocs(compile: *Compile) LazyPath {
874888 return compile.getEmittedFileGeneric(&compile.generated_docs);
......@@ -1794,6 +1808,8 @@ fn make(step: *Step, options: Step.MakeOptions) !void {
17941808 // zig fmt: off
17951809 if (compile.generated_bin) |lp| lp.path = compile.outputPath(output_dir, .bin);
17961810 if (compile.generated_pdb) |lp| lp.path = compile.outputPath(output_dir, .pdb);
1811 // hack for stage2_x86_64 + coff
1812 if (compile.generated_compiler_rt_dyn_lib) |lp| lp.path = compile.outputPath(output_dir, .compiler_rt_dyn_lib);
17971813 if (compile.generated_implib) |lp| lp.path = compile.outputPath(output_dir, .implib);
17981814 if (compile.generated_h) |lp| lp.path = compile.outputPath(output_dir, .h);
17991815 if (compile.generated_docs) |lp| lp.path = compile.outputPath(output_dir, .docs);
lib/std/Build/Step/InstallArtifact.zig+18
......@@ -17,6 +17,10 @@ emitted_implib: ?LazyPath,
1717pdb_dir: ?InstallDir,
1818emitted_pdb: ?LazyPath,
1919
20// hack for stage2_x86_64 + coff
21compiler_rt_dyn_lib_dir: ?InstallDir,
22emitted_compiler_rt_dyn_lib: ?LazyPath,
23
2024h_dir: ?InstallDir,
2125emitted_h: ?LazyPath,
2226
......@@ -35,6 +39,7 @@ pub const Options = struct {
3539 /// Which installation directory to put the main output file into.
3640 dest_dir: Dir = .default,
3741 pdb_dir: Dir = .default,
42 compiler_rt_dyn_lib_dir: Dir = .default,
3843 h_dir: Dir = .default,
3944 implib_dir: Dir = .default,
4045
......@@ -75,6 +80,11 @@ pub fn create(owner: *std.Build, artifact: *Step.Compile, options: Options) *Ins
7580 .default => if (artifact.producesPdbFile()) dest_dir else null,
7681 .override => |o| o,
7782 },
83 .compiler_rt_dyn_lib_dir = switch (options.compiler_rt_dyn_lib_dir) {
84 .disabled => null,
85 .default => if (artifact.producesCompilerRtDynLib()) dest_dir else null,
86 .override => |o| o,
87 },
7888 .h_dir = switch (options.h_dir) {
7989 .disabled => null,
8090 .default => if (artifact.kind == .lib) .header else null,
......@@ -98,6 +108,7 @@ pub fn create(owner: *std.Build, artifact: *Step.Compile, options: Options) *Ins
98108
99109 .emitted_bin = null,
100110 .emitted_pdb = null,
111 .emitted_compiler_rt_dyn_lib = null,
101112 .emitted_h = null,
102113 .emitted_implib = null,
103114
......@@ -107,6 +118,7 @@ pub fn create(owner: *std.Build, artifact: *Step.Compile, options: Options) *Ins
107118 install_artifact.step.dependOn(&artifact.step);
108119
109120 if (install_artifact.dest_dir != null) install_artifact.emitted_bin = artifact.getEmittedBin();
121 if (install_artifact.compiler_rt_dyn_lib_dir != null) install_artifact.emitted_compiler_rt_dyn_lib = artifact.getEmittedCompilerRtDynLib();
110122 if (install_artifact.pdb_dir != null) install_artifact.emitted_pdb = artifact.getEmittedPdb();
111123 // https://github.com/ziglang/zig/issues/9698
112124 //if (install_artifact.h_dir != null) install_artifact.emitted_h = artifact.getEmittedH();
......@@ -135,6 +147,12 @@ fn make(step: *Step, options: Step.MakeOptions) !void {
135147 install_artifact.artifact.installed_path = full_dest_path;
136148 }
137149
150 if (install_artifact.compiler_rt_dyn_lib_dir) |compiler_rt_dir| {
151 const full_compiler_rt_path = b.getInstallPath(compiler_rt_dir, install_artifact.emitted_compiler_rt_dyn_lib.?.basename(b, step));
152 const p = try step.installFile(install_artifact.emitted_compiler_rt_dyn_lib.?, full_compiler_rt_path);
153 all_cached = all_cached and p == .fresh;
154 }
155
138156 if (install_artifact.implib_dir) |implib_dir| {
139157 const full_implib_path = b.getInstallPath(implib_dir, install_artifact.emitted_implib.?.basename(b, step));
140158 const p = try step.installFile(install_artifact.emitted_implib.?, full_implib_path);
lib/std/zig.zig+4
......@@ -985,11 +985,14 @@ pub const EmitArtifact = enum {
985985 docs,
986986 pdb,
987987 h,
988 compiler_rt_dyn_lib,
988989
989990 /// If using `Server` to communicate with the compiler, it will place requested artifacts in
990991 /// paths under the output directory, where those paths are named according to this function.
991992 /// Returned string is allocated with `gpa` and owned by the caller.
992993 pub fn cacheName(ea: EmitArtifact, gpa: Allocator, opts: BinNameOptions) Allocator.Error![]const u8 {
994 // hack for stage2_x86_64 + coff
995 if (ea == .compiler_rt_dyn_lib) return "compiler_rt.dll";
993996 const suffix: []const u8 = switch (ea) {
994997 .bin => return binNameAlloc(gpa, opts),
995998 .@"asm" => ".s",
......@@ -999,6 +1002,7 @@ pub const EmitArtifact = enum {
9991002 .docs => "-docs",
10001003 .pdb => ".pdb",
10011004 .h => ".h",
1005 .compiler_rt_dyn_lib => unreachable,
10021006 };
10031007 return std.fmt.allocPrint(gpa, "{s}{s}", .{ opts.root_name, suffix });
10041008 }