| 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 | 91 | set(ZIG_SHARED_LLVM off CACHE BOOL "Prefer linking against shared LLVM libraries") |
| 92 | 92 | set(ZIG_STATIC_LLVM off CACHE BOOL "Prefer linking against static LLVM libraries") |
| 93 | 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 | 95 | set(ZIG_STATIC_ZSTD off CACHE BOOL "Prefer linking against static zstd") |
| 95 | 96 | set(ZIG_USE_CCACHE off CACHE BOOL "Use ccache") |
| 96 | 97 | |
| ... | ... | @@ -138,19 +139,24 @@ find_package(clang 15) |
| 138 | 139 | find_package(lld 15) |
| 139 | 140 | |
| 140 | 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 | 148 | find_library(ZLIB NAMES libz.a libzlibstatic.a z zlib libz NAMES_PER_DIR) |
| 143 | 149 | list(APPEND LLVM_LIBRARIES "${ZLIB}") |
| 144 | 150 | endif() |
| 145 | 151 | |
| 146 | if(ZIG_STATIC_ZSTD) | |
| 147 | list(REMOVE_ITEM LLVM_LIBRARIES "-lzstd") | |
| 152 | if(ZIG_STATIC_ZSTD AND ZIG_ENABLE_ZSTD) | |
| 153 | list(REMOVE_ITEM LLVM_SYSTEM_LIBRARIES "-lzstd") | |
| 148 | 154 | find_library(ZSTD NAMES libzstd.a libzstdstatic.a zstd NAMES_PER_DIR) |
| 149 | 155 | list(APPEND LLVM_LIBRARIES "${ZSTD}") |
| 150 | 156 | endif() |
| 151 | 157 | |
| 152 | 158 | if(APPLE AND ZIG_STATIC) |
| 153 | list(REMOVE_ITEM LLVM_LIBRARIES "-lcurses") | |
| 159 | list(REMOVE_ITEM LLVM_SYSTEM_LIBRARIES "-lcurses") | |
| 154 | 160 | find_library(CURSES NAMES libcurses.a libncurses.a NAMES_PER_DIR |
| 155 | 161 | PATHS |
| 156 | 162 | /usr/local/opt/ncurses/lib |
| ... | ... | @@ -706,6 +712,7 @@ target_link_libraries(zigcpp LINK_PUBLIC |
| 706 | 712 | ${CLANG_LIBRARIES} |
| 707 | 713 | ${LLD_LIBRARIES} |
| 708 | 714 | ${LLVM_LIBRARIES} |
| 715 | ${LLVM_SYSTEM_LIBRARIES} | |
| 709 | 716 | ${CMAKE_THREAD_LIBS_INIT} |
| 710 | 717 | ) |
| 711 | 718 | |
| ... | ... | @@ -839,7 +846,7 @@ if(ZIG_SINGLE_THREADED) |
| 839 | 846 | else() |
| 840 | 847 | set(ZIG_SINGLE_THREADED_ARG "") |
| 841 | 848 | endif() |
| 842 | if(ZIG_STATIC) | |
| 849 | if(ZIG_STATIC AND NOT MSVC) | |
| 843 | 850 | set(ZIG_STATIC_ARG "-Duse-zig-libcxx") |
| 844 | 851 | else() |
| 845 | 852 | set(ZIG_STATIC_ARG "") |
build.zig+20-3| ... | ... | @@ -552,6 +552,7 @@ fn addCmakeCfgOptionsToExe( |
| 552 | 552 | addCMakeLibraryList(exe, cfg.clang_libraries); |
| 553 | 553 | addCMakeLibraryList(exe, cfg.lld_libraries); |
| 554 | 554 | addCMakeLibraryList(exe, cfg.llvm_libraries); |
| 555 | addCMakeSystemLibraryList(exe, cfg.clang_system_libraries); | |
| 555 | 556 | addCMakeSystemLibraryList(exe, cfg.llvm_system_libraries); |
| 556 | 557 | |
| 557 | 558 | if (use_zig_libcxx) { |
| ... | ... | @@ -627,10 +628,20 @@ fn addStaticLlvmOptionsToExe(exe: *std.build.LibExeObjStep) !void { |
| 627 | 628 | } |
| 628 | 629 | |
| 629 | 630 | exe.linkSystemLibrary("z"); |
| 630 | exe.linkSystemLibrary("zstd"); | |
| 631 | 631 | |
| 632 | // This means we rely on clang-or-zig-built LLVM, Clang, LLD libraries. | |
| 633 | exe.linkSystemLibrary("c++"); | |
| 632 | if (exe.target.getOs().tag != .windows and exe.target.getAbi() != .msvc) { | |
| 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 | 647 | fn addCxxKnownPath( |
| ... | ... | @@ -707,6 +718,7 @@ const CMakeConfig = struct { |
| 707 | 718 | lld_include_dir: []const u8, |
| 708 | 719 | lld_libraries: []const u8, |
| 709 | 720 | clang_libraries: []const u8, |
| 721 | clang_system_libraries: []const u8, | |
| 710 | 722 | llvm_lib_dir: []const u8, |
| 711 | 723 | llvm_include_dir: []const u8, |
| 712 | 724 | llvm_libraries: []const u8, |
| ... | ... | @@ -773,6 +785,7 @@ fn parseConfigH(b: *Builder, config_h_text: []const u8) ?CMakeConfig { |
| 773 | 785 | .lld_include_dir = undefined, |
| 774 | 786 | .lld_libraries = undefined, |
| 775 | 787 | .clang_libraries = undefined, |
| 788 | .clang_system_libraries = undefined, | |
| 776 | 789 | .llvm_lib_dir = undefined, |
| 777 | 790 | .llvm_include_dir = undefined, |
| 778 | 791 | .llvm_libraries = undefined, |
| ... | ... | @@ -813,6 +826,10 @@ fn parseConfigH(b: *Builder, config_h_text: []const u8) ?CMakeConfig { |
| 813 | 826 | .prefix = "#define ZIG_CLANG_LIBRARIES ", |
| 814 | 827 | .field = "clang_libraries", |
| 815 | 828 | }, |
| 829 | .{ | |
| 830 | .prefix = "#define ZIG_CLANG_SYSTEM_LIBRARIES ", | |
| 831 | .field = "clang_system_libraries", | |
| 832 | }, | |
| 816 | 833 | .{ |
| 817 | 834 | .prefix = "#define ZIG_LLVM_LIBRARIES ", |
| 818 | 835 | .field = "llvm_libraries", |
cmake/Findclang.cmake+5| ... | ... | @@ -5,6 +5,7 @@ |
| 5 | 5 | # CLANG_FOUND |
| 6 | 6 | # CLANG_INCLUDE_DIRS |
| 7 | 7 | # CLANG_LIBRARIES |
| 8 | # CLANG_SYSTEM_LIBRARIES | |
| 8 | 9 | # CLANG_LIBDIRS |
| 9 | 10 | |
| 10 | 11 | find_path(CLANG_INCLUDE_DIRS NAMES clang/Frontend/ASTUnit.h |
| ... | ... | @@ -68,6 +69,10 @@ else() |
| 68 | 69 | FIND_AND_ADD_CLANG_LIB(clangSupport) |
| 69 | 70 | endif() |
| 70 | 71 | |
| 72 | if (MSVC) | |
| 73 | set(CLANG_SYSTEM_LIBRARIES "version.lib") | |
| 74 | endif() | |
| 75 | ||
| 71 | 76 | include(FindPackageHandleStandardArgs) |
| 72 | 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 | 3297 | // TODO Surface more error details. |
| 3298 | 3298 | comp.lockAndSetMiscFailure( |
| 3299 | 3299 | .windows_import_lib, |
| 3300 | "unable to generate DLL import .lib file: {s}", | |
| 3301 | .{@errorName(err)}, | |
| 3300 | "unable to generate DLL import .lib file for {s}: {s}", | |
| 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 | 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 | 495 | log.err("DLL import library for -l{s} not found", .{key}); |
| 490 | 496 | return error.DllImportLibraryNotFound; |
| 491 | 497 | } |
stage1/config.h.in+1| ... | ... | @@ -16,6 +16,7 @@ |
| 16 | 16 | |
| 17 | 17 | // Used by build.zig for communicating build information to self hosted build. |
| 18 | 18 | #define ZIG_CLANG_LIBRARIES "@CLANG_LIBRARIES@" |
| 19 | #define ZIG_CLANG_SYSTEM_LIBRARIES "@CLANG_SYSTEM_LIBRARIES@" | |
| 19 | 20 | #define ZIG_CMAKE_BINARY_DIR "@CMAKE_BINARY_DIR@" |
| 20 | 21 | #define ZIG_CMAKE_PREFIX_PATH "@ZIG_CMAKE_PREFIX_PATH@" |
| 21 | 22 | #define ZIG_CMAKE_STATIC_LIBRARY_PREFIX "@CMAKE_STATIC_LIBRARY_PREFIX@" |