From eb4337fe8362b7faab34e974d3538d21a10a151f Mon Sep 17 00:00:00 2001 From: Jacob Young Date: Wed, 7 Dec 2022 00:45:03 -0500 Subject: [PATCH 1/4] Revert "CI: revert windows script to master branch version" This reverts commit 106e9678937a662fec220367d5d57d04eb09b6b7. --- ci/x86_64-windows.ps1 | 58 ++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/ci/x86_64-windows.ps1 b/ci/x86_64-windows.ps1 index c5907b47b2..641657b2c6 100644 --- a/ci/x86_64-windows.ps1 +++ b/ci/x86_64-windows.ps1 @@ -1,20 +1,17 @@ $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" 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 +28,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..." +Write-Output "Main test suite..." +& "stage3-release\bin\zig.exe" build test docs ` + --zig-lib-dir "..\lib" ` + --search-prefix "../$ZIG_LLVM_CLANG_LLD_NAME" ` + -Dstatic-llvm ` + -Dskip-non-native ` + -Denable-symlinks-windows +CheckLastExitCode -& "$ZIGINSTALLDIR\bin\zig.exe" test "$ZIGLIBDIR\std\std.zig" ` - --zig-lib-dir "$ZIGLIBDIR" ` +Write-Output "Testing Autodocs..." +& "stage3-release\bin\zig.exe" test "..\lib\std\std.zig" ` + --zig-lib-dir "..\lib" ` -femit-docs ` -fno-emit-bin CheckLastExitCode + From 9627018d0ce3cbe2af91b045d16b094f7adbc15b Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 7 Dec 2022 01:44:15 -0700 Subject: [PATCH 2/4] build: obtain zigcpp library prefix/suffix from cmake --- build.zig | 18 +++++++++++++++++- stage1/config.h.in | 10 ++++++---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/build.zig b/build.zig index f37fa9b268..b452885827 100644 --- a/build.zig +++ b/build.zig @@ -537,7 +537,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); @@ -669,6 +673,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 +738,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 +759,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", diff --git a/stage1/config.h.in b/stage1/config.h.in index 2d4fff6df2..0f1d902ef9 100644 --- a/stage1/config.h.in +++ b/stage1/config.h.in @@ -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 From 6d48357cc79a8c6b626cba7152165dfe2d3674d3 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 7 Dec 2022 01:50:49 -0800 Subject: [PATCH 3/4] build.zig: on windows always link llvm-required system libs When building with LLVM, always do -lole32 -lversion -luuid even when using the cmake-provided build stuff. Otherwise we get undefined symbols when linking. --- build.zig | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/build.zig b/build.zig index b452885827..bcc50ea9fa 100644 --- a/build.zig +++ b/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); @@ -614,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( From 1122d9d212f2147e12675eb86565d63d2b0949a5 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 7 Dec 2022 02:47:54 -0800 Subject: [PATCH 4/4] CI: windows: fix zig lib dir path See #12685 --- ci/x86_64-windows.ps1 | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/ci/x86_64-windows.ps1 b/ci/x86_64-windows.ps1 index 641657b2c6..f5645eaee4 100644 --- a/ci/x86_64-windows.ps1 +++ b/ci/x86_64-windows.ps1 @@ -4,6 +4,7 @@ $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" @@ -52,8 +53,8 @@ CheckLastExitCode Write-Output "Main test suite..." & "stage3-release\bin\zig.exe" build test docs ` - --zig-lib-dir "..\lib" ` - --search-prefix "../$ZIG_LLVM_CLANG_LLD_NAME" ` + --zig-lib-dir "$ZIG_LIB_DIR" ` + --search-prefix "$PREFIX_PATH" ` -Dstatic-llvm ` -Dskip-non-native ` -Denable-symlinks-windows @@ -61,8 +62,8 @@ CheckLastExitCode Write-Output "Testing Autodocs..." & "stage3-release\bin\zig.exe" test "..\lib\std\std.zig" ` - --zig-lib-dir "..\lib" ` - -femit-docs ` - -fno-emit-bin + --zig-lib-dir "$ZIG_LIB_DIR" ` + -femit-docs ` + -fno-emit-bin CheckLastExitCode