diff --git a/CMakeLists.txt b/CMakeLists.txt index 47eb8e2c8836148927f780c0c7331797e4ad3ee1..1feb0fc95412df800bd48cdf377e6c5e73fc02cc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,7 @@ set(ZIG_LIBC_LIB_DIR "" CACHE STRING "Default native target libc directory where set(ZIG_LIBC_STATIC_LIB_DIR "" CACHE STRING "Default native target libc directory where crtbeginT.o can be found") set(ZIG_LIBC_INCLUDE_DIR "/usr/include" CACHE STRING "Default native target libc include directory") set(ZIG_LD_PATH "ld" CACHE STRING "Path to ld for the native target") +set(ZIG_AR_PATH "ar" CACHE STRING "Path to ar for the native target") set(ZIG_DYNAMIC_LINKER "" CACHE STRING "Override dynamic linker for native target") option(ZIG_TEST_COVERAGE "Build Zig with test coverage instrumentation" OFF) @@ -217,6 +218,7 @@ install(FILES "${CMAKE_SOURCE_DIR}/std/linux_i386.zig" DESTINATION "${ZIG_STD_DE install(FILES "${CMAKE_SOURCE_DIR}/std/mem.zig" DESTINATION "${ZIG_STD_DEST}") install(FILES "${CMAKE_SOURCE_DIR}/std/list.zig" DESTINATION "${ZIG_STD_DEST}") install(FILES "${CMAKE_SOURCE_DIR}/std/hash_map.zig" DESTINATION "${ZIG_STD_DEST}") +install(FILES "${CMAKE_SOURCE_DIR}/std/empty.zig" DESTINATION "${ZIG_STD_DEST}") add_executable(run_tests ${TEST_SOURCES}) target_link_libraries(run_tests) diff --git a/src/all_types.hpp b/src/all_types.hpp index b44bbb7e6d0dac7d66fe03bb1ba5da202c250562..c386587a682cd0380e8516cb91b2dfce7bc6410b 100644 --- a/src/all_types.hpp +++ b/src/all_types.hpp @@ -1214,6 +1214,7 @@ struct CodeGen { Buf *libc_include_dir; Buf *dynamic_linker; Buf *linker_path; + Buf *ar_path; Buf triple_str; bool is_release_build; bool is_test_build; diff --git a/src/codegen.cpp b/src/codegen.cpp index 3b38387b0ae7c03b5c01bf8c7eec77bb9a41b74c..dc66680ecfb4df7d25b6be8cba0b739f54d0481f 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -85,6 +85,7 @@ CodeGen *codegen_create(Buf *root_source_dir, const ZigTarget *target) { g->libc_static_lib_dir = buf_create_from_str(""); g->libc_include_dir = buf_create_from_str(""); g->linker_path = buf_create_from_str(""); + g->ar_path = buf_create_from_str(""); g->darwin_linker_version = buf_create_from_str(""); } else { // native compilation, we can rely on the configuration stuff @@ -96,6 +97,7 @@ CodeGen *codegen_create(Buf *root_source_dir, const ZigTarget *target) { g->libc_static_lib_dir = buf_create_from_str(ZIG_LIBC_STATIC_LIB_DIR); g->libc_include_dir = buf_create_from_str(ZIG_LIBC_INCLUDE_DIR); g->linker_path = buf_create_from_str(ZIG_LD_PATH); + g->ar_path = buf_create_from_str(ZIG_AR_PATH); g->darwin_linker_version = buf_create_from_str(ZIG_HOST_LINK_VERSION); if (g->zig_target.os == ZigLLVM_Darwin || @@ -171,6 +173,10 @@ void codegen_set_linker_path(CodeGen *g, Buf *linker_path) { g->linker_path = linker_path; } +void codegen_set_ar_path(CodeGen *g, Buf *ar_path) { + g->ar_path = ar_path; +} + void codegen_add_lib_dir(CodeGen *g, const char *dir) { g->lib_dirs.append(dir); } diff --git a/src/codegen.hpp b/src/codegen.hpp index dba52b8bfbbb0091217492fb5b8239d1f963bf51..509f78aaa8187680186fc69415f9c4f03c53eb6f 100644 --- a/src/codegen.hpp +++ b/src/codegen.hpp @@ -32,6 +32,7 @@ void codegen_set_libc_static_lib_dir(CodeGen *g, Buf *libc_static_lib_dir); void codegen_set_libc_include_dir(CodeGen *codegen, Buf *libc_include_dir); void codegen_set_dynamic_linker(CodeGen *g, Buf *dynamic_linker); void codegen_set_linker_path(CodeGen *g, Buf *linker_path); +void codegen_set_ar_path(CodeGen *g, Buf *ar_path); void codegen_set_windows_subsystem(CodeGen *g, bool mwindows, bool mconsole); void codegen_set_windows_unicode(CodeGen *g, bool municode); void codegen_add_lib_dir(CodeGen *codegen, const char *dir); diff --git a/src/config.h.in b/src/config.h.in index 1985a53e2bf5222a8c5771b790e10ba34a11afab..3ad0dadf1b7e3616d1f33132a69e10929b7f68a6 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -12,6 +12,7 @@ #define ZIG_LIBC_LIB_DIR "@ZIG_LIBC_LIB_DIR@" #define ZIG_LIBC_STATIC_LIB_DIR "@ZIG_LIBC_STATIC_LIB_DIR@" #define ZIG_LD_PATH "@ZIG_LD_PATH@" +#define ZIG_AR_PATH "@ZIG_AR_PATH@" #define ZIG_DYNAMIC_LINKER "@ZIG_DYNAMIC_LINKER@" #define ZIG_HOST_LINK_VERSION "@ZIG_HOST_LINK_VERSION@" diff --git a/src/link.cpp b/src/link.cpp index a2fab503738fb8cf7eef80948c90e37f62f91b06..d0e8a1bf39aa75495b3db847eaa8816f462bf4a9 100644 --- a/src/link.cpp +++ b/src/link.cpp @@ -152,6 +152,7 @@ static void construct_linker_job_linux(LinkJob *lj) { find_libc_lib_path(g); } + lj->args.append("--gc-sections"); lj->args.append("-m"); lj->args.append(getLDMOption(&g->zig_target)); diff --git a/src/main.cpp b/src/main.cpp index 798ef5af52dbb92b5cb5901bc1e83b0a43ec8ab4..009b22858ed98056ef75976963ecef0734ee7e89 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -37,6 +37,7 @@ static int usage(const char *arg0) { " --libc-include-dir [path] directory where libc stdlib.h resides\n" " --dynamic-linker [path] set the path to ld.so\n" " --ld-path [path] set the path to the linker\n" + " --ar-path [path] set the path to ar\n" " -isystem [dir] add additional search path for other .h files\n" " -dirafter [dir] same as -isystem but do it last\n" " --library-path [dir] add a directory to the library search path\n" @@ -118,6 +119,7 @@ int main(int argc, char **argv) { const char *libc_include_dir = nullptr; const char *dynamic_linker = nullptr; const char *linker_path = nullptr; + const char *ar_path = nullptr; ZigList clang_argv = {0}; ZigList lib_dirs = {0}; ZigList link_libs = {0}; @@ -196,6 +198,8 @@ int main(int argc, char **argv) { dynamic_linker = argv[i]; } else if (strcmp(arg, "--ld-path") == 0) { linker_path = argv[i]; + } else if (strcmp(arg, "--ar-path") == 0) { + ar_path = argv[i]; } else if (strcmp(arg, "-isystem") == 0) { clang_argv.append("-isystem"); clang_argv.append(argv[i]); @@ -356,6 +360,8 @@ int main(int argc, char **argv) { codegen_set_dynamic_linker(g, buf_create_from_str(dynamic_linker)); if (linker_path) codegen_set_linker_path(g, buf_create_from_str(linker_path)); + if (ar_path) + codegen_set_ar_path(g, buf_create_from_str(ar_path)); codegen_set_verbose(g, verbose); codegen_set_errmsg_color(g, color); diff --git a/std/empty.zig b/std/empty.zig new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/std/index.zig b/std/index.zig index 90c82519d5cf10ca03312268383648d79eee59d0..5f2ac7fd8c7cc1090e56500776194f30b5b02857 100644 --- a/std/index.zig +++ b/std/index.zig @@ -8,7 +8,13 @@ pub const net = @import("net.zig"); pub const list = @import("list.zig"); pub const hash_map = @import("hash_map.zig"); pub const mem = @import("mem.zig"); +pub const linux = switch(@compile_var("os")) { + linux => @import("linux.zig"), + else => null_import, +}; pub fn assert(b: bool) { if (!b) unreachable{} } + +const null_import = @import("empty.zig"); diff --git a/std/io.zig b/std/io.zig index 3f904236eb6fb56a4d5601bea4bc7561760315f4..98eecef65421cfcdf72cfe55df2214f2d1241d99 100644 --- a/std/io.zig +++ b/std/io.zig @@ -119,10 +119,10 @@ pub struct OutStream { } pub fn flush(os: &OutStream) -> %void { - const amt_written = linux.write(os.fd, &os.buffer[0], os.index); - os.index = 0; - if (amt_written < 0) { - return switch (-amt_written) { + const write_ret = linux.write(os.fd, &os.buffer[0], os.index); + const write_err = linux.get_errno(write_ret); + if (write_err > 0) { + return switch (write_err) { errno.EINVAL => unreachable{}, errno.EDQUOT => error.DiskQuota, errno.EFBIG => error.FileTooBig, @@ -134,6 +134,7 @@ pub struct OutStream { else => error.Unexpected, } } + os.index = 0; } pub fn close(os: &OutStream) -> %void {