From d9fe38789b2a4e8376b71d839181d9c28d098164 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 6 Nov 2018 17:21:47 -0500 Subject: [PATCH] macos: use the same code as linux to determine libc include path this fixes .h file locating on macos 10.14 --- src/analyze.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/analyze.cpp b/src/analyze.cpp index ac7f589d5..33958c090 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -4488,7 +4488,7 @@ static ZigWindowsSDK *get_windows_sdk(CodeGen *g) { } -Buf *get_linux_libc_lib_path(const char *o_file) { +static Buf *get_linux_libc_lib_path(const char *o_file) { const char *cc_exe = getenv("CC"); cc_exe = (cc_exe == nullptr) ? "cc" : cc_exe; ZigList args = {}; @@ -4514,7 +4514,7 @@ Buf *get_linux_libc_lib_path(const char *o_file) { return result; } -Buf *get_linux_libc_include_path(void) { +static Buf *get_posix_libc_include_path(void) { const char *cc_exe = getenv("CC"); cc_exe = (cc_exe == nullptr) ? "cc" : cc_exe; ZigList args = {}; @@ -4569,6 +4569,10 @@ Buf *get_linux_libc_include_path(void) { void find_libc_include_path(CodeGen *g) { if (g->libc_include_dir == nullptr) { + if (!g->is_native_target) { + fprintf(stderr, "Unable to determine libc include path. --libc-include-dir"); + exit(1); + } if (g->zig_target.os == OsWindows) { ZigWindowsSDK *sdk = get_windows_sdk(g); @@ -4577,13 +4581,13 @@ 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->libc_include_dir = get_linux_libc_include_path(); - } else if (g->zig_target.os == OsMacOSX) { - g->libc_include_dir = buf_create_from_str("/usr/include"); + } else if (g->zig_target.os == OsLinux || g->zig_target.os == OsMacOSX) { + g->libc_include_dir = get_posix_libc_include_path(); } else { - // TODO find libc at runtime for other operating systems - zig_panic("Unable to determine libc include path."); + fprintf(stderr, "Unable to determine libc include path.\n" + "TODO: implement finding libc at runtime for other operating systems.\n" + "in the meantime, you can use as a workaround: --libc-include-dir\n"); + exit(1); } } assert(buf_len(g->libc_include_dir) != 0);