From e4b8148e9c0dc8e1e523965456a59d469e93a26c Mon Sep 17 00:00:00 2001 From: xackus <14938807+xackus@users.noreply.github.com> Date: Tue, 15 Dec 2020 19:30:00 +0100 Subject: [PATCH] Fix system library path detection on linux Uses the NativeTargetInfo results instead of std.Target.current. --- lib/std/zig/system.zig | 12 ++++++------ src/main.zig | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/std/zig/system.zig b/lib/std/zig/system.zig index a052c81a7d..ea1e3c87a2 100644 --- a/lib/std/zig/system.zig +++ b/lib/std/zig/system.zig @@ -15,8 +15,6 @@ const Target = std.Target; const CrossTarget = std.zig.CrossTarget; const macos = @import("system/macos.zig"); -const is_windows = Target.current.os.tag == .windows; - pub const getSDKPath = macos.getSDKPath; pub const NativePaths = struct { @@ -26,7 +24,9 @@ pub const NativePaths = struct { rpaths: ArrayList([:0]u8), warnings: ArrayList([:0]u8), - pub fn detect(allocator: *Allocator) !NativePaths { + pub fn detect(allocator: *Allocator, native_info: NativeTargetInfo) !NativePaths { + const native_target = native_info.target; + var self: NativePaths = .{ .include_dirs = ArrayList([:0]u8).init(allocator), .lib_dirs = ArrayList([:0]u8).init(allocator), @@ -103,9 +103,9 @@ pub const NativePaths = struct { return self; } - if (!is_windows) { - const triple = try Target.current.linuxTriple(allocator); - const qual = Target.current.cpu.arch.ptrBitWidth(); + if (native_target.os.tag != .windows) { + const triple = try native_target.linuxTriple(allocator); + const qual = native_target.cpu.arch.ptrBitWidth(); // TODO: $ ld --verbose | grep SEARCH_DIR // the output contains some paths that end with lib64, maybe include them too? diff --git a/src/main.zig b/src/main.zig index 668e601475..992581fe52 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1448,7 +1448,7 @@ fn buildOutputType( } if (cross_target.isNativeOs() and (system_libs.items.len != 0 or want_native_include_dirs)) { - const paths = std.zig.system.NativePaths.detect(arena) catch |err| { + const paths = std.zig.system.NativePaths.detect(arena, target_info) catch |err| { fatal("unable to detect native system paths: {s}", .{@errorName(err)}); }; for (paths.warnings.items) |warning| {