authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-08-01 23:48:14-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-08-03 09:52:14-07:00
log986a3d23abcbdb61fd733d2340d4872b6ee55dca
tree9efe038889e06038573ead7e3596802585dc977a
parente565ff305ae208b15058a462d348fde515b3e950

frontend: make SystemLib.path optional

This can be null in two cases right now: 1. Windows DLLs that zig ships such as advapi32. 2. extern "foo" fn declarations where we find out about libraries too late TODO: make this non-optional and resolve those two cases somehow.

4 files changed, 10 insertions(+), 6 deletions(-)

src/Compilation.zig+2-2
......@@ -1728,7 +1728,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
17281728 try comp.bin_file.options.system_libs.put(comp.gpa, name, .{
17291729 .needed = false,
17301730 .weak = false,
1731 .path = name,
1731 .path = null,
17321732 });
17331733 }
17341734 }
......@@ -5621,7 +5621,7 @@ pub fn addLinkLib(comp: *Compilation, lib_name: []const u8) !void {
56215621 gop.value_ptr.* = .{
56225622 .needed = true,
56235623 .weak = false,
5624 .path = undefined,
5624 .path = null,
56255625 };
56265626 try comp.work_queue.writeItem(.{
56275627 .windows_import_lib = comp.bin_file.options.system_libs.count() - 1,
src/link.zig+6-2
......@@ -26,7 +26,11 @@ const TypedValue = @import("TypedValue.zig");
2626pub const SystemLib = struct {
2727 needed: bool,
2828 weak: bool,
29 path: []const u8,
29 /// This can be null in two cases right now:
30 /// 1. Windows DLLs that zig ships such as advapi32.
31 /// 2. extern "foo" fn declarations where we find out about libraries too late
32 /// TODO: make this non-optional and resolve those two cases somehow.
33 path: ?[]const u8,
3034};
3135
3236/// When adding a new field, remember to update `hashAddFrameworks`.
......@@ -48,7 +52,7 @@ pub fn hashAddSystemLibs(
4852 for (hm.values()) |value| {
4953 man.hash.add(value.needed);
5054 man.hash.add(value.weak);
51 _ = try man.addFile(value.path, null);
55 if (value.path) |p| _ = try man.addFile(p, null);
5256 }
5357}
5458
src/link/Elf.zig+1-1
......@@ -1842,7 +1842,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v
18421842 // libraries and not static libraries (the check for that needs to be earlier),
18431843 // but they could be full paths to .so files, in which case we
18441844 // want to avoid prepending "-l".
1845 argv.appendAssumeCapacity(lib_info.path);
1845 argv.appendAssumeCapacity(lib_info.path.?);
18461846 }
18471847
18481848 if (!as_needed) {
src/link/MachO/zld.zig+1-1
......@@ -3554,7 +3554,7 @@ pub fn linkWithZld(macho_file: *MachO, comp: *Compilation, prog_node: *std.Progr
35543554 {
35553555 const vals = options.system_libs.values();
35563556 try libs.ensureUnusedCapacity(vals.len);
3557 for (vals) |v| libs.putAssumeCapacity(v.path, v);
3557 for (vals) |v| libs.putAssumeCapacity(v.path.?, v);
35583558 }
35593559
35603560 try MachO.resolveLibSystem(arena, comp, options.sysroot, target, options.lib_dirs, &libs);