Skip to content

stage1 compiler for dragonfly os + ravenports #2381

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ set(ZIG_STD_FILES
"build/fmt.zig"
"c.zig"
"c/darwin.zig"
"c/dragonfly.zig"
"c/freebsd.zig"
"c/linux.zig"
"c/netbsd.zig"
Expand Down Expand Up @@ -607,6 +608,7 @@ set(ZIG_STD_FILES
"os.zig"
"os/bits.zig"
"os/bits/darwin.zig"
"os/bits/dragonfly.zig"
"os/bits/freebsd.zig"
"os/bits/linux.zig"
"os/bits/linux/arm64.zig"
Expand All @@ -616,6 +618,7 @@ set(ZIG_STD_FILES
"os/bits/wasi.zig"
"os/bits/windows.zig"
"os/darwin.zig"
"os/dragonfly.zig"
"os/freebsd.zig"
"os/linux.zig"
"os/linux/arm64.zig"
Expand Down
2 changes: 1 addition & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ fn configureStage2(b: *Builder, exe: var, ctx: Context) !void {
}
dependOnLib(b, exe, ctx.llvm);

if (exe.target.getOs() == .linux) {
if (exe.target.getOs() == .linux or exe.target.getOs() == .dragonfly) {
try addCxxKnownPath(b, ctx, exe, "libstdc++.a",
\\Unable to determine path to libstdc++.a
\\On Fedora, install libstdc++-static and try again.
Expand Down
40 changes: 33 additions & 7 deletions src/libc_installation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ static const char *zig_libc_keys[] = {
"sys_include_dir",
"crt_dir",
"static_crt_dir",
"shared_gcc_dir",
"msvc_lib_dir",
"kernel32_lib_dir",
};
Expand All @@ -36,6 +37,7 @@ static void zig_libc_init_empty(ZigLibCInstallation *libc) {
buf_init_from_str(&libc->sys_include_dir, "");
buf_init_from_str(&libc->crt_dir, "");
buf_init_from_str(&libc->static_crt_dir, "");
buf_init_from_str(&libc->shared_gcc_dir, "");
buf_init_from_str(&libc->msvc_lib_dir, "");
buf_init_from_str(&libc->kernel32_lib_dir, "");
}
Expand Down Expand Up @@ -77,8 +79,9 @@ Error zig_libc_parse(ZigLibCInstallation *libc, Buf *libc_file, const ZigTarget
match = match || zig_libc_match_key(name, value, found_keys, 1, &libc->sys_include_dir);
match = match || zig_libc_match_key(name, value, found_keys, 2, &libc->crt_dir);
match = match || zig_libc_match_key(name, value, found_keys, 3, &libc->static_crt_dir);
match = match || zig_libc_match_key(name, value, found_keys, 4, &libc->msvc_lib_dir);
match = match || zig_libc_match_key(name, value, found_keys, 5, &libc->kernel32_lib_dir);
match = match || zig_libc_match_key(name, value, found_keys, 4, &libc->shared_gcc_dir);
match = match || zig_libc_match_key(name, value, found_keys, 5, &libc->msvc_lib_dir);
match = match || zig_libc_match_key(name, value, found_keys, 6, &libc->kernel32_lib_dir);
}

for (size_t i = 0; i < zig_libc_keys_len; i += 1) {
Expand Down Expand Up @@ -122,6 +125,15 @@ Error zig_libc_parse(ZigLibCInstallation *libc, Buf *libc_file, const ZigTarget
}
}

if (buf_len(&libc->shared_gcc_dir) == 0) {
if (target->os == OsDragonFly) {
if (verbose) {
fprintf(stderr, "shared_gcc_dir may not be empty for %s\n", target_os_name(target->os));
}
return ErrorSemanticAnalyzeFail;
}
}

if (buf_len(&libc->msvc_lib_dir) == 0) {
if (target->os == OsWindows && !target_abi_is_gnu(target->abi)) {
if (verbose) {
Expand Down Expand Up @@ -318,17 +330,19 @@ Error zig_libc_cc_print_file_name(const char *o_file, Buf *out, bool want_dirnam

#undef CC_EXE

#if defined(ZIG_OS_WINDOWS) || defined(ZIG_OS_LINUX)
static Error zig_libc_find_native_crt_dir_posix(ZigLibCInstallation *self, bool verbose) {
return zig_libc_cc_print_file_name("crt1.o", &self->crt_dir, true, verbose);
}
#endif

#if defined(ZIG_OS_WINDOWS)
static Error zig_libc_find_native_static_crt_dir_posix(ZigLibCInstallation *self, bool verbose) {
return zig_libc_cc_print_file_name("crtbegin.o", &self->static_crt_dir, true, verbose);
}

static Error zig_libc_find_native_shared_gcc_dir_posix(ZigLibCInstallation *self, bool verbose) {
return zig_libc_cc_print_file_name("libgcc_s.so", &self->shared_gcc_dir, true, verbose);
}

#if defined(ZIG_OS_WINDOWS)
static Error zig_libc_find_native_include_dir_windows(ZigLibCInstallation *self, ZigWindowsSDK *sdk, bool verbose) {
Error err;
if ((err = os_get_win32_ucrt_include_path(sdk, &self->include_dir))) {
Expand Down Expand Up @@ -411,6 +425,7 @@ void zig_libc_render(ZigLibCInstallation *self, FILE *file) {
"# The directory that contains `stdlib.h`.\n"
"# On POSIX-like systems, include directories be found with: `cc -E -Wp,-v -xc /dev/null`\n"
"include_dir=%s\n"
"\n"
"# The system-specific include directory. May be the same as `include_dir`.\n"
"# On Windows it's the directory that includes `vcruntime.h`.\n"
"# On POSIX it's the directory that includes `sys/errno.h`.\n"
Expand All @@ -426,19 +441,23 @@ void zig_libc_render(ZigLibCInstallation *self, FILE *file) {
"# Not needed when targeting MacOS.\n"
"static_crt_dir=%s\n"
"\n"
"# The directory that contains `libgcc_s.so`.\n"
"# Only needed when targeting DragonFly.\n"
"shared_gcc_dir=%s\n"
"\n"
"# The directory that contains `vcruntime.lib`.\n"
"# Only needed when targeting MSVC on Windows.\n"
"msvc_lib_dir=%s\n"
"\n"
"# The directory that contains `kernel32.lib`.\n"
"# Only needed when targeting MSVC on Windows.\n"
"kernel32_lib_dir=%s\n"
"\n"
,
"\n",
buf_ptr(&self->include_dir),
buf_ptr(&self->sys_include_dir),
buf_ptr(&self->crt_dir),
buf_ptr(&self->static_crt_dir),
buf_ptr(&self->shared_gcc_dir),
buf_ptr(&self->msvc_lib_dir),
buf_ptr(&self->kernel32_lib_dir)
);
Expand Down Expand Up @@ -487,6 +506,13 @@ Error zig_libc_find_native(ZigLibCInstallation *self, bool verbose) {
return err;
#if defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD)
buf_init_from_str(&self->crt_dir, "/usr/lib");
#elif defined(ZIG_OS_DRAGONFLY)
if ((err = zig_libc_find_native_crt_dir_posix(self, verbose)))
return err;
if ((err = zig_libc_find_native_static_crt_dir_posix(self, verbose)))
return err;
if ((err = zig_libc_find_native_shared_gcc_dir_posix(self, verbose)))
return err;
#elif defined(ZIG_OS_LINUX)
if ((err = zig_libc_find_native_crt_dir_posix(self, verbose)))
return err;
Expand Down
1 change: 1 addition & 0 deletions src/libc_installation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct ZigLibCInstallation {
Buf sys_include_dir;
Buf crt_dir;
Buf static_crt_dir;
Buf shared_gcc_dir;
Buf msvc_lib_dir;
Buf kernel32_lib_dir;
};
Expand Down
6 changes: 6 additions & 0 deletions src/link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,12 @@ static void construct_linker_job_elf(LinkJob *lj) {
lj->args.append("-lm");
lj->args.append("--end-group");
} else {
if(g->zig_target->os == OsDragonFly) {
lj->args.append("-L");
lj->args.append(buf_ptr(&g->libc->static_crt_dir));
lj->args.append("-L");
lj->args.append(buf_ptr(&g->libc->shared_gcc_dir));
}
lj->args.append("-lgcc");
lj->args.append("--as-needed");
lj->args.append("-lgcc_s");
Expand Down
12 changes: 6 additions & 6 deletions src/os.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ typedef SSIZE_T ssize_t;

#endif

#if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD)
#if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD) || defined(ZIG_OS_DRAGONFLY)
#include <link.h>
#endif

#if defined(ZIG_OS_LINUX)
#include <sys/auxv.h>
#endif

#if defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD)
#if defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD) || defined(ZIG_OS_DRAGONFLY)
#include <sys/sysctl.h>
#endif

Expand All @@ -84,7 +84,7 @@ static clock_serv_t macos_monotonic_clock;
#if defined(__APPLE__) && !defined(environ)
#include <crt_externs.h>
#define environ (*_NSGetEnviron())
#elif defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD)
#elif defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD) || defined(ZIG_OS_DRAGONFLY)
extern char **environ;
#endif

Expand Down Expand Up @@ -1428,7 +1428,7 @@ Error os_self_exe_path(Buf *out_path) {
}
buf_resize(out_path, amt);
return ErrorNone;
#elif defined(ZIG_OS_FREEBSD)
#elif defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_DRAGONFLY)
buf_resize(out_path, PATH_MAX);
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
size_t cb = PATH_MAX;
Expand Down Expand Up @@ -1770,7 +1770,7 @@ Error os_get_app_data_dir(Buf *out_path, const char *appname) {
}


#if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD)
#if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD) || defined(ZIG_OS_DRAGONFLY)
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] == '/') {
Expand All @@ -1781,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) || defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD)
#if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD) || defined(ZIG_OS_DRAGONFLY)
paths.resize(0);
dl_iterate_phdr(self_exe_shared_libs_callback, &paths);
return ErrorNone;
Expand Down
2 changes: 2 additions & 0 deletions src/os.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#define ZIG_OS_FREEBSD
#elif defined(__NetBSD__)
#define ZIG_OS_NETBSD
#elif defined(__DragonFly__)
#define ZIG_OS_DRAGONFLY
#else
#define ZIG_OS_UNKNOWN
#endif
Expand Down
9 changes: 5 additions & 4 deletions src/target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,7 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {
case OsZen:
case OsFreeBSD:
case OsNetBSD:
case OsDragonFly:
case OsOpenBSD:
case OsWASI:
switch (id) {
Expand Down Expand Up @@ -912,7 +913,6 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {
}
case OsAnanas:
case OsCloudABI:
case OsDragonFly:
case OsKFreeBSD:
case OsLv2:
case OsSolaris:
Expand Down Expand Up @@ -1033,6 +1033,8 @@ const char *target_dynamic_linker(const ZigTarget *target) {
return "/libexec/ld-elf.so.1";
case OsNetBSD:
return "/libexec/ld.elf_so";
case OsDragonFly:
return "/libexec/ld-elf.so.2";
case OsLinux: {
const ZigLLVM_EnvironmentType abi = target->abi;
if (abi == ZigLLVM_Android) {
Expand Down Expand Up @@ -1153,7 +1155,6 @@ const char *target_dynamic_linker(const ZigTarget *target) {

case OsAnanas:
case OsCloudABI:
case OsDragonFly:
case OsFuchsia:
case OsKFreeBSD:
case OsLv2:
Expand Down Expand Up @@ -1347,7 +1348,7 @@ bool target_os_requires_libc(Os os) {
// On Darwin, we always link libSystem which contains libc.
// Similarly on FreeBSD and NetBSD we always link system libc
// since this is the stable syscall interface.
return (target_os_is_darwin(os) || os == OsFreeBSD || os == OsNetBSD);
return (target_os_is_darwin(os) || os == OsFreeBSD || os == OsNetBSD || os == OsDragonFly);
}

bool target_supports_fpic(const ZigTarget *target) {
Expand Down Expand Up @@ -1390,7 +1391,6 @@ ZigLLVM_EnvironmentType target_default_abi(ZigLLVM_ArchType arch, Os os) {
case OsFreestanding:
case OsAnanas:
case OsCloudABI:
case OsDragonFly:
case OsLv2:
case OsSolaris:
case OsHaiku:
Expand Down Expand Up @@ -1419,6 +1419,7 @@ ZigLLVM_EnvironmentType target_default_abi(ZigLLVM_ArchType arch, Os os) {
case OsFuchsia:
case OsKFreeBSD:
case OsNetBSD:
case OsDragonFly:
case OsHurd:
return ZigLLVM_GNU;
case OsWindows:
Expand Down
3 changes: 3 additions & 0 deletions std/atomic/queue.zig
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ const puts_per_thread = 500;
const put_thread_count = 3;

test "std.atomic.Queue" {
if (builtin.os == .dragonfly) {
return error.SkipZigTest;
}
var direct_allocator = std.heap.DirectAllocator.init();
defer direct_allocator.deinit();

Expand Down
3 changes: 3 additions & 0 deletions std/atomic/stack.zig
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ const puts_per_thread = 500;
const put_thread_count = 3;

test "std.atomic.stack" {
if (builtin.os == .dragonfly) {
return error.SkipZigTest;
}
var direct_allocator = std.heap.DirectAllocator.init();
defer direct_allocator.deinit();

Expand Down
7 changes: 7 additions & 0 deletions std/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,13 @@ pub const Target = union(enum) {
};
}

pub fn isDragonFly(self: Target) bool {
return switch (self.getOs()) {
.dragonfly => true,
else => false,
};
}

pub fn wantSharedLibSymLinks(self: Target) bool {
return !self.isWindows();
}
Expand Down
1 change: 1 addition & 0 deletions std/c.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub usingnamespace switch (builtin.os) {
.macosx, .ios, .tvos, .watchos => @import("c/darwin.zig"),
.freebsd => @import("c/freebsd.zig"),
.netbsd => @import("c/netbsd.zig"),
.dragonfly => @import("c/dragonfly.zig"),
else => struct {},
};

Expand Down
Loading