authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-02-17 16:55:12-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-02-17 23:42:48-07:00
log6f42876e74831b7f9cecf5a863634df920c52b98
tree627bbefc0ec47b98a76055299cc700baf39d3cda
parent419074a81ba7d7111bae7d07af26aad9c7deeb1f

CLI: resolve system libs into static libraries

using the provided -L directories before checking if we need to integrate with system library paths. This prevents false positive of invoking system cc to find native paths when in fact all dependencies are satisfied by -L (or --search-prefix to zig build).

3 files changed, 37 insertions(+), 12 deletions(-)

build.zig+1-3
......@@ -502,9 +502,7 @@ fn addCmakeCfgOptionsToExe(
502502 }
503503}
504504
505fn addStaticLlvmOptionsToExe(
506 exe: *std.build.LibExeObjStep,
507) !void {
505fn addStaticLlvmOptionsToExe(exe: *std.build.LibExeObjStep) !void {
508506 // Adds the Zig C++ sources which both stage1 and stage2 need.
509507 //
510508 // We need this because otherwise zig_clang_cc1_main.cpp ends up pulling
ci/zinc/linux_test.sh+1-2
......@@ -48,7 +48,7 @@ cd $WORKSPACE
4848$ZIG fmt --check .
4949
5050# Build stage2 standalone so that we can test stage2 against stage2 compiler-rt.
51$ZIG build -p stage2 -Denable-llvm -Dstatic-llvm -Duse-zig-libcxx
51$ZIG build -p stage2 -Dstatic-llvm -Duse-zig-libcxx
5252
5353stage2/bin/zig test test/behavior.zig -I test -fLLVM
5454stage2/bin/zig test test/behavior.zig -I test
......@@ -94,7 +94,6 @@ tidy --drop-empty-elements no -qe zig-cache/langref.html
9494$ZIG build
9595 --prefix "RELEASE_STAGING" \
9696 --search-prefix "$DEPS_LOCAL" \
97 -Denable-llvm \
9897 -Dstatic-llvm \
9998 -Drelease \
10099 -Dstrip \
src/main.zig+35-7
......@@ -2008,28 +2008,34 @@ fn buildOutputType(
20082008 // are part of libc or libc++. We remove them from the list and communicate their
20092009 // existence via flags instead.
20102010 {
2011 // Similarly, if any libs in this list are statically provided, we remove
2012 // them from this list and populate the link_objects array instead.
2013 const sep = fs.path.sep_str;
2014 var test_path = std.ArrayList(u8).init(gpa);
2015 defer test_path.deinit();
2016
20112017 var i: usize = 0;
2012 while (i < system_libs.count()) {
2018 syslib: while (i < system_libs.count()) {
20132019 const lib_name = system_libs.keys()[i];
20142020
20152021 if (target_util.is_libc_lib_name(target_info.target, lib_name)) {
20162022 link_libc = true;
2017 _ = system_libs.orderedRemove(lib_name);
2023 system_libs.orderedRemoveAt(i);
20182024 continue;
20192025 }
20202026 if (target_util.is_libcpp_lib_name(target_info.target, lib_name)) {
20212027 link_libcpp = true;
2022 _ = system_libs.orderedRemove(lib_name);
2028 system_libs.orderedRemoveAt(i);
20232029 continue;
20242030 }
20252031 if (mem.eql(u8, lib_name, "unwind")) {
20262032 link_libunwind = true;
2027 _ = system_libs.orderedRemove(lib_name);
2033 system_libs.orderedRemoveAt(i);
20282034 continue;
20292035 }
20302036 if (target_util.is_compiler_rt_lib_name(target_info.target, lib_name)) {
20312037 std.log.warn("ignoring superfluous library '{s}': this dependency is fulfilled instead by compiler-rt which zig unconditionally provides", .{lib_name});
2032 _ = system_libs.orderedRemove(lib_name);
2038 system_libs.orderedRemoveAt(i);
20332039 continue;
20342040 }
20352041 if (std.fs.path.isAbsolute(lib_name)) {
......@@ -2038,10 +2044,30 @@ fn buildOutputType(
20382044 if (target_info.target.os.tag == .wasi) {
20392045 if (wasi_libc.getEmulatedLibCRTFile(lib_name)) |crt_file| {
20402046 try wasi_emulated_libs.append(crt_file);
2041 _ = system_libs.orderedRemove(lib_name);
2047 system_libs.orderedRemoveAt(i);
20422048 continue;
20432049 }
20442050 }
2051
2052 for (lib_dirs.items) |lib_dir_path| {
2053 test_path.clearRetainingCapacity();
2054 try test_path.writer().print("{s}" ++ sep ++ "{s}{s}{s}", .{
2055 lib_dir_path,
2056 target_info.target.libPrefix(),
2057 lib_name,
2058 target_info.target.staticLibSuffix(),
2059 });
2060 fs.cwd().access(test_path.items, .{}) catch |err| switch (err) {
2061 error.FileNotFound => continue,
2062 else => |e| fatal("unable to search for static library '{s}': {s}", .{
2063 test_path.items, @errorName(e),
2064 }),
2065 };
2066 try link_objects.append(.{ .path = try arena.dupe(u8, test_path.items) });
2067 system_libs.orderedRemoveAt(i);
2068 continue :syslib;
2069 }
2070
20452071 i += 1;
20462072 }
20472073 }
......@@ -2068,7 +2094,9 @@ fn buildOutputType(
20682094 want_native_include_dirs = true;
20692095 }
20702096
2071 if (sysroot == null and cross_target.isNativeOs() and (system_libs.count() != 0 or want_native_include_dirs)) {
2097 if (sysroot == null and cross_target.isNativeOs() and
2098 (system_libs.count() != 0 or want_native_include_dirs))
2099 {
20722100 const paths = std.zig.system.NativePaths.detect(arena, target_info) catch |err| {
20732101 fatal("unable to detect native system paths: {s}", .{@errorName(err)});
20742102 };