authorgravatar for carl@astholm.seCarl Åstholm <carl@astholm.se> 2024-04-22 22:13:49+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-04-22 17:12:18-07:00
loge8f28cda9edb06a5f2189ca5e8928df52ddea20d
tree2b243731106c292b737319edaa0d719682a47eaf
parentc947e79d73d3ec7a7a7c4640f001b34f63d36d89

std.Build: Install Windows DLLs to `<prefix>/bin/` by default

Windows does not support RPATH and only searches for DLLs in a small number of predetermined paths by default, with one of them being the directory from which the application loaded. Installing both executables and DLLs to `bin/` by default helps ensure that the executable can find any DLL artifacts it has linked to. DLL import libraries are still installed to `lib/`. These defaults match CMake's behavior.

2 files changed, 9 insertions(+), 8 deletions(-)

lib/std/Build/Step/Compile.zig+5-1
......@@ -614,6 +614,10 @@ pub fn isStaticLibrary(self: *const Compile) bool {
614614 return self.kind == .lib and self.linkage != .dynamic;
615615}
616616
617pub fn isDll(self: *Compile) bool {
618 return self.isDynamicLibrary() and self.rootModuleTarget().os.tag == .windows;
619}
620
617621pub fn producesPdbFile(self: *Compile) bool {
618622 const target = self.rootModuleTarget();
619623 // TODO: Is this right? Isn't PDB for *any* PE/COFF file?
......@@ -632,7 +636,7 @@ pub fn producesPdbFile(self: *Compile) bool {
632636}
633637
634638pub fn producesImplib(self: *Compile) bool {
635 return self.isDynamicLibrary() and self.rootModuleTarget().os.tag == .windows;
639 return self.isDll();
636640}
637641
638642pub fn linkLibC(self: *Compile) void {
lib/std/Build/Step/InstallArtifact.zig+4-7
......@@ -57,8 +57,8 @@ pub fn create(owner: *std.Build, artifact: *Step.Compile, options: Options) *Ins
5757 .disabled => null,
5858 .default => switch (artifact.kind) {
5959 .obj => @panic("object files have no standard installation procedure"),
60 .exe, .@"test" => InstallDir{ .bin = {} },
61 .lib => InstallDir{ .lib = {} },
60 .exe, .@"test" => .bin,
61 .lib => if (artifact.isDll()) .bin else .lib,
6262 },
6363 .override => |o| o,
6464 };
......@@ -77,15 +77,12 @@ pub fn create(owner: *std.Build, artifact: *Step.Compile, options: Options) *Ins
7777 },
7878 .h_dir = switch (options.h_dir) {
7979 .disabled => null,
80 .default => switch (artifact.kind) {
81 .lib => .header,
82 else => null,
83 },
80 .default => if (artifact.kind == .lib) .header else null,
8481 .override => |o| o,
8582 },
8683 .implib_dir = switch (options.implib_dir) {
8784 .disabled => null,
88 .default => if (artifact.producesImplib()) dest_dir else null,
85 .default => if (artifact.producesImplib()) .lib else null,
8986 .override => |o| o,
9087 },
9188