Skip to content

Commit 8bd734d

Browse files
authored
Merge pull request #13699 from mikdusan/bsd
give BSDs some attention
2 parents c1f404a + 7798af7 commit 8bd734d

File tree

16 files changed

+164
-72
lines changed

16 files changed

+164
-72
lines changed

CMakeLists.txt

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -708,21 +708,15 @@ target_link_libraries(zigcpp LINK_PUBLIC
708708
${CMAKE_THREAD_LIBS_INIT}
709709
)
710710

711-
if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "AMD64")
711+
string(TOLOWER "${CMAKE_HOST_SYSTEM_PROCESSOR}" HOST_TARGET_ARCH)
712+
if(HOST_TARGET_ARCH STREQUAL "amd64")
712713
set(HOST_TARGET_ARCH "x86_64")
713-
elseif(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "amd64")
714-
set(HOST_TARGET_ARCH "x86_64")
715-
elseif(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "arm64")
716-
set(HOST_TARGET_ARCH "aarch64")
717-
elseif(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "ARM64")
714+
elseif(HOST_TARGET_ARCH STREQUAL "arm64")
718715
set(HOST_TARGET_ARCH "aarch64")
719-
else()
720-
string(TOLOWER "${CMAKE_HOST_SYSTEM_PROCESSOR}" HOST_TARGET_ARCH)
721716
endif()
722-
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
717+
string(TOLOWER "${CMAKE_HOST_SYSTEM_NAME}" HOST_TARGET_OS)
718+
if(HOST_TARGET_OS STREQUAL "darwin")
723719
set(HOST_TARGET_OS "macos")
724-
else()
725-
string(TOLOWER "${CMAKE_HOST_SYSTEM_NAME}" HOST_TARGET_OS)
726720
endif()
727721
set(HOST_TARGET_TRIPLE "${HOST_TARGET_ARCH}-${HOST_TARGET_OS}")
728722

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

lib/libcxx/include/__config

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
# endif
149149
// Feature macros for disabling pre ABI v1 features. All of these options
150150
// are deprecated.
151-
# if defined(__FreeBSD__)
151+
# if defined(__FreeBSD__) || defined(__DragonFly__)
152152
# define _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR
153153
# endif
154154
# endif
@@ -726,11 +726,11 @@ _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD
726726
# endif // _LIBCPP_CXX03_LANG
727727

728728
# if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) || defined(__sun__) || \
729-
defined(__NetBSD__)
729+
defined(__NetBSD__) || defined(__DragonFly__)
730730
# define _LIBCPP_LOCALE__L_EXTENSIONS 1
731731
# endif
732732

733-
# ifdef __FreeBSD__
733+
# if defined(__FreeBSD__) || defined(__DragonFly__)
734734
# define _DECLARE_C99_LDBL_MATH 1
735735
# endif
736736

@@ -750,11 +750,11 @@ _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD
750750
# define _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
751751
# endif
752752

753-
# if defined(__APPLE__) || defined(__FreeBSD__)
753+
# if defined(__APPLE__) || defined(__FreeBSD__) || defined(__DragonFly__)
754754
# define _LIBCPP_HAS_DEFAULTRUNELOCALE
755755
# endif
756756

757-
# if defined(__APPLE__) || defined(__FreeBSD__) || defined(__sun__)
757+
# if defined(__APPLE__) || defined(__FreeBSD__) || defined(__sun__) || defined(__DragonFly__)
758758
# define _LIBCPP_WCTYPE_IS_MASK
759759
# endif
760760

@@ -901,6 +901,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD
901901

902902
# if defined(__FreeBSD__) || \
903903
defined(__wasi__) || \
904+
defined(__DragonFly__) || \
904905
defined(__NetBSD__) || \
905906
defined(__OpenBSD__) || \
906907
defined(__NuttX__) || \

lib/libcxx/include/__locale

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
# include <__support/newlib/xlocale.h>
3434
#elif defined(__OpenBSD__)
3535
# include <__support/openbsd/xlocale.h>
36-
#elif (defined(__APPLE__) || defined(__FreeBSD__))
36+
#elif (defined(__APPLE__) || defined(__FreeBSD__) || defined(__DragonFly__))
3737
# include <xlocale.h>
3838
#elif defined(__Fuchsia__)
3939
# include <__support/fuchsia/xlocale.h>
@@ -453,10 +453,10 @@ public:
453453
static const mask __regex_word = 0x4000; // 0x8000 and 0x0100 and 0x00ff are used
454454
# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT
455455
# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA
456-
#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__)
456+
#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__) || defined(__DragonFly__)
457457
# ifdef __APPLE__
458458
typedef __uint32_t mask;
459-
# elif defined(__FreeBSD__)
459+
# elif defined(__FreeBSD__) || defined(__DragonFly__)
460460
typedef unsigned long mask;
461461
# elif defined(__EMSCRIPTEN__) || defined(__NetBSD__)
462462
typedef unsigned short mask;

