Skip to content

Commit 0a4d4eb

Browse files
committed
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.
1 parent 0063f4a commit 0a4d4eb

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

src/Compilation.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ const TypedValue = @import("TypedValue.zig");
2626
pub 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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3518,7 +3518,7 @@ pub fn linkWithZld(macho_file: *MachO, comp: *Compilation, prog_node: *std.Progr
35183518
{
35193519
const vals = options.system_libs.values();
35203520
try libs.ensureUnusedCapacity(vals.len);
3521-
for (vals) |v| libs.putAssumeCapacity(v.path, v);
3521+
for (vals) |v| libs.putAssumeCapacity(v.path.?, v);
35223522
}
35233523

35243524
try MachO.resolveLibSystem(arena, comp, options.sysroot, target, options.lib_dirs, &libs);

0 commit comments

Comments
 (0)