Skip to content

Commit

Permalink
Merge pull request #1859 from mgxm/fbsd2
Browse files Browse the repository at this point in the history
Progress towards tier 1 support for FreeBSD x86_64
  • Loading branch information
andrewrk authored Dec 29, 2018
2 parents c464ecf + 2e08bd6 commit d8b6fa9
Show file tree
Hide file tree
Showing 14 changed files with 274 additions and 757 deletions.
25 changes: 23 additions & 2 deletions .builds/freebsd.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
arch: x86_64
image: freebsd
image: freebsd/latest
packages:
- cmake
- ninja
Expand All @@ -14,6 +13,28 @@ tasks:
- test: |
cd zig/build
bin/zig test ../test/behavior.zig
bin/zig test ../std/special/compiler_rt/index.zig
bin/zig test ../test/behavior.zig --library c
bin/zig test ../std/special/compiler_rt/index.zig --library c
bin/zig test ../test/behavior.zig --release-fast
bin/zig test ../std/special/compiler_rt/index.zig --release-fast
bin/zig test ../test/behavior.zig --release-fast --library c
bin/zig test ../std/special/compiler_rt/index.zig --release-fast --library c
bin/zig test ../test/behavior.zig --release-small --library c
bin/zig test ../std/special/compiler_rt/index.zig --release-small --library c
bin/zig test ../test/behavior.zig --release-small
bin/zig test ../std/special/compiler_rt/index.zig --release-small
bin/zig test ../test/behavior.zig --release-safe
bin/zig test ../std/special/compiler_rt/index.zig --release-safe
bin/zig test ../test/behavior.zig --release-safe --library c
bin/zig test ../std/special/compiler_rt/index.zig --release-safe --library c
# TODO enable all tests
#bin/zig build --build-file ../build.zig test
# TODO integrate with the download page updater and make a
Expand Down
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -586,8 +586,6 @@ set(ZIG_STD_FILES
"os/linux/arm64.zig"
"os/freebsd/errno.zig"
"os/freebsd/index.zig"
"os/freebsd/syscall.zig"
"os/freebsd/x86_64.zig"
"os/path.zig"
"os/time.zig"
"os/uefi.zig"
Expand Down
7 changes: 5 additions & 2 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,14 @@ fn configureStage2(b: *Builder, exe: var, ctx: Context) !void {
try addCxxKnownPath(b, ctx, exe, "libstdc++.a",
\\Unable to determine path to libstdc++.a
\\On Fedora, install libstdc++-static and try again.
\\
);

exe.linkSystemLibrary("pthread");
} else if (exe.target.isDarwin() or exe.target.isFreeBSD()) {
} else if (exe.target.isFreeBSD()) {
try addCxxKnownPath(b, ctx, exe, "libc++.a", null);
exe.linkSystemLibrary("pthread");
}
else if (exe.target.isDarwin()) {
if (addCxxKnownPath(b, ctx, exe, "libgcc_eh.a", "")) {
// Compiler is GCC.
try addCxxKnownPath(b, ctx, exe, "libstdc++.a", null);
Expand Down
2 changes: 1 addition & 1 deletion src/analyze.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6374,7 +6374,7 @@ LinkLib *add_link_lib(CodeGen *g, Buf *name) {
if (is_libc && g->libc_link_lib != nullptr)
return g->libc_link_lib;

if (g->enable_cache && is_libc && g->zig_target.os != OsMacOSX && g->zig_target.os != OsIOS) {
if (g->enable_cache && is_libc && g->zig_target.os != OsMacOSX && g->zig_target.os != OsIOS && g->zig_target.os != OsFreeBSD) {
fprintf(stderr, "TODO linking against libc is currently incompatible with `--cache on`.\n"
"Zig is not yet capable of determining whether the libc installation has changed on subsequent builds.\n");
exit(1);
Expand Down
3 changes: 2 additions & 1 deletion src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out

// On Darwin/MacOS/iOS, we always link libSystem which contains libc.
if (g->zig_target.os == OsMacOSX ||
g->zig_target.os == OsIOS)
g->zig_target.os == OsIOS ||
g->zig_target.os == OsFreeBSD)
{
g->libc_link_lib = create_link_lib(buf_create_from_str("c"));
g->link_libs_list.append(g->libc_link_lib);
Expand Down
64 changes: 62 additions & 2 deletions std/c/freebsd.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const timespec = @import("../os/freebsd/index.zig").timespec;

extern "c" fn __error() *c_int;
pub const _errno = __error;

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

/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.
pub const Kevent = extern struct {
Expand All @@ -31,3 +38,56 @@ pub const pthread_attr_t = extern struct {
__size: [56]u8,
__align: c_long,
};

pub const msghdr = extern struct {
msg_name: *u8,
msg_namelen: socklen_t,
msg_iov: *iovec,
msg_iovlen: i32,
__pad1: i32,
msg_control: *u8,
msg_controllen: socklen_t,
__pad2: socklen_t,
msg_flags: i32,
};

pub const Stat = extern struct {
dev: u64,
ino: u64,
nlink: usize,

mode: u16,
__pad0: u16,
uid: u32,
gid: u32,
__pad1: u32,
rdev: u64,

atim: timespec,
mtim: timespec,
ctim: timespec,
birthtim: timespec,

size: i64,
blocks: i64,
blksize: isize,
flags: u32,
gen: u64,
__spare: [10]u64,
};

pub const timespec = extern struct {
tv_sec: isize,
tv_nsec: isize,
};

pub const dirent = extern struct {
d_fileno: usize,
d_off: i64,
d_reclen: u16,
d_type: u8,
d_pad0: u8,
d_namlen: u16,
d_pad1: u16,
d_name: [256]u8,
};
7 changes: 3 additions & 4 deletions std/debug/index.zig
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ pub fn writeCurrentStackTraceWindows(
pub fn printSourceAtAddress(debug_info: *DebugInfo, out_stream: var, address: usize, tty_color: bool) !void {
switch (builtin.os) {
builtin.Os.macosx => return printSourceAtAddressMacOs(debug_info, out_stream, address, tty_color),
builtin.Os.linux => return printSourceAtAddressLinux(debug_info, out_stream, address, tty_color),
builtin.Os.linux, builtin.Os.freebsd => return printSourceAtAddressLinux(debug_info, out_stream, address, tty_color),
builtin.Os.windows => return printSourceAtAddressWindows(debug_info, out_stream, address, tty_color),
else => return error.UnsupportedOperatingSystem,
}
Expand Down Expand Up @@ -717,7 +717,7 @@ pub const OpenSelfDebugInfoError = error{

pub fn openSelfDebugInfo(allocator: *mem.Allocator) !DebugInfo {
switch (builtin.os) {
builtin.Os.linux => return openSelfDebugInfoLinux(allocator),
builtin.Os.linux, builtin.Os.freebsd => return openSelfDebugInfoLinux(allocator),
builtin.Os.macosx, builtin.Os.ios => return openSelfDebugInfoMacOs(allocator),
builtin.Os.windows => return openSelfDebugInfoWindows(allocator),
else => return error.UnsupportedOperatingSystem,
Expand Down Expand Up @@ -1141,8 +1141,7 @@ pub const DebugInfo = switch (builtin.os) {
sect_contribs: []pdb.SectionContribEntry,
modules: []Module,
},
builtin.Os.linux => DwarfInfo,
builtin.Os.freebsd => struct {},
builtin.Os.linux, builtin.Os.freebsd => DwarfInfo,
else => @compileError("Unsupported OS"),
};

Expand Down
Loading

0 comments on commit d8b6fa9

Please sign in to comment.