Merge pull request #13802 from ziglang/windows-lib-name
CI: make Windows build from source like every other system
This commit is contained in:
31
build.zig
31
build.zig
@@ -280,6 +280,13 @@ pub fn build(b: *Builder) !void {
|
||||
try addStaticLlvmOptionsToExe(exe);
|
||||
try addStaticLlvmOptionsToExe(test_cases);
|
||||
}
|
||||
if (target.isWindows()) {
|
||||
inline for (.{ exe, test_cases }) |artifact| {
|
||||
artifact.linkSystemLibrary("version");
|
||||
artifact.linkSystemLibrary("uuid");
|
||||
artifact.linkSystemLibrary("ole32");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const semver = try std.SemanticVersion.parse(version);
|
||||
@@ -537,7 +544,11 @@ fn addCmakeCfgOptionsToExe(
|
||||
exe.addObjectFile(fs.path.join(b.allocator, &[_][]const u8{
|
||||
cfg.cmake_binary_dir,
|
||||
"zigcpp",
|
||||
b.fmt("{s}{s}{s}", .{ exe.target.libPrefix(), "zigcpp", exe.target.staticLibSuffix() }),
|
||||
b.fmt("{s}{s}{s}", .{
|
||||
cfg.cmake_static_library_prefix,
|
||||
"zigcpp",
|
||||
cfg.cmake_static_library_suffix,
|
||||
}),
|
||||
}) catch unreachable);
|
||||
assert(cfg.lld_include_dir.len != 0);
|
||||
exe.addIncludePath(cfg.lld_include_dir);
|
||||
@@ -610,12 +621,6 @@ fn addStaticLlvmOptionsToExe(exe: *std.build.LibExeObjStep) !void {
|
||||
|
||||
// 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(
|
||||
@@ -669,6 +674,8 @@ const CMakeConfig = struct {
|
||||
llvm_linkage: std.build.LibExeObjStep.Linkage,
|
||||
cmake_binary_dir: []const u8,
|
||||
cmake_prefix_path: []const u8,
|
||||
cmake_static_library_prefix: []const u8,
|
||||
cmake_static_library_suffix: []const u8,
|
||||
cxx_compiler: []const u8,
|
||||
lld_include_dir: []const u8,
|
||||
lld_libraries: []const u8,
|
||||
@@ -732,6 +739,8 @@ fn parseConfigH(b: *Builder, config_h_text: []const u8) ?CMakeConfig {
|
||||
.llvm_linkage = undefined,
|
||||
.cmake_binary_dir = undefined,
|
||||
.cmake_prefix_path = undefined,
|
||||
.cmake_static_library_prefix = undefined,
|
||||
.cmake_static_library_suffix = undefined,
|
||||
.cxx_compiler = undefined,
|
||||
.lld_include_dir = undefined,
|
||||
.lld_libraries = undefined,
|
||||
@@ -751,6 +760,14 @@ fn parseConfigH(b: *Builder, config_h_text: []const u8) ?CMakeConfig {
|
||||
.prefix = "#define ZIG_CMAKE_PREFIX_PATH ",
|
||||
.field = "cmake_prefix_path",
|
||||
},
|
||||
.{
|
||||
.prefix = "#define ZIG_CMAKE_STATIC_LIBRARY_PREFIX ",
|
||||
.field = "cmake_static_library_prefix",
|
||||
},
|
||||
.{
|
||||
.prefix = "#define ZIG_CMAKE_STATIC_LIBRARY_SUFFIX ",
|
||||
.field = "cmake_static_library_suffix",
|
||||
},
|
||||
.{
|
||||
.prefix = "#define ZIG_CXX_COMPILER ",
|
||||
.field = "cxx_compiler",
|
||||
|
||||
@@ -1,20 +1,18 @@
|
||||
$TARGET = "$($Env:ARCH)-windows-gnu"
|
||||
$ZIG_LLVM_CLANG_LLD_NAME = "zig+llvm+lld+clang-$TARGET-0.11.0-dev.448+e6e459e9e"
|
||||
$MCPU = "baseline"
|
||||
$ZIG_LLVM_CLANG_LLD_URL = "https://ziglang.org/deps/$ZIG_LLVM_CLANG_LLD_NAME.zip"
|
||||
$PREFIX_PATH = "$(Get-Location)\$ZIG_LLVM_CLANG_LLD_NAME"
|
||||
$ZIG = "$PREFIX_PATH\bin\zig.exe"
|
||||
$ZIG_LIB_DIR = "$(Get-Location)\lib"
|
||||
|
||||
Write-Output "Downloading $ZIG_LLVM_CLANG_LLD_URL"
|
||||
|
||||
Invoke-WebRequest -Uri "$ZIG_LLVM_CLANG_LLD_URL" -OutFile "$ZIG_LLVM_CLANG_LLD_NAME.zip"
|
||||
|
||||
Write-Output "Extracting..."
|
||||
|
||||
Add-Type -AssemblyName System.IO.Compression.FileSystem ;
|
||||
[System.IO.Compression.ZipFile]::ExtractToDirectory("$PWD/$ZIG_LLVM_CLANG_LLD_NAME.zip", "$PWD")
|
||||
|
||||
Set-Variable -Name ZIGLIBDIR -Value "$(Get-Location)\lib"
|
||||
Set-Variable -Name ZIGINSTALLDIR -Value "$(Get-Location)\stage3-release"
|
||||
Set-Variable -Name ZIGPREFIXPATH -Value "$(Get-Location)\$ZIG_LLVM_CLANG_LLD_NAME"
|
||||
|
||||
function CheckLastExitCode {
|
||||
if (!$?) {
|
||||
exit 1
|
||||
@@ -31,32 +29,41 @@ if ((git rev-parse --is-shallow-repository) -eq "true") {
|
||||
git fetch --unshallow # `git describe` won't work on a shallow repo
|
||||
}
|
||||
|
||||
Write-Output "Building Zig..."
|
||||
Write-Output "Building from source..."
|
||||
Remove-Item -Path 'build-release' -Recurse -Force -ErrorAction Ignore
|
||||
New-Item -Path 'build-release' -ItemType Directory
|
||||
Set-Location -Path 'build-release'
|
||||
|
||||
& "$ZIGPREFIXPATH\bin\zig.exe" build `
|
||||
--prefix "$ZIGINSTALLDIR" `
|
||||
--search-prefix "$ZIGPREFIXPATH" `
|
||||
--zig-lib-dir "$ZIGLIBDIR" `
|
||||
-Dstatic-llvm `
|
||||
-Drelease `
|
||||
-Duse-zig-libcxx `
|
||||
-Dtarget="$TARGET"
|
||||
# CMake gives a syntax error when file paths with backward slashes are used.
|
||||
# Here, we use forward slashes only to work around this.
|
||||
& cmake .. `
|
||||
-GNinja `
|
||||
-DCMAKE_INSTALL_PREFIX="stage3-release" `
|
||||
-DCMAKE_PREFIX_PATH="$($PREFIX_PATH -Replace "\\", "/")" `
|
||||
-DCMAKE_BUILD_TYPE=Release `
|
||||
-DCMAKE_C_COMPILER="$($ZIG -Replace "\\", "/");cc;-target;$TARGET;-mcpu=$MCPU" `
|
||||
-DCMAKE_CXX_COMPILER="$($ZIG -Replace "\\", "/");c++;-target;$TARGET;-mcpu=$MCPU" `
|
||||
-DZIG_TARGET_TRIPLE="$TARGET" `
|
||||
-DZIG_TARGET_MCPU="$MCPU" `
|
||||
-DZIG_STATIC=ON
|
||||
CheckLastExitCode
|
||||
|
||||
Write-Output " zig build test docs..."
|
||||
|
||||
& "$ZIGINSTALLDIR\bin\zig.exe" build test docs `
|
||||
--search-prefix "$ZIGPREFIXPATH" `
|
||||
-Dstatic-llvm `
|
||||
-Dskip-non-native `
|
||||
-Denable-symlinks-windows
|
||||
ninja install
|
||||
CheckLastExitCode
|
||||
|
||||
# Produce the experimental std lib documentation.
|
||||
Write-Output "zig test std/std.zig..."
|
||||
|
||||
& "$ZIGINSTALLDIR\bin\zig.exe" test "$ZIGLIBDIR\std\std.zig" `
|
||||
--zig-lib-dir "$ZIGLIBDIR" `
|
||||
-femit-docs `
|
||||
-fno-emit-bin
|
||||
Write-Output "Main test suite..."
|
||||
& "stage3-release\bin\zig.exe" build test docs `
|
||||
--zig-lib-dir "$ZIG_LIB_DIR" `
|
||||
--search-prefix "$PREFIX_PATH" `
|
||||
-Dstatic-llvm `
|
||||
-Dskip-non-native `
|
||||
-Denable-symlinks-windows
|
||||
CheckLastExitCode
|
||||
|
||||
Write-Output "Testing Autodocs..."
|
||||
& "stage3-release\bin\zig.exe" test "..\lib\std\std.zig" `
|
||||
--zig-lib-dir "$ZIG_LIB_DIR" `
|
||||
-femit-docs `
|
||||
-fno-emit-bin
|
||||
CheckLastExitCode
|
||||
|
||||
|
||||
@@ -15,16 +15,18 @@
|
||||
#define ZIG_VERSION_STRING "@ZIG_VERSION@"
|
||||
|
||||
// Used by build.zig for communicating build information to self hosted build.
|
||||
#define ZIG_CLANG_LIBRARIES "@CLANG_LIBRARIES@"
|
||||
#define ZIG_CMAKE_BINARY_DIR "@CMAKE_BINARY_DIR@"
|
||||
#define ZIG_LLVM_LINK_MODE "@LLVM_LINK_MODE@"
|
||||
#define ZIG_CMAKE_PREFIX_PATH "@ZIG_CMAKE_PREFIX_PATH@"
|
||||
#define ZIG_CMAKE_STATIC_LIBRARY_PREFIX "@CMAKE_STATIC_LIBRARY_PREFIX@"
|
||||
#define ZIG_CMAKE_STATIC_LIBRARY_SUFFIX "@CMAKE_STATIC_LIBRARY_SUFFIX@"
|
||||
#define ZIG_CXX_COMPILER "@CMAKE_CXX_COMPILER@"
|
||||
#define ZIG_DIA_GUIDS_LIB "@ZIG_DIA_GUIDS_LIB_ESCAPED@"
|
||||
#define ZIG_LLD_INCLUDE_PATH "@LLD_INCLUDE_DIRS@"
|
||||
#define ZIG_LLD_LIBRARIES "@LLD_LIBRARIES@"
|
||||
#define ZIG_CLANG_LIBRARIES "@CLANG_LIBRARIES@"
|
||||
#define ZIG_LLVM_INCLUDE_PATH "@LLVM_INCLUDE_DIRS@"
|
||||
#define ZIG_LLVM_LIB_PATH "@LLVM_LIBDIRS@"
|
||||
#define ZIG_LLVM_LIBRARIES "@LLVM_LIBRARIES@"
|
||||
#define ZIG_DIA_GUIDS_LIB "@ZIG_DIA_GUIDS_LIB_ESCAPED@"
|
||||
#define ZIG_LLVM_LIB_PATH "@LLVM_LIBDIRS@"
|
||||
#define ZIG_LLVM_LINK_MODE "@LLVM_LINK_MODE@"
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user