| ... | ... | @@ -705,6 +705,7 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void { |
| 705 | 705 | // By this time, we depend on these libs being dynamically linked libraries and not static libraries |
| 706 | 706 | // (the check for that needs to be earlier), but they could be full paths to .dylib files, in which |
| 707 | 707 | // case we want to avoid prepending "-l". |
| 708 | // TODO I think then they should go as an input file instead of via shared_libs. |
| 708 | 709 | if (Compilation.classifyFileExt(link_lib) == .shared_library) { |
| 709 | 710 | try shared_libs.append(link_lib); |
| 710 | 711 | continue; |
| ... | ... | @@ -714,18 +715,45 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void { |
| 714 | 715 | } |
| 715 | 716 | |
| 716 | 717 | var search_lib_dirs = std.ArrayList([]const u8).init(arena); |
| 717 | | try search_lib_dirs.ensureCapacity(self.base.options.lib_dirs.len * 2 + 1); |
| 718 | 718 | |
| 719 | | search_lib_dirs.appendAssumeCapacity("."); // We will always start the search in cwd |
| 719 | for (self.base.options.lib_dirs) |path| { |
| 720 | if (fs.path.isAbsolute(path)) { |
| 721 | var candidates = std.ArrayList([]const u8).init(arena); |
| 722 | if (self.base.options.syslibroot) |syslibroot| { |
| 723 | const full_path = try fs.path.join(arena, &[_][]const u8{ syslibroot, path }); |
| 724 | try candidates.append(full_path); |
| 725 | } |
| 726 | try candidates.append(path); |
| 727 | |
| 728 | var found = false; |
| 729 | for (candidates.items) |candidate| { |
| 730 | // Verify that search path actually exists |
| 731 | var tmp = fs.cwd().openDir(candidate, .{}) catch |err| switch (err) { |
| 732 | error.FileNotFound => continue, |
| 733 | else => |e| return e, |
| 734 | }; |
| 735 | defer tmp.close(); |
| 736 | |
| 737 | try search_lib_dirs.append(candidate); |
| 738 | found = true; |
| 739 | break; |
| 740 | } |
| 720 | 741 | |
| 721 | | for (self.base.options.lib_dirs) |lib_dir| { |
| 722 | | search_lib_dirs.appendAssumeCapacity(lib_dir); |
| 723 | | } |
| 742 | if (!found) { |
| 743 | log.warn("directory not found for '-L{s}'", .{path}); |
| 744 | } |
| 745 | } else { |
| 746 | // Verify that search path actually exists |
| 747 | var tmp = fs.cwd().openDir(path, .{}) catch |err| switch (err) { |
| 748 | error.FileNotFound => { |
| 749 | log.warn("directory not found for '-L{s}'", .{path}); |
| 750 | continue; |
| 751 | }, |
| 752 | else => |e| return e, |
| 753 | }; |
| 754 | defer tmp.close(); |
| 724 | 755 | |
| 725 | | if (self.base.options.syslibroot) |syslibroot| { |
| 726 | | for (self.base.options.lib_dirs) |lib_dir| { |
| 727 | | const path = try fs.path.join(arena, &[_][]const u8{ syslibroot, lib_dir }); |
| 728 | | search_lib_dirs.appendAssumeCapacity(path); |
| 756 | try search_lib_dirs.append(path); |
| 729 | 757 | } |
| 730 | 758 | } |
| 731 | 759 | |
| ... | ... | @@ -749,7 +777,7 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void { |
| 749 | 777 | |
| 750 | 778 | if (!found) { |
| 751 | 779 | log.warn("library '-l{s}' not found", .{l_name}); |
| 752 | | log.warn("searched paths:", .{}); |
| 780 | log.warn("Library search paths:", .{}); |
| 753 | 781 | for (search_lib_dirs.items) |lib_dir| { |
| 754 | 782 | log.warn(" {s}", .{lib_dir}); |
| 755 | 783 | } |
| ... | ... | @@ -763,7 +791,7 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void { |
| 763 | 791 | try rpath_table.putNoClobber(rpath, {}); |
| 764 | 792 | } |
| 765 | 793 | |
| 766 | | var rpaths = std.ArrayList([]const u8) .init(arena); |
| 794 | var rpaths = std.ArrayList([]const u8).init(arena); |
| 767 | 795 | try rpaths.ensureCapacity(rpath_table.count()); |
| 768 | 796 | for (rpath_table.items()) |entry| { |
| 769 | 797 | rpaths.appendAssumeCapacity(entry.key); |