lib/libcxx/include/locale

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ _LIBCPP_PUSH_MACROS
239239

240240
_LIBCPP_BEGIN_NAMESPACE_STD
241241

242-
#if defined(__APPLE__) || defined(__FreeBSD__)
242+
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__DragonFly__)
243243
# define _LIBCPP_GET_C_LOCALE 0
244244
#elif defined(__NetBSD__)
245245
# define _LIBCPP_GET_C_LOCALE LC_C_LOCALE

lib/libcxx/src/locale.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,7 @@ ctype<char>::classic_table() noexcept
11901190
const ctype<char>::mask*
11911191
ctype<char>::classic_table() noexcept
11921192
{
1193-
#if defined(__APPLE__) || defined(__FreeBSD__)
1193+
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__DragonFly__)
11941194
return _DefaultRuneLocale.__runetype;
11951195
#elif defined(__NetBSD__)
11961196
return _C_ctype_tab_ + 1;

lib/std/c/dragonfly.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) usize;
1212
pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
1313
pub extern "c" fn getrandom(buf_ptr: [*]u8, buf_len: usize, flags: c_uint) isize;
1414
pub extern "c" fn pipe2(fds: *[2]fd_t, flags: u32) c_int;
15+
pub extern "c" fn arc4random_buf(buf: [*]u8, len: usize) void;
1516

1617
pub const dl_iterate_phdr_callback = *const fn (info: *dl_phdr_info, size: usize, data: ?*anyopaque) callconv(.C) c_int;
1718
pub extern "c" fn dl_iterate_phdr(callback: dl_iterate_phdr_callback, data: ?*anyopaque) c_int;
@@ -419,6 +420,7 @@ pub const F = struct {
419420
pub const DUP2FD = 10;
420421
pub const DUPFD_CLOEXEC = 17;
421422
pub const DUP2FD_CLOEXEC = 18;
423+
pub const GETPATH = 19;
422424
};
423425

424426
pub const FD_CLOEXEC = 1;

lib/std/c/freebsd.zig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@ pub extern "c" fn pthread_getthreadid_np() c_int;
1515
pub extern "c" fn pthread_set_name_np(thread: std.c.pthread_t, name: [*:0]const u8) void;
1616
pub extern "c" fn pthread_get_name_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) void;
1717
pub extern "c" fn pipe2(fds: *[2]fd_t, flags: u32) c_int;
18+
pub extern "c" fn arc4random_buf(buf: [*]u8, len: usize) void;
1819

1920
pub extern "c" fn posix_memalign(memptr: *?*anyopaque, alignment: usize, size: usize) c_int;
2021
pub extern "c" fn malloc_usable_size(?*const anyopaque) usize;
2122

2223
pub extern "c" fn getpid() pid_t;
2324

25+
pub extern "c" fn kinfo_getfile(pid: pid_t, cntp: *c_int) ?[*]kinfo_file;
26+
2427
pub const sf_hdtr = extern struct {
2528
headers: [*]const iovec_const,
2629
hdr_cnt: c_int,

lib/std/c/netbsd.zig

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@ pub const KERN = struct {
537537
};
538538

539539
pub const PATH_MAX = 1024;
540+
pub const NAME_MAX = 255;
540541
pub const IOV_MAX = KERN.IOV_MAX;
541542

542543
pub const STDIN_FILENO = 0;
@@ -689,13 +690,17 @@ pub const F = struct {
689690
pub const SETFD = 2;
690691
pub const GETFL = 3;
691692
pub const SETFL = 4;
692-
693693
pub const GETOWN = 5;
694694
pub const SETOWN = 6;
695-
696695
pub const GETLK = 7;
697696
pub const SETLK = 8;
698697
pub const SETLKW = 9;
698+
pub const CLOSEM = 10;
699+
pub const MAXFD = 11;
700+
pub const DUPFD_CLOEXEC = 12;
701+
pub const GETNOSIGPIPE = 13;
702+
pub const SETNOSIGPIPE = 14;
703+
pub const GETPATH = 15;
699704

700705
pub const RDLCK = 1;
701706
pub const WRLCK = 3;

lib/std/c/openbsd.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ pub const AI = struct {
417417
};
418418

419419
pub const PATH_MAX = 1024;
420+
pub const NAME_MAX = 255;
420421
pub const IOV_MAX = 1024;
421422

422423
pub const STDIN_FILENO = 0;

0 commit comments

Comments
 (0)