| author | |
| committer | |
| log | 0471eea0e2cac49946449efe4698d5ac18c0dc0d |
| tree | f1d6d3a29e16d952380c3b0ea498d9cc65cf0d07 |
| parent | c3945d9edeb304ccd9f3d44e9ab0bf94f5420694 |
6 files changed, 46 insertions(+), 10 deletions(-)
CMakeLists.txt+12-5| ... | @@ -91,6 +91,7 @@ set(ZIG_STATIC off CACHE BOOL "Attempt to build a static zig executable (not com | ... | @@ -91,6 +91,7 @@ set(ZIG_STATIC off CACHE BOOL "Attempt to build a static zig executable (not com |
| 91 | set(ZIG_SHARED_LLVM off CACHE BOOL "Prefer linking against shared LLVM libraries") | 91 | set(ZIG_SHARED_LLVM off CACHE BOOL "Prefer linking against shared LLVM libraries") |
| 92 | set(ZIG_STATIC_LLVM off CACHE BOOL "Prefer linking against static LLVM libraries") | 92 | set(ZIG_STATIC_LLVM off CACHE BOOL "Prefer linking against static LLVM libraries") |
| 93 | set(ZIG_STATIC_ZLIB off CACHE BOOL "Prefer linking against static zlib") | 93 | set(ZIG_STATIC_ZLIB off CACHE BOOL "Prefer linking against static zlib") |
| 94 | set(ZIG_ENABLE_ZSTD on CACHE BOOL "Enable linking zstd") | ||
| 94 | set(ZIG_STATIC_ZSTD off CACHE BOOL "Prefer linking against static zstd") | 95 | set(ZIG_STATIC_ZSTD off CACHE BOOL "Prefer linking against static zstd") |
| 95 | set(ZIG_USE_CCACHE off CACHE BOOL "Use ccache") | 96 | set(ZIG_USE_CCACHE off CACHE BOOL "Use ccache") |
| 96 | 97 | ||
| ... | @@ -138,19 +139,24 @@ find_package(clang 15) | ... | @@ -138,19 +139,24 @@ find_package(clang 15) |
| 138 | find_package(lld 15) | 139 | find_package(lld 15) |
| 139 | 140 | ||
| 140 | if(ZIG_STATIC_ZLIB) | 141 | if(ZIG_STATIC_ZLIB) |
| 141 | list(REMOVE_ITEM LLVM_LIBRARIES "-lz") | 142 | if (MSVC) |
| 143 | list(REMOVE_ITEM LLVM_SYSTEM_LIBRARIES "z.lib") | ||
| 144 | else() | ||
| 145 | list(REMOVE_ITEM LLVM_SYSTEM_LIBRARIES "-lz") | ||
| 146 | endif() | ||
| 147 | |||
| 142 | find_library(ZLIB NAMES libz.a libzlibstatic.a z zlib libz NAMES_PER_DIR) | 148 | find_library(ZLIB NAMES libz.a libzlibstatic.a z zlib libz NAMES_PER_DIR) |
| 143 | list(APPEND LLVM_LIBRARIES "${ZLIB}") | 149 | list(APPEND LLVM_LIBRARIES "${ZLIB}") |
| 144 | endif() | 150 | endif() |
| 145 | 151 | ||
| 146 | if(ZIG_STATIC_ZSTD) | 152 | if(ZIG_STATIC_ZSTD AND ZIG_ENABLE_ZSTD) |
| 147 | list(REMOVE_ITEM LLVM_LIBRARIES "-lzstd") | 153 | list(REMOVE_ITEM LLVM_SYSTEM_LIBRARIES "-lzstd") |
| 148 | find_library(ZSTD NAMES libzstd.a libzstdstatic.a zstd NAMES_PER_DIR) | 154 | find_library(ZSTD NAMES libzstd.a libzstdstatic.a zstd NAMES_PER_DIR) |
| 149 | list(APPEND LLVM_LIBRARIES "${ZSTD}") | 155 | list(APPEND LLVM_LIBRARIES "${ZSTD}") |
| 150 | endif() | 156 | endif() |
| 151 | 157 | ||
| 152 | if(APPLE AND ZIG_STATIC) | 158 | if(APPLE AND ZIG_STATIC) |
| 153 | list(REMOVE_ITEM LLVM_LIBRARIES "-lcurses") | 159 | list(REMOVE_ITEM LLVM_SYSTEM_LIBRARIES "-lcurses") |
| 154 | find_library(CURSES NAMES libcurses.a libncurses.a NAMES_PER_DIR | 160 | find_library(CURSES NAMES libcurses.a libncurses.a NAMES_PER_DIR |
| 155 | PATHS | 161 | PATHS |
| 156 | /usr/local/opt/ncurses/lib | 162 | /usr/local/opt/ncurses/lib |
| ... | @@ -706,6 +712,7 @@ target_link_libraries(zigcpp LINK_PUBLIC | ... | @@ -706,6 +712,7 @@ target_link_libraries(zigcpp LINK_PUBLIC |
| 706 | ${CLANG_LIBRARIES} | 712 | ${CLANG_LIBRARIES} |
| 707 | ${LLD_LIBRARIES} | 713 | ${LLD_LIBRARIES} |
| 708 | ${LLVM_LIBRARIES} | 714 | ${LLVM_LIBRARIES} |
| 715 | ${LLVM_SYSTEM_LIBRARIES} | ||
| 709 | ${CMAKE_THREAD_LIBS_INIT} | 716 | ${CMAKE_THREAD_LIBS_INIT} |
| 710 | ) | 717 | ) |
| 711 | 718 | ||
| ... | @@ -839,7 +846,7 @@ if(ZIG_SINGLE_THREADED) | ... | @@ -839,7 +846,7 @@ if(ZIG_SINGLE_THREADED) |
| 839 | else() | 846 | else() |
| 840 | set(ZIG_SINGLE_THREADED_ARG "") | 847 | set(ZIG_SINGLE_THREADED_ARG "") |
| 841 | endif() | 848 | endif() |
| 842 | if(ZIG_STATIC) | 849 | if(ZIG_STATIC AND NOT MSVC) |
| 843 | set(ZIG_STATIC_ARG "-Duse-zig-libcxx") | 850 | set(ZIG_STATIC_ARG "-Duse-zig-libcxx") |
| 844 | else() | 851 | else() |
| 845 | set(ZIG_STATIC_ARG "") | 852 | set(ZIG_STATIC_ARG "") |
build.zig+20-3| ... | @@ -552,6 +552,7 @@ fn addCmakeCfgOptionsToExe( | ... | @@ -552,6 +552,7 @@ fn addCmakeCfgOptionsToExe( |
| 552 | addCMakeLibraryList(exe, cfg.clang_libraries); | 552 | addCMakeLibraryList(exe, cfg.clang_libraries); |
| 553 | addCMakeLibraryList(exe, cfg.lld_libraries); | 553 | addCMakeLibraryList(exe, cfg.lld_libraries); |
| 554 | addCMakeLibraryList(exe, cfg.llvm_libraries); | 554 | addCMakeLibraryList(exe, cfg.llvm_libraries); |
| 555 | addCMakeSystemLibraryList(exe, cfg.clang_system_libraries); | ||
| 555 | addCMakeSystemLibraryList(exe, cfg.llvm_system_libraries); | 556 | addCMakeSystemLibraryList(exe, cfg.llvm_system_libraries); |
| 556 | 557 | ||
| 557 | if (use_zig_libcxx) { | 558 | if (use_zig_libcxx) { |
| ... | @@ -627,10 +628,20 @@ fn addStaticLlvmOptionsToExe(exe: *std.build.LibExeObjStep) !void { | ... | @@ -627,10 +628,20 @@ fn addStaticLlvmOptionsToExe(exe: *std.build.LibExeObjStep) !void { |
| 627 | } | 628 | } |
| 628 | 629 | ||
| 629 | exe.linkSystemLibrary("z"); | 630 | exe.linkSystemLibrary("z"); |
| 630 | exe.linkSystemLibrary("zstd"); | ||
| 631 | 631 | ||
| 632 | // This means we rely on clang-or-zig-built LLVM, Clang, LLD libraries. | 632 | if (exe.target.getOs().tag != .windows and exe.target.getAbi() != .msvc) { |
| 633 | exe.linkSystemLibrary("c++"); | 633 | // TODO: Support this on msvc |
| 634 | exe.linkSystemLibrary("zstd"); | ||
| 635 | |||
| 636 | // This means we rely on clang-or-zig-built LLVM, Clang, LLD libraries. | ||
| 637 | exe.linkSystemLibrary("c++"); | ||
| 638 | } | ||
| 639 | |||
| 640 | if (exe.target.getOs().tag == .windows) { | ||
| 641 | exe.linkSystemLibrary("version"); | ||
| 642 | exe.linkSystemLibrary("uuid"); | ||
| 643 | exe.linkSystemLibrary("ole32"); | ||
| 644 | } | ||
| 634 | } | 645 | } |
| 635 | 646 | ||
| 636 | fn addCxxKnownPath( | 647 | fn addCxxKnownPath( |
| ... | @@ -707,6 +718,7 @@ const CMakeConfig = struct { | ... | @@ -707,6 +718,7 @@ const CMakeConfig = struct { |
| 707 | lld_include_dir: []const u8, | 718 | lld_include_dir: []const u8, |
| 708 | lld_libraries: []const u8, | 719 | lld_libraries: []const u8, |
| 709 | clang_libraries: []const u8, | 720 | clang_libraries: []const u8, |
| 721 | clang_system_libraries: []const u8, | ||
| 710 | llvm_lib_dir: []const u8, | 722 | llvm_lib_dir: []const u8, |
| 711 | llvm_include_dir: []const u8, | 723 | llvm_include_dir: []const u8, |
| 712 | llvm_libraries: []const u8, | 724 | llvm_libraries: []const u8, |
| ... | @@ -773,6 +785,7 @@ fn parseConfigH(b: *Builder, config_h_text: []const u8) ?CMakeConfig { | ... | @@ -773,6 +785,7 @@ fn parseConfigH(b: *Builder, config_h_text: []const u8) ?CMakeConfig { |
| 773 | .lld_include_dir = undefined, | 785 | .lld_include_dir = undefined, |
| 774 | .lld_libraries = undefined, | 786 | .lld_libraries = undefined, |
| 775 | .clang_libraries = undefined, | 787 | .clang_libraries = undefined, |
| 788 | .clang_system_libraries = undefined, | ||
| 776 | .llvm_lib_dir = undefined, | 789 | .llvm_lib_dir = undefined, |
| 777 | .llvm_include_dir = undefined, | 790 | .llvm_include_dir = undefined, |
| 778 | .llvm_libraries = undefined, | 791 | .llvm_libraries = undefined, |
| ... | @@ -813,6 +826,10 @@ fn parseConfigH(b: *Builder, config_h_text: []const u8) ?CMakeConfig { | ... | @@ -813,6 +826,10 @@ fn parseConfigH(b: *Builder, config_h_text: []const u8) ?CMakeConfig { |
| 813 | .prefix = "#define ZIG_CLANG_LIBRARIES ", | 826 | .prefix = "#define ZIG_CLANG_LIBRARIES ", |
| 814 | .field = "clang_libraries", | 827 | .field = "clang_libraries", |
| 815 | }, | 828 | }, |
| 829 | .{ | ||
| 830 | .prefix = "#define ZIG_CLANG_SYSTEM_LIBRARIES ", | ||
| 831 | .field = "clang_system_libraries", | ||
| 832 | }, | ||
| 816 | .{ | 833 | .{ |
| 817 | .prefix = "#define ZIG_LLVM_LIBRARIES ", | 834 | .prefix = "#define ZIG_LLVM_LIBRARIES ", |
| 818 | .field = "llvm_libraries", | 835 | .field = "llvm_libraries", |
cmake/Findclang.cmake+5| ... | @@ -5,6 +5,7 @@ | ... | @@ -5,6 +5,7 @@ |
| 5 | # CLANG_FOUND | 5 | # CLANG_FOUND |
| 6 | # CLANG_INCLUDE_DIRS | 6 | # CLANG_INCLUDE_DIRS |
| 7 | # CLANG_LIBRARIES | 7 | # CLANG_LIBRARIES |
| 8 | # CLANG_SYSTEM_LIBRARIES | ||
| 8 | # CLANG_LIBDIRS | 9 | # CLANG_LIBDIRS |
| 9 | 10 | ||
| 10 | find_path(CLANG_INCLUDE_DIRS NAMES clang/Frontend/ASTUnit.h | 11 | find_path(CLANG_INCLUDE_DIRS NAMES clang/Frontend/ASTUnit.h |
| ... | @@ -68,6 +69,10 @@ else() | ... | @@ -68,6 +69,10 @@ else() |
| 68 | FIND_AND_ADD_CLANG_LIB(clangSupport) | 69 | FIND_AND_ADD_CLANG_LIB(clangSupport) |
| 69 | endif() | 70 | endif() |
| 70 | 71 | ||
| 72 | if (MSVC) | ||
| 73 | set(CLANG_SYSTEM_LIBRARIES "version.lib") | ||
| 74 | endif() | ||
| 75 | |||
| 71 | include(FindPackageHandleStandardArgs) | 76 | include(FindPackageHandleStandardArgs) |
| 72 | find_package_handle_standard_args(clang DEFAULT_MSG CLANG_LIBRARIES CLANG_INCLUDE_DIRS) | 77 | find_package_handle_standard_args(clang DEFAULT_MSG CLANG_LIBRARIES CLANG_INCLUDE_DIRS) |
| 73 | 78 |
src/Compilation.zig+2-2| ... | @@ -3297,8 +3297,8 @@ fn processOneJob(comp: *Compilation, job: Job) !void { | ... | @@ -3297,8 +3297,8 @@ fn processOneJob(comp: *Compilation, job: Job) !void { |
| 3297 | // TODO Surface more error details. | 3297 | // TODO Surface more error details. |
| 3298 | comp.lockAndSetMiscFailure( | 3298 | comp.lockAndSetMiscFailure( |
| 3299 | .windows_import_lib, | 3299 | .windows_import_lib, |
| 3300 | "unable to generate DLL import .lib file: {s}", | 3300 | "unable to generate DLL import .lib file for {s}: {s}", |
| 3301 | .{@errorName(err)}, | 3301 | .{link_lib, @errorName(err)}, |
| 3302 | ); | 3302 | ); |
| 3303 | }; | 3303 | }; |
| 3304 | }, | 3304 | }, |
src/link/Coff/lld.zig+6| ... | @@ -486,6 +486,12 @@ pub fn linkWithLLD(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod | ... | @@ -486,6 +486,12 @@ pub fn linkWithLLD(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod |
| 486 | continue; | 486 | continue; |
| 487 | } | 487 | } |
| 488 | } | 488 | } |
| 489 | if (target.abi == .msvc) { // TODO: Do this at the top, if we detect we're using the native libc? | ||
| 490 | log.warn("adding system lib {s}", .{ lib_basename }); | ||
| 491 | argv.appendAssumeCapacity(lib_basename); | ||
| 492 | continue; | ||
| 493 | } | ||
| 494 | |||
| 489 | log.err("DLL import library for -l{s} not found", .{key}); | 495 | log.err("DLL import library for -l{s} not found", .{key}); |
| 490 | return error.DllImportLibraryNotFound; | 496 | return error.DllImportLibraryNotFound; |
| 491 | } | 497 | } |
stage1/config.h.in+1| ... | @@ -16,6 +16,7 @@ | ... | @@ -16,6 +16,7 @@ |
| 16 | 16 | ||
| 17 | // Used by build.zig for communicating build information to self hosted build. | 17 | // Used by build.zig for communicating build information to self hosted build. |
| 18 | #define ZIG_CLANG_LIBRARIES "@CLANG_LIBRARIES@" | 18 | #define ZIG_CLANG_LIBRARIES "@CLANG_LIBRARIES@" |
| 19 | #define ZIG_CLANG_SYSTEM_LIBRARIES "@CLANG_SYSTEM_LIBRARIES@" | ||
| 19 | #define ZIG_CMAKE_BINARY_DIR "@CMAKE_BINARY_DIR@" | 20 | #define ZIG_CMAKE_BINARY_DIR "@CMAKE_BINARY_DIR@" |
| 20 | #define ZIG_CMAKE_PREFIX_PATH "@ZIG_CMAKE_PREFIX_PATH@" | 21 | #define ZIG_CMAKE_PREFIX_PATH "@ZIG_CMAKE_PREFIX_PATH@" |
| 21 | #define ZIG_CMAKE_STATIC_LIBRARY_PREFIX "@CMAKE_STATIC_LIBRARY_PREFIX@" | 22 | #define ZIG_CMAKE_STATIC_LIBRARY_PREFIX "@CMAKE_STATIC_LIBRARY_PREFIX@" |