Merge branch 'freebsd-up' of https://github.com/myfreeweb/zig into freebsd2
This commit is contained in:
@@ -4579,7 +4579,10 @@ void find_libc_include_path(CodeGen *g) {
|
||||
fprintf(stderr, "Unable to determine libc include path. --libc-include-dir");
|
||||
exit(1);
|
||||
}
|
||||
} else if (g->zig_target.os == OsLinux || g->zig_target.os == OsMacOSX) {
|
||||
} else if (g->zig_target.os == OsLinux ||
|
||||
g->zig_target.os == OsMacOSX ||
|
||||
g->zig_target.os == OsFreeBSD)
|
||||
{
|
||||
g->libc_include_dir = get_posix_libc_include_path();
|
||||
} else {
|
||||
fprintf(stderr, "Unable to determine libc include path.\n"
|
||||
@@ -4627,6 +4630,8 @@ void find_libc_lib_path(CodeGen *g) {
|
||||
|
||||
} else if (g->zig_target.os == OsLinux) {
|
||||
g->libc_lib_dir = get_linux_libc_lib_path("crt1.o");
|
||||
} else if (g->zig_target.os == OsFreeBSD) {
|
||||
g->libc_lib_dir = buf_create_from_str("/usr/lib");
|
||||
} else {
|
||||
zig_panic("Unable to determine libc lib path.");
|
||||
}
|
||||
@@ -4639,6 +4644,8 @@ void find_libc_lib_path(CodeGen *g) {
|
||||
return;
|
||||
} else if (g->zig_target.os == OsLinux) {
|
||||
g->libc_static_lib_dir = get_linux_libc_lib_path("crtbegin.o");
|
||||
} else if (g->zig_target.os == OsFreeBSD) {
|
||||
g->libc_static_lib_dir = buf_create_from_str("/usr/lib");
|
||||
} else {
|
||||
zig_panic("Unable to determine libc static lib path.");
|
||||
}
|
||||
|
||||
@@ -150,6 +150,10 @@ static const char *getLDMOption(const ZigTarget *t) {
|
||||
if (t->env_type == ZigLLVM_GNUX32) {
|
||||
return "elf32_x86_64";
|
||||
}
|
||||
// Any target elf will use the freebsd osabi if suffixed with "_fbsd".
|
||||
if (t->os == OsFreeBSD) {
|
||||
return "elf_x86_64_fbsd";
|
||||
}
|
||||
return "elf_x86_64";
|
||||
default:
|
||||
zig_unreachable();
|
||||
@@ -191,6 +195,9 @@ static Buf *try_dynamic_linker_path(const char *ld_name) {
|
||||
}
|
||||
|
||||
static Buf *get_dynamic_linker_path(CodeGen *g) {
|
||||
if (g->zig_target.os == OsFreeBSD) {
|
||||
return buf_create_from_str("/libexec/ld-elf.so.1");
|
||||
}
|
||||
if (g->is_native_target && g->zig_target.arch.arch == ZigLLVM_x86_64) {
|
||||
static const char *ld_names[] = {
|
||||
"ld-linux-x86-64.so.2",
|
||||
|
||||
26
src/os.cpp
26
src/os.cpp
@@ -50,10 +50,13 @@ typedef SSIZE_T ssize_t;
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(ZIG_OS_LINUX)
|
||||
#if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD)
|
||||
#include <link.h>
|
||||
#endif
|
||||
|
||||
#if defined(ZIG_OS_FREEBSD)
|
||||
#include <sys/sysctl.h>
|
||||
#endif
|
||||
|
||||
#if defined(__MACH__)
|
||||
#include <mach/clock.h>
|
||||
@@ -75,7 +78,9 @@ static clock_serv_t cclock;
|
||||
#if defined(__APPLE__) && !defined(environ)
|
||||
#include <crt_externs.h>
|
||||
#define environ (*_NSGetEnviron())
|
||||
#endif
|
||||
#elif defined(ZIG_OS_FREEBSD)
|
||||
extern char **environ;
|
||||
#endif
|
||||
|
||||
#if defined(ZIG_OS_POSIX)
|
||||
static void populate_termination(Termination *term, int status) {
|
||||
@@ -1438,6 +1443,15 @@ Error os_self_exe_path(Buf *out_path) {
|
||||
}
|
||||
buf_resize(out_path, amt);
|
||||
return ErrorNone;
|
||||
#elif defined(ZIG_OS_FREEBSD)
|
||||
buf_resize(out_path, PATH_MAX);
|
||||
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
|
||||
size_t cb = PATH_MAX;
|
||||
if (sysctl(mib, 4, buf_ptr(out_path), &cb, nullptr, 0) != 0) {
|
||||
return ErrorUnexpected;
|
||||
}
|
||||
buf_resize(out_path, cb);
|
||||
return ErrorNone;
|
||||
#endif
|
||||
return ErrorFileNotFound;
|
||||
}
|
||||
@@ -1743,7 +1757,7 @@ Error os_get_app_data_dir(Buf *out_path, const char *appname) {
|
||||
buf_resize(out_path, 0);
|
||||
buf_appendf(out_path, "%s/Library/Application Support/%s", home_dir, appname);
|
||||
return ErrorNone;
|
||||
#elif defined(ZIG_OS_LINUX)
|
||||
#elif defined(ZIG_OS_POSIX)
|
||||
const char *home_dir = getenv("HOME");
|
||||
if (home_dir == nullptr) {
|
||||
// TODO use /etc/passwd
|
||||
@@ -1756,7 +1770,7 @@ Error os_get_app_data_dir(Buf *out_path, const char *appname) {
|
||||
}
|
||||
|
||||
|
||||
#if defined(ZIG_OS_LINUX)
|
||||
#if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD)
|
||||
static int self_exe_shared_libs_callback(struct dl_phdr_info *info, size_t size, void *data) {
|
||||
ZigList<Buf *> *libs = reinterpret_cast< ZigList<Buf *> *>(data);
|
||||
if (info->dlpi_name[0] == '/') {
|
||||
@@ -1767,7 +1781,7 @@ static int self_exe_shared_libs_callback(struct dl_phdr_info *info, size_t size,
|
||||
#endif
|
||||
|
||||
Error os_self_exe_shared_libs(ZigList<Buf *> &paths) {
|
||||
#if defined(ZIG_OS_LINUX)
|
||||
#if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD)
|
||||
paths.resize(0);
|
||||
dl_iterate_phdr(self_exe_shared_libs_callback, &paths);
|
||||
return ErrorNone;
|
||||
@@ -1936,7 +1950,7 @@ Error os_file_mtime(OsFile file, OsTimeStamp *mtime) {
|
||||
mtime->sec = (((ULONGLONG) last_write_time.dwHighDateTime) << 32) + last_write_time.dwLowDateTime;
|
||||
mtime->nsec = 0;
|
||||
return ErrorNone;
|
||||
#elif defined(ZIG_OS_LINUX)
|
||||
#elif defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD)
|
||||
struct stat statbuf;
|
||||
if (fstat(file, &statbuf) == -1)
|
||||
return ErrorFileSystem;
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
#define ZIG_OS_WINDOWS
|
||||
#elif defined(__linux__)
|
||||
#define ZIG_OS_LINUX
|
||||
#elif defined(__FreeBSD__)
|
||||
#define ZIG_OS_FREEBSD
|
||||
#else
|
||||
#define ZIG_OS_UNKNOWN
|
||||
#endif
|
||||
|
||||
@@ -738,6 +738,7 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {
|
||||
case OsLinux:
|
||||
case OsMacOSX:
|
||||
case OsZen:
|
||||
case OsFreeBSD:
|
||||
case OsOpenBSD:
|
||||
switch (id) {
|
||||
case CIntTypeShort:
|
||||
@@ -774,7 +775,6 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {
|
||||
case OsAnanas:
|
||||
case OsCloudABI:
|
||||
case OsDragonFly:
|
||||
case OsFreeBSD:
|
||||
case OsIOS:
|
||||
case OsKFreeBSD:
|
||||
case OsLv2:
|
||||
|
||||
@@ -47,7 +47,7 @@ bool ptr_eq(const void *a, const void *b) {
|
||||
// Ported from std/mem.zig.
|
||||
bool SplitIterator_isSplitByte(SplitIterator *self, uint8_t byte) {
|
||||
for (size_t i = 0; i < self->split_bytes.len; i += 1) {
|
||||
if (byte == self->split_bytes.ptr[i]) {
|
||||
if (byte == self->split_bytes.ptr[i] || byte == 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user