Skip to content

Commit d8b6fa9

Browse files
authored
Merge pull request #1859 from mgxm/fbsd2
Progress towards tier 1 support for FreeBSD x86_64
2 parents c464ecf + 2e08bd6 commit d8b6fa9

14 files changed

+274
-757
lines changed

.builds/freebsd.yml

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
arch: x86_64
2-
image: freebsd
1+
image: freebsd/latest
32
packages:
43
- cmake
54
- ninja
@@ -14,6 +13,28 @@ tasks:
1413
- test: |
1514
cd zig/build
1615
bin/zig test ../test/behavior.zig
16+
bin/zig test ../std/special/compiler_rt/index.zig
17+
18+
bin/zig test ../test/behavior.zig --library c
19+
bin/zig test ../std/special/compiler_rt/index.zig --library c
20+
21+
bin/zig test ../test/behavior.zig --release-fast
22+
bin/zig test ../std/special/compiler_rt/index.zig --release-fast
23+
24+
bin/zig test ../test/behavior.zig --release-fast --library c
25+
bin/zig test ../std/special/compiler_rt/index.zig --release-fast --library c
26+
27+
bin/zig test ../test/behavior.zig --release-small --library c
28+
bin/zig test ../std/special/compiler_rt/index.zig --release-small --library c
29+
30+
bin/zig test ../test/behavior.zig --release-small
31+
bin/zig test ../std/special/compiler_rt/index.zig --release-small
32+
33+
bin/zig test ../test/behavior.zig --release-safe
34+
bin/zig test ../std/special/compiler_rt/index.zig --release-safe
35+
36+
bin/zig test ../test/behavior.zig --release-safe --library c
37+
bin/zig test ../std/special/compiler_rt/index.zig --release-safe --library c
1738
# TODO enable all tests
1839
#bin/zig build --build-file ../build.zig test
1940
# TODO integrate with the download page updater and make a

CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -586,8 +586,6 @@ set(ZIG_STD_FILES
586586
"os/linux/arm64.zig"
587587
"os/freebsd/errno.zig"
588588
"os/freebsd/index.zig"
589-
"os/freebsd/syscall.zig"
590-
"os/freebsd/x86_64.zig"
591589
"os/path.zig"
592590
"os/time.zig"
593591
"os/uefi.zig"

build.zig

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,11 +293,14 @@ fn configureStage2(b: *Builder, exe: var, ctx: Context) !void {
293293
try addCxxKnownPath(b, ctx, exe, "libstdc++.a",
294294
\\Unable to determine path to libstdc++.a
295295
\\On Fedora, install libstdc++-static and try again.
296-
\\
297296
);
298297

299298
exe.linkSystemLibrary("pthread");
300-
} else if (exe.target.isDarwin() or exe.target.isFreeBSD()) {
299+
} else if (exe.target.isFreeBSD()) {
300+
try addCxxKnownPath(b, ctx, exe, "libc++.a", null);
301+
exe.linkSystemLibrary("pthread");
302+
}
303+
else if (exe.target.isDarwin()) {
301304
if (addCxxKnownPath(b, ctx, exe, "libgcc_eh.a", "")) {
302305
// Compiler is GCC.
303306
try addCxxKnownPath(b, ctx, exe, "libstdc++.a", null);

src/analyze.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6374,7 +6374,7 @@ LinkLib *add_link_lib(CodeGen *g, Buf *name) {
63746374
if (is_libc && g->libc_link_lib != nullptr)
63756375
return g->libc_link_lib;
63766376

6377-
if (g->enable_cache && is_libc && g->zig_target.os != OsMacOSX && g->zig_target.os != OsIOS) {
6377+
if (g->enable_cache && is_libc && g->zig_target.os != OsMacOSX && g->zig_target.os != OsIOS && g->zig_target.os != OsFreeBSD) {
63786378
fprintf(stderr, "TODO linking against libc is currently incompatible with `--cache on`.\n"
63796379
"Zig is not yet capable of determining whether the libc installation has changed on subsequent builds.\n");
63806380
exit(1);

src/codegen.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out
178178

179179
// On Darwin/MacOS/iOS, we always link libSystem which contains libc.
180180
if (g->zig_target.os == OsMacOSX ||
181-
g->zig_target.os == OsIOS)
181+
g->zig_target.os == OsIOS ||
182+
g->zig_target.os == OsFreeBSD)
182183
{
183184
g->libc_link_lib = create_link_lib(buf_create_from_str("c"));
184185
g->link_libs_list.append(g->libc_link_lib);

std/c/freebsd.zig

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const timespec = @import("../os/freebsd/index.zig").timespec;
2-
31
extern "c" fn __error() *c_int;
42
pub const _errno = __error;
53

@@ -15,6 +13,15 @@ pub extern "c" fn kevent(
1513
pub extern "c" fn sysctl(name: [*]c_int, namelen: c_uint, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int;
1614
pub extern "c" fn sysctlbyname(name: [*]const u8, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int;
1715
pub extern "c" fn sysctlnametomib(name: [*]const u8, mibp: ?*c_int, sizep: ?*usize) c_int;
16+
pub extern "c" fn getdirentries(fd: c_int, buf_ptr: [*]u8, nbytes: usize, basep: *i64) usize;
17+
pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) usize;
18+
pub extern "c" fn pipe2(arg0: *[2]c_int, arg1: u32) c_int;
19+
pub extern "c" fn preadv(fd: c_int, iov: *const c_void, iovcnt: c_int, offset: usize) isize;
20+
pub extern "c" fn pwritev(fd: c_int, iov: *const c_void, iovcnt: c_int, offset: usize) isize;
21+
pub extern "c" fn openat(fd: c_int, path: ?[*]const u8, flags: c_int) c_int;
22+
pub extern "c" fn setgid(ruid: c_uint, euid: c_uint) c_int;
23+
pub extern "c" fn setuid(uid: c_uint) c_int;
24+
pub extern "c" fn kill(pid: c_int, sig: c_int) c_int;
1825

1926
/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.
2027
pub const Kevent = extern struct {
@@ -31,3 +38,56 @@ pub const pthread_attr_t = extern struct {
3138
__size: [56]u8,
3239
__align: c_long,
3340
};
41+
42+
pub const msghdr = extern struct {
43+
msg_name: *u8,
44+
msg_namelen: socklen_t,
45+
msg_iov: *iovec,
46+
msg_iovlen: i32,
47+
__pad1: i32,
48+
msg_control: *u8,
49+
msg_controllen: socklen_t,
50+
__pad2: socklen_t,
51+
msg_flags: i32,
52+
};
53+
54+
pub const Stat = extern struct {
55+
dev: u64,
56+
ino: u64,
57+
nlink: usize,
58+
59+
mode: u16,
60+
__pad0: u16,
61+
uid: u32,
62+
gid: u32,
63+
__pad1: u32,
64+
rdev: u64,
65+
66+
atim: timespec,
67+
mtim: timespec,
68+
ctim: timespec,
69+
birthtim: timespec,
70+
71+
size: i64,
72+
blocks: i64,
73+
blksize: isize,
74+
flags: u32,
75+
gen: u64,
76+
__spare: [10]u64,
77+
};
78+
79+
pub const timespec = extern struct {
80+
tv_sec: isize,
81+
tv_nsec: isize,
82+
};
83+
84+
pub const dirent = extern struct {
85+
d_fileno: usize,
86+
d_off: i64,
87+
d_reclen: u16,
88+
d_type: u8,
89+
d_pad0: u8,
90+
d_namlen: u16,
91+
d_pad1: u16,
92+
d_name: [256]u8,
93+
};

std/debug/index.zig

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ pub fn writeCurrentStackTraceWindows(
264264
pub fn printSourceAtAddress(debug_info: *DebugInfo, out_stream: var, address: usize, tty_color: bool) !void {
265265
switch (builtin.os) {
266266
builtin.Os.macosx => return printSourceAtAddressMacOs(debug_info, out_stream, address, tty_color),
267-
builtin.Os.linux => return printSourceAtAddressLinux(debug_info, out_stream, address, tty_color),
267+
builtin.Os.linux, builtin.Os.freebsd => return printSourceAtAddressLinux(debug_info, out_stream, address, tty_color),
268268
builtin.Os.windows => return printSourceAtAddressWindows(debug_info, out_stream, address, tty_color),
269269
else => return error.UnsupportedOperatingSystem,
270270
}
@@ -717,7 +717,7 @@ pub const OpenSelfDebugInfoError = error{
717717

718718
pub fn openSelfDebugInfo(allocator: *mem.Allocator) !DebugInfo {
719719
switch (builtin.os) {
720-
builtin.Os.linux => return openSelfDebugInfoLinux(allocator),
720+
builtin.Os.linux, builtin.Os.freebsd => return openSelfDebugInfoLinux(allocator),
721721
builtin.Os.macosx, builtin.Os.ios => return openSelfDebugInfoMacOs(allocator),
722722
builtin.Os.windows => return openSelfDebugInfoWindows(allocator),
723723
else => return error.UnsupportedOperatingSystem,
@@ -1141,8 +1141,7 @@ pub const DebugInfo = switch (builtin.os) {
11411141
sect_contribs: []pdb.SectionContribEntry,
11421142
modules: []Module,
11431143
},
1144-
builtin.Os.linux => DwarfInfo,
1145-
builtin.Os.freebsd => struct {},
1144+
builtin.Os.linux, builtin.Os.freebsd => DwarfInfo,
11461145
else => @compileError("Unsupported OS"),
11471146
};
11481147

0 commit comments

Comments
 (0)