aboutsummaryrefslogtreecommitdiff
path: root/src/link.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2023-06-15 17:10:42 -0700
committerAndrew Kelley <andrew@ziglang.org>2023-08-03 09:52:14 -0700
commita08cc7d2ae3bd6e90f8d26ac13f2e0652687dc30 (patch)
tree85cd80a1276d31cb543ae2d4317b257e39bed146 /src/link.zig
parentf887b0251822f75dc4a3e24ca5337cb681c1eb1f (diff)
downloadzig-a08cc7d2ae3bd6e90f8d26ac13f2e0652687dc30.tar.gz
zig-a08cc7d2ae3bd6e90f8d26ac13f2e0652687dc30.zip
compiler: resolve library paths in the frontend
search_strategy is no longer passed to Compilation at all; instead it is used in the CLI code only. When using Zig CLI mode, `-l` no longer has the ability to link statically; use positional arguments for this. The CLI has a small abstraction around library resolution handling which is used to remove some code duplication regarding static libraries, as well as handle the difference between zig cc CLI mode and zig CLI mode. Thanks to this, system libraries are now included in the cache hash, and thus changes to them will correctly cause cache misses. In the future, lib_dirs should no longer be passed to Compilation at all, because it is a frontend-only concept. Previously, -search_paths_first and -search_dylibs_first were Darwin-only arguments; they now work the same for all targets. Same thing with --sysroot. Improved the error reporting for failure to find a system library. An example error now looks like this: ``` $ zig build-exe test.zig -lfoo -L. -L/a -target x86_64-macos --sysroot /home/andy/local error: unable to find Dynamic system library 'foo' using strategy 'no_fallback'. search paths: ./libfoo.tbd ./libfoo.dylib ./libfoo.so /home/andy/local/a/libfoo.tbd /home/andy/local/a/libfoo.dylib /home/andy/local/a/libfoo.so /a/libfoo.tbd /a/libfoo.dylib /a/libfoo.so ``` closes #14963
Diffstat (limited to 'src/link.zig')
-rw-r--r--src/link.zig33
1 files changed, 27 insertions, 6 deletions
diff --git a/src/link.zig b/src/link.zig
index 42322cbda8..9edba50123 100644
--- a/src/link.zig
+++ b/src/link.zig
@@ -21,7 +21,16 @@ const Type = @import("type.zig").Type;
const TypedValue = @import("TypedValue.zig");
/// When adding a new field, remember to update `hashAddSystemLibs`.
+/// These are *always* dynamically linked. Static libraries will be
+/// provided as positional arguments.
pub const SystemLib = struct {
+ needed: bool,
+ weak: bool,
+ path: []const u8,
+};
+
+/// When adding a new field, remember to update `hashAddFrameworks`.
+pub const Framework = struct {
needed: bool = false,
weak: bool = false,
};
@@ -31,11 +40,23 @@ pub const SortSection = enum { name, alignment };
pub const CacheMode = enum { incremental, whole };
pub fn hashAddSystemLibs(
- hh: *Cache.HashHelper,
+ man: *Cache.Manifest,
hm: std.StringArrayHashMapUnmanaged(SystemLib),
+) !void {
+ const keys = hm.keys();
+ man.hash.addListOfBytes(keys);
+ for (hm.values()) |value| {
+ man.hash.add(value.needed);
+ man.hash.add(value.weak);
+ _ = try man.addFile(value.path, null);
+ }
+}
+
+pub fn hashAddFrameworks(
+ hh: *Cache.HashHelper,
+ hm: std.StringArrayHashMapUnmanaged(Framework),
) void {
const keys = hm.keys();
- hh.add(keys.len);
hh.addListOfBytes(keys);
for (hm.values()) |value| {
hh.add(value.needed);
@@ -183,9 +204,12 @@ pub const Options = struct {
objects: []Compilation.LinkObject,
framework_dirs: []const []const u8,
- frameworks: std.StringArrayHashMapUnmanaged(SystemLib),
+ frameworks: std.StringArrayHashMapUnmanaged(Framework),
+ /// These are *always* dynamically linked. Static libraries will be
+ /// provided as positional arguments.
system_libs: std.StringArrayHashMapUnmanaged(SystemLib),
wasi_emulated_libs: []const wasi_libc.CRTFile,
+ // TODO: remove this. libraries are resolved by the frontend.
lib_dirs: []const []const u8,
rpath_list: []const []const u8,
@@ -225,9 +249,6 @@ pub const Options = struct {
/// (Darwin) size of the __PAGEZERO segment
pagezero_size: ?u64 = null,
- /// (Darwin) search strategy for system libraries
- search_strategy: ?File.MachO.SearchStrategy = null,
-
/// (Darwin) set minimum space for future expansion of the load commands
headerpad_size: ?u32 = null,