diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2023-08-01 23:48:14 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2023-08-03 09:52:14 -0700 |
| commit | 986a3d23abcbdb61fd733d2340d4872b6ee55dca (patch) | |
| tree | 9efe038889e06038573ead7e3596802585dc977a | |
| parent | e565ff305ae208b15058a462d348fde515b3e950 (diff) | |
| download | zig-986a3d23abcbdb61fd733d2340d4872b6ee55dca.tar.gz zig-986a3d23abcbdb61fd733d2340d4872b6ee55dca.zip | |
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.
| -rw-r--r-- | src/Compilation.zig | 4 | ||||
| -rw-r--r-- | src/link.zig | 8 | ||||
| -rw-r--r-- | src/link/Elf.zig | 2 | ||||
| -rw-r--r-- | src/link/MachO/zld.zig | 2 |
4 files changed, 10 insertions, 6 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig index 0c8b3c5248..91b31c6004 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -1728,7 +1728,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { try comp.bin_file.options.system_libs.put(comp.gpa, name, .{ .needed = false, .weak = false, - .path = name, + .path = null, }); } } @@ -5621,7 +5621,7 @@ pub fn addLinkLib(comp: *Compilation, lib_name: []const u8) !void { gop.value_ptr.* = .{ .needed = true, .weak = false, - .path = undefined, + .path = null, }; try comp.work_queue.writeItem(.{ .windows_import_lib = comp.bin_file.options.system_libs.count() - 1, diff --git a/src/link.zig b/src/link.zig index 9edba50123..6e5921d815 100644 --- a/src/link.zig +++ b/src/link.zig @@ -26,7 +26,11 @@ const TypedValue = @import("TypedValue.zig"); pub const SystemLib = struct { needed: 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`. @@ -48,7 +52,7 @@ pub fn hashAddSystemLibs( for (hm.values()) |value| { man.hash.add(value.needed); man.hash.add(value.weak); - _ = try man.addFile(value.path, null); + if (value.path) |p| _ = try man.addFile(p, null); } } diff --git a/src/link/Elf.zig b/src/link/Elf.zig index 3292168bce..dd88d47fab 100644 --- a/src/link/Elf.zig +++ b/src/link/Elf.zig @@ -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), // but they could be full paths to .so files, in which case we // want to avoid prepending "-l". - argv.appendAssumeCapacity(lib_info.path); + argv.appendAssumeCapacity(lib_info.path.?); } if (!as_needed) { diff --git a/src/link/MachO/zld.zig b/src/link/MachO/zld.zig index 40cf9b217a..56eee2b546 100644 --- a/src/link/MachO/zld.zig +++ b/src/link/MachO/zld.zig @@ -3554,7 +3554,7 @@ pub fn linkWithZld(macho_file: *MachO, comp: *Compilation, prog_node: *std.Progr { const vals = options.system_libs.values(); 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); |
