mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 05:44:20 +00:00
build: first pass on geting stage3 building under x64_64-windows-msvc
This commit is contained in:
parent
c3945d9ede
commit
0471eea0e2
6 changed files with 46 additions and 10 deletions
|
|
@ -91,6 +91,7 @@ set(ZIG_STATIC off CACHE BOOL "Attempt to build a static zig executable (not com
|
|||
set(ZIG_SHARED_LLVM off CACHE BOOL "Prefer linking against shared LLVM libraries")
|
||||
set(ZIG_STATIC_LLVM off CACHE BOOL "Prefer linking against static LLVM libraries")
|
||||
set(ZIG_STATIC_ZLIB off CACHE BOOL "Prefer linking against static zlib")
|
||||
set(ZIG_ENABLE_ZSTD on CACHE BOOL "Enable linking zstd")
|
||||
set(ZIG_STATIC_ZSTD off CACHE BOOL "Prefer linking against static zstd")
|
||||
set(ZIG_USE_CCACHE off CACHE BOOL "Use ccache")
|
||||
|
||||
|
|
@ -138,19 +139,24 @@ find_package(clang 15)
|
|||
find_package(lld 15)
|
||||
|
||||
if(ZIG_STATIC_ZLIB)
|
||||
list(REMOVE_ITEM LLVM_LIBRARIES "-lz")
|
||||
if (MSVC)
|
||||
list(REMOVE_ITEM LLVM_SYSTEM_LIBRARIES "z.lib")
|
||||
else()
|
||||
list(REMOVE_ITEM LLVM_SYSTEM_LIBRARIES "-lz")
|
||||
endif()
|
||||
|
||||
find_library(ZLIB NAMES libz.a libzlibstatic.a z zlib libz NAMES_PER_DIR)
|
||||
list(APPEND LLVM_LIBRARIES "${ZLIB}")
|
||||
endif()
|
||||
|
||||
if(ZIG_STATIC_ZSTD)
|
||||
list(REMOVE_ITEM LLVM_LIBRARIES "-lzstd")
|
||||
if(ZIG_STATIC_ZSTD AND ZIG_ENABLE_ZSTD)
|
||||
list(REMOVE_ITEM LLVM_SYSTEM_LIBRARIES "-lzstd")
|
||||
find_library(ZSTD NAMES libzstd.a libzstdstatic.a zstd NAMES_PER_DIR)
|
||||
list(APPEND LLVM_LIBRARIES "${ZSTD}")
|
||||
endif()
|
||||
|
||||
if(APPLE AND ZIG_STATIC)
|
||||
list(REMOVE_ITEM LLVM_LIBRARIES "-lcurses")
|
||||
list(REMOVE_ITEM LLVM_SYSTEM_LIBRARIES "-lcurses")
|
||||
find_library(CURSES NAMES libcurses.a libncurses.a NAMES_PER_DIR
|
||||
PATHS
|
||||
/usr/local/opt/ncurses/lib
|
||||
|
|
@ -706,6 +712,7 @@ target_link_libraries(zigcpp LINK_PUBLIC
|
|||
${CLANG_LIBRARIES}
|
||||
${LLD_LIBRARIES}
|
||||
${LLVM_LIBRARIES}
|
||||
${LLVM_SYSTEM_LIBRARIES}
|
||||
${CMAKE_THREAD_LIBS_INIT}
|
||||
)
|
||||
|
||||
|
|
@ -839,7 +846,7 @@ if(ZIG_SINGLE_THREADED)
|
|||
else()
|
||||
set(ZIG_SINGLE_THREADED_ARG "")
|
||||
endif()
|
||||
if(ZIG_STATIC)
|
||||
if(ZIG_STATIC AND NOT MSVC)
|
||||
set(ZIG_STATIC_ARG "-Duse-zig-libcxx")
|
||||
else()
|
||||
set(ZIG_STATIC_ARG "")
|
||||
|
|
|
|||
17
build.zig
17
build.zig
|
|
@ -552,6 +552,7 @@ fn addCmakeCfgOptionsToExe(
|
|||
addCMakeLibraryList(exe, cfg.clang_libraries);
|
||||
addCMakeLibraryList(exe, cfg.lld_libraries);
|
||||
addCMakeLibraryList(exe, cfg.llvm_libraries);
|
||||
addCMakeSystemLibraryList(exe, cfg.clang_system_libraries);
|
||||
addCMakeSystemLibraryList(exe, cfg.llvm_system_libraries);
|
||||
|
||||
if (use_zig_libcxx) {
|
||||
|
|
@ -627,12 +628,22 @@ fn addStaticLlvmOptionsToExe(exe: *std.build.LibExeObjStep) !void {
|
|||
}
|
||||
|
||||
exe.linkSystemLibrary("z");
|
||||
|
||||
if (exe.target.getOs().tag != .windows and exe.target.getAbi() != .msvc) {
|
||||
// TODO: Support this on msvc
|
||||
exe.linkSystemLibrary("zstd");
|
||||
|
||||
// This means we rely on clang-or-zig-built LLVM, Clang, LLD libraries.
|
||||
exe.linkSystemLibrary("c++");
|
||||
}
|
||||
|
||||
if (exe.target.getOs().tag == .windows) {
|
||||
exe.linkSystemLibrary("version");
|
||||
exe.linkSystemLibrary("uuid");
|
||||
exe.linkSystemLibrary("ole32");
|
||||
}
|
||||
}
|
||||
|
||||
fn addCxxKnownPath(
|
||||
b: *Builder,
|
||||
ctx: CMakeConfig,
|
||||
|
|
@ -707,6 +718,7 @@ const CMakeConfig = struct {
|
|||
lld_include_dir: []const u8,
|
||||
lld_libraries: []const u8,
|
||||
clang_libraries: []const u8,
|
||||
clang_system_libraries: []const u8,
|
||||
llvm_lib_dir: []const u8,
|
||||
llvm_include_dir: []const u8,
|
||||
llvm_libraries: []const u8,
|
||||
|
|
@ -773,6 +785,7 @@ fn parseConfigH(b: *Builder, config_h_text: []const u8) ?CMakeConfig {
|
|||
.lld_include_dir = undefined,
|
||||
.lld_libraries = undefined,
|
||||
.clang_libraries = undefined,
|
||||
.clang_system_libraries = undefined,
|
||||
.llvm_lib_dir = undefined,
|
||||
.llvm_include_dir = undefined,
|
||||
.llvm_libraries = undefined,
|
||||
|
|
@ -813,6 +826,10 @@ fn parseConfigH(b: *Builder, config_h_text: []const u8) ?CMakeConfig {
|
|||
.prefix = "#define ZIG_CLANG_LIBRARIES ",
|
||||
.field = "clang_libraries",
|
||||
},
|
||||
.{
|
||||
.prefix = "#define ZIG_CLANG_SYSTEM_LIBRARIES ",
|
||||
.field = "clang_system_libraries",
|
||||
},
|
||||
.{
|
||||
.prefix = "#define ZIG_LLVM_LIBRARIES ",
|
||||
.field = "llvm_libraries",
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
# CLANG_FOUND
|
||||
# CLANG_INCLUDE_DIRS
|
||||
# CLANG_LIBRARIES
|
||||
# CLANG_SYSTEM_LIBRARIES
|
||||
# CLANG_LIBDIRS
|
||||
|
||||
find_path(CLANG_INCLUDE_DIRS NAMES clang/Frontend/ASTUnit.h
|
||||
|
|
@ -68,6 +69,10 @@ else()
|
|||
FIND_AND_ADD_CLANG_LIB(clangSupport)
|
||||
endif()
|
||||
|
||||
if (MSVC)
|
||||
set(CLANG_SYSTEM_LIBRARIES "version.lib")
|
||||
endif()
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(clang DEFAULT_MSG CLANG_LIBRARIES CLANG_INCLUDE_DIRS)
|
||||
|
||||
|
|
|
|||
|
|
@ -3297,8 +3297,8 @@ fn processOneJob(comp: *Compilation, job: Job) !void {
|
|||
// TODO Surface more error details.
|
||||
comp.lockAndSetMiscFailure(
|
||||
.windows_import_lib,
|
||||
"unable to generate DLL import .lib file: {s}",
|
||||
.{@errorName(err)},
|
||||
"unable to generate DLL import .lib file for {s}: {s}",
|
||||
.{link_lib, @errorName(err)},
|
||||
);
|
||||
};
|
||||
},
|
||||
|
|
|
|||
|
|
@ -486,6 +486,12 @@ pub fn linkWithLLD(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod
|
|||
continue;
|
||||
}
|
||||
}
|
||||
if (target.abi == .msvc) { // TODO: Do this at the top, if we detect we're using the native libc?
|
||||
log.warn("adding system lib {s}", .{ lib_basename });
|
||||
argv.appendAssumeCapacity(lib_basename);
|
||||
continue;
|
||||
}
|
||||
|
||||
log.err("DLL import library for -l{s} not found", .{key});
|
||||
return error.DllImportLibraryNotFound;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
// Used by build.zig for communicating build information to self hosted build.
|
||||
#define ZIG_CLANG_LIBRARIES "@CLANG_LIBRARIES@"
|
||||
#define ZIG_CLANG_SYSTEM_LIBRARIES "@CLANG_SYSTEM_LIBRARIES@"
|
||||
#define ZIG_CMAKE_BINARY_DIR "@CMAKE_BINARY_DIR@"
|
||||
#define ZIG_CMAKE_PREFIX_PATH "@ZIG_CMAKE_PREFIX_PATH@"
|
||||
#define ZIG_CMAKE_STATIC_LIBRARY_PREFIX "@CMAKE_STATIC_LIBRARY_PREFIX@"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue