aboutsummaryrefslogtreecommitdiff
path: root/src/link/MachO.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/link/MachO.zig')
-rw-r--r--src/link/MachO.zig42
1 files changed, 23 insertions, 19 deletions
diff --git a/src/link/MachO.zig b/src/link/MachO.zig
index f0f25bea66..e00a4d2c2d 100644
--- a/src/link/MachO.zig
+++ b/src/link/MachO.zig
@@ -698,8 +698,8 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {
try positionals.append(comp.libcxx_static_lib.?.full_object_path);
}
- // Shared libraries.
- var shared_libs = std.ArrayList([]const u8).init(arena);
+ // Shared and static libraries passed via `-l` flag.
+ var libs = std.ArrayList([]const u8).init(arena);
var search_lib_names = std.ArrayList([]const u8).init(arena);
const system_libs = self.base.options.system_libs.items();
@@ -708,9 +708,8 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {
// By this time, we depend on these libs being dynamically linked libraries and not static libraries
// (the check for that needs to be earlier), but they could be full paths to .dylib files, in which
// case we want to avoid prepending "-l".
- // TODO I think they should go as an input file instead of via shared_libs.
if (Compilation.classifyFileExt(link_lib) == .shared_library) {
- try shared_libs.append(link_lib);
+ try positionals.append(link_lib);
continue;
}
@@ -760,24 +759,29 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {
}
}
- for (search_lib_names.items) |l_name| {
- // TODO text-based API, or .tbd files.
- const l_name_ext = try std.fmt.allocPrint(arena, "lib{s}.dylib", .{l_name});
+ // TODO text-based API, or .tbd files.
+ const exts = &[_][]const u8{ "dylib", "a" };
+ for (search_lib_names.items) |l_name| {
var found = false;
- for (search_lib_dirs.items) |lib_dir| {
- const full_path = try fs.path.join(arena, &[_][]const u8{ lib_dir, l_name_ext });
- // Check if the dylib file exists.
- const tmp = fs.cwd().openFile(full_path, .{}) catch |err| switch (err) {
- error.FileNotFound => continue,
- else => |e| return e,
- };
- defer tmp.close();
+ for (exts) |ext| ext: {
+ const l_name_ext = try std.fmt.allocPrint(arena, "lib{s}.{s}", .{ l_name, ext });
+
+ for (search_lib_dirs.items) |lib_dir| {
+ const full_path = try fs.path.join(arena, &[_][]const u8{ lib_dir, l_name_ext });
- try shared_libs.append(full_path);
- found = true;
- break;
+ // Check if the dylib file exists.
+ const tmp = fs.cwd().openFile(full_path, .{}) catch |err| switch (err) {
+ error.FileNotFound => continue,
+ else => |e| return e,
+ };
+ defer tmp.close();
+
+ try libs.append(full_path);
+ found = true;
+ break :ext;
+ }
}
if (!found) {
@@ -835,7 +839,7 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {
}
try zld.link(positionals.items, full_out_path, .{
- .shared_libs = shared_libs.items,
+ .libs = libs.items,
.rpaths = rpaths.items,
});