diff options
| author | Michael Dusan <michael.dusan@gmail.com> | 2023-09-01 10:04:26 -0400 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2023-09-03 08:38:03 +0200 |
| commit | 3cf71580c460a30bb52da6e2cbc4482a67bd2930 (patch) | |
| tree | 18d4a840df75cfd0f1296e987ecbedf1c438d171 /build.zig | |
| parent | 1816bb4ab050f46504a2f1e827e9d74f8d253101 (diff) | |
| download | zig-3cf71580c460a30bb52da6e2cbc4482a67bd2930.tar.gz zig-3cf71580c460a30bb52da6e2cbc4482a67bd2930.zip | |
build stage3: detect system libcxx
Detect system libcxx name with the CMake build system and convey that
information to build.zig via config.h so that the same system libcxx is
used for stage3.
This undoes the hacky search 901457d173467c71b681a8c69f4b77c94d516da7 .
closes #17018
Diffstat (limited to 'build.zig')
| -rw-r--r-- | build.zig | 24 |
1 files changed, 14 insertions, 10 deletions
@@ -632,16 +632,14 @@ fn addCmakeCfgOptionsToExe( const lib_suffix = if (static) exe.target.staticLibSuffix()[1..] else exe.target.dynamicLibSuffix()[1..]; switch (exe.target.getOsTag()) { .linux => { - // First we try to link against system libstdc++ or libc++. - // If that doesn't work, we fall to -lc++ and cross our fingers. - const found = for ([_][]const u8{ "stdc++", "c++" }) |name| { - addCxxKnownPath(b, cfg, exe, b.fmt("lib{s}.{s}", .{ name, lib_suffix }), "", need_cpp_includes) catch |err| switch (err) { - error.RequiredLibraryNotFound => continue, - else => |e| return e, - }; - break true; - } else false; - if (!found) exe.linkLibCpp(); + // First we try to link against the detected libcxx name. If that doesn't work, we fall + // back to -lc++ and cross our fingers. + addCxxKnownPath(b, cfg, exe, b.fmt("lib{s}.{s}", .{ cfg.system_libcxx, lib_suffix }), "", need_cpp_includes) catch |err| switch (err) { + error.RequiredLibraryNotFound => { + exe.linkLibCpp(); + }, + else => |e| return e, + }; exe.linkSystemLibrary("unwind"); }, .ios, .macos, .watchos, .tvos => { @@ -775,6 +773,7 @@ const CMakeConfig = struct { llvm_include_dir: []const u8, llvm_libraries: []const u8, dia_guids_lib: []const u8, + system_libcxx: []const u8, }; const max_config_h_bytes = 1 * 1024 * 1024; @@ -840,6 +839,7 @@ fn parseConfigH(b: *std.Build, config_h_text: []const u8) ?CMakeConfig { .llvm_include_dir = undefined, .llvm_libraries = undefined, .dia_guids_lib = undefined, + .system_libcxx = undefined, }; const mappings = [_]struct { prefix: []const u8, field: []const u8 }{ @@ -891,6 +891,10 @@ fn parseConfigH(b: *std.Build, config_h_text: []const u8) ?CMakeConfig { .prefix = "#define ZIG_LLVM_LIB_PATH ", .field = "llvm_lib_dir", }, + .{ + .prefix = "#define ZIG_SYSTEM_LIBCXX", + .field = "system_libcxx", + }, // .prefix = ZIG_LLVM_LINK_MODE parsed manually below }; |
