Skip to content

Commit ef08894

Browse files
committed
build stage3: add more BSD support
- add netbsd - add dragonfly - fixup freebsd
1 parent 46c3b09 commit ef08894

1 file changed

Lines changed: 32 additions & 18 deletions

File tree

build.zig

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -560,24 +560,38 @@ fn addCmakeCfgOptionsToExe(
560560

561561
// System -lc++ must be used because in this code path we are attempting to link
562562
// against system-provided LLVM, Clang, LLD.
563-
if (exe.target.getOsTag() == .linux) {
564-
// First we try to link against gcc libstdc++. If that doesn't work, we fall
565-
// back to -lc++ and cross our fingers.
566-
addCxxKnownPath(b, cfg, exe, b.fmt("libstdc++.{s}", .{lib_suffix}), "", need_cpp_includes) catch |err| switch (err) {
567-
error.RequiredLibraryNotFound => {
568-
exe.linkSystemLibrary("c++");
569-
},
570-
else => |e| return e,
571-
};
572-
exe.linkSystemLibrary("unwind");
573-
} else if (exe.target.isFreeBSD()) {
574-
try addCxxKnownPath(b, cfg, exe, b.fmt("libc++.{s}", .{lib_suffix}), null, need_cpp_includes);
575-
exe.linkSystemLibrary("pthread");
576-
} else if (exe.target.getOsTag() == .openbsd) {
577-
try addCxxKnownPath(b, cfg, exe, b.fmt("libc++.{s}", .{lib_suffix}), null, need_cpp_includes);
578-
try addCxxKnownPath(b, cfg, exe, b.fmt("libc++abi.{s}", .{lib_suffix}), null, need_cpp_includes);
579-
} else if (exe.target.isDarwin()) {
580-
exe.linkSystemLibrary("c++");
563+
switch (exe.target.getOsTag()) {
564+
.linux => {
565+
// First we try to link against gcc libstdc++. If that doesn't work, we fall
566+
// back to -lc++ and cross our fingers.
567+
addCxxKnownPath(b, cfg, exe, b.fmt("libstdc++.{s}", .{lib_suffix}), "", need_cpp_includes) catch |err| switch (err) {
568+
error.RequiredLibraryNotFound => {
569+
exe.linkSystemLibrary("c++");
570+
},
571+
else => |e| return e,
572+
};
573+
exe.linkSystemLibrary("unwind");
574+
},
575+
.ios, .macos, .watchos, .tvos => {
576+
exe.linkSystemLibrary("c++");
577+
},
578+
.freebsd => {
579+
try addCxxKnownPath(b, cfg, exe, b.fmt("libc++.{s}", .{lib_suffix}), null, need_cpp_includes);
580+
try addCxxKnownPath(b, cfg, exe, b.fmt("libgcc_eh.{s}", .{lib_suffix}), null, need_cpp_includes);
581+
},
582+
.openbsd => {
583+
try addCxxKnownPath(b, cfg, exe, b.fmt("libc++.{s}", .{lib_suffix}), null, need_cpp_includes);
584+
try addCxxKnownPath(b, cfg, exe, b.fmt("libc++abi.{s}", .{lib_suffix}), null, need_cpp_includes);
585+
},
586+
.netbsd => {
587+
try addCxxKnownPath(b, cfg, exe, b.fmt("libstdc++.{s}", .{lib_suffix}), null, need_cpp_includes);
588+
try addCxxKnownPath(b, cfg, exe, b.fmt("libgcc_eh.{s}", .{lib_suffix}), null, need_cpp_includes);
589+
},
590+
.dragonfly => {
591+
try addCxxKnownPath(b, cfg, exe, b.fmt("libstdc++.{s}", .{lib_suffix}), null, need_cpp_includes);
592+
try addCxxKnownPath(b, cfg, exe, b.fmt("libgcc_eh.{s}", .{lib_suffix}), null, need_cpp_includes);
593+
},
594+
else => {},
581595
}
582596
}
583597

0 commit comments

Comments
 (0)