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.
This commit is contained in:
Andrew Kelley 2023-08-01 23:48:14 -07:00
parent e565ff305a
commit 986a3d23ab
4 changed files with 10 additions and 6 deletions

View file

@ -1728,7 +1728,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
try comp.bin_file.options.system_libs.put(comp.gpa, name, .{ try comp.bin_file.options.system_libs.put(comp.gpa, name, .{
.needed = false, .needed = false,
.weak = false, .weak = false,
.path = name, .path = null,
}); });
} }
} }
@ -5621,7 +5621,7 @@ pub fn addLinkLib(comp: *Compilation, lib_name: []const u8) !void {
gop.value_ptr.* = .{ gop.value_ptr.* = .{
.needed = true, .needed = true,
.weak = false, .weak = false,
.path = undefined, .path = null,
}; };
try comp.work_queue.writeItem(.{ try comp.work_queue.writeItem(.{
.windows_import_lib = comp.bin_file.options.system_libs.count() - 1, .windows_import_lib = comp.bin_file.options.system_libs.count() - 1,

View file

@ -26,7 +26,11 @@ const TypedValue = @import("TypedValue.zig");
pub const SystemLib = struct { pub const SystemLib = struct {
needed: bool, needed: bool,
weak: bool, weak: bool,
path: []const u8, /// 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.
path: ?[]const u8,
}; };
/// When adding a new field, remember to update `hashAddFrameworks`. /// When adding a new field, remember to update `hashAddFrameworks`.
@ -48,7 +52,7 @@ pub fn hashAddSystemLibs(
for (hm.values()) |value| { for (hm.values()) |value| {
man.hash.add(value.needed); man.hash.add(value.needed);
man.hash.add(value.weak); man.hash.add(value.weak);
_ = try man.addFile(value.path, null); if (value.path) |p| _ = try man.addFile(p, null);
} }
} }

View file

@ -1842,7 +1842,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v
// libraries and not static libraries (the check for that needs to be earlier), // libraries and not static libraries (the check for that needs to be earlier),
// but they could be full paths to .so files, in which case we // but they could be full paths to .so files, in which case we
// want to avoid prepending "-l". // want to avoid prepending "-l".
argv.appendAssumeCapacity(lib_info.path); argv.appendAssumeCapacity(lib_info.path.?);
} }
if (!as_needed) { if (!as_needed) {

View file

@ -3554,7 +3554,7 @@ pub fn linkWithZld(macho_file: *MachO, comp: *Compilation, prog_node: *std.Progr
{ {
const vals = options.system_libs.values(); const vals = options.system_libs.values();
try libs.ensureUnusedCapacity(vals.len); try libs.ensureUnusedCapacity(vals.len);
for (vals) |v| libs.putAssumeCapacity(v.path, v); for (vals) |v| libs.putAssumeCapacity(v.path.?, v);
} }
try MachO.resolveLibSystem(arena, comp, options.sysroot, target, options.lib_dirs, &libs); try MachO.resolveLibSystem(arena, comp, options.sysroot, target, options.lib_dirs, &libs);