From 4b91e4c91fae760f30becbafaf28befef832ecf5 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 17 Feb 2020 16:03:01 -0500 Subject: [PATCH] fix dynamic linker detection on windows (where there isn't one) --- lib/std/process.zig | 2 +- lib/std/target.zig | 22 ++++++++++++++++++++++ src-self-hosted/libc_installation.zig | 6 +++++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/std/process.zig b/lib/std/process.zig index ddae0bffbb..89307b44da 100644 --- a/lib/std/process.zig +++ b/lib/std/process.zig @@ -666,6 +666,6 @@ pub fn getSelfExeSharedLibPaths(allocator: *Allocator) error{OutOfMemory}![][:0] } return paths.toOwnedSlice(); }, - else => return error.UnimplementedSelfExeSharedPaths, + else => @compileError("getSelfExeSharedLibPaths unimplemented for this target"), } } diff --git a/lib/std/target.zig b/lib/std/target.zig index d3f487e9ff..bc78b2dce5 100644 --- a/lib/std/target.zig +++ b/lib/std/target.zig @@ -1220,6 +1220,28 @@ pub const Target = union(enum) { }; } + pub fn hasDynamicLinker(self: Target) bool { + switch (self.getArch()) { + .wasm32, + .wasm64, + => return false, + else => {}, + } + switch (self.getOs()) { + .freestanding, + .ios, + .tvos, + .watchos, + .macosx, + .uefi, + .windows, + .emscripten, + .other, + => return false, + else => return true, + } + } + /// Caller owns returned memory. pub fn getStandardDynamicLinkerPath( self: Target, diff --git a/src-self-hosted/libc_installation.zig b/src-self-hosted/libc_installation.zig index 1fec40c516..fbb7b010c4 100644 --- a/src-self-hosted/libc_installation.zig +++ b/src-self-hosted/libc_installation.zig @@ -536,7 +536,11 @@ fn ccPrintFileName( } /// Caller owns returned memory. -pub fn detectNativeDynamicLinker(allocator: *Allocator) ![:0]u8 { +pub fn detectNativeDynamicLinker(allocator: *Allocator) error{OutOfMemory, TargetHasNoDynamicLinker, UnknownDynamicLinkerPath}![:0]u8 { + if (!comptime Target.current.hasDynamicLinker()) { + return error.TargetHasNoDynamicLinker; + } + const standard_ld_path = try std.Target.current.getStandardDynamicLinkerPath(allocator); var standard_ld_path_resource: ?[:0]u8 = standard_ld_path; // Set to null to avoid freeing it. defer if (standard_ld_path_resource) |s| allocator.free(s);