From 373a4990a4cc5ab04e33620c3b624d18ea1896a9 Mon Sep 17 00:00:00 2001 From: Jacob Young Date: Thu, 18 Jul 2024 08:26:25 -0400 Subject: [PATCH] rewrite CI scripts in Zig --- .github/workflows/ci.yaml | 155 +++++-- CMakeLists.txt | 6 +- ci/aarch64-linux-debug.sh | 100 ----- ci/aarch64-linux-release.sh | 100 ----- ci/aarch64-macos-debug.sh | 58 --- ci/aarch64-macos-release.sh | 74 ---- ci/aarch64-windows.ps1 | 71 ---- ci/build.zig | 665 +++++++++++++++++++++++++++++++ ci/build.zig.zon | 188 +++++++++ ci/chmod.zig | 32 ++ ci/cmp.zig | 28 ++ ci/run.zig | 126 ++++++ ci/x86_64-linux-debug.sh | 108 ----- ci/x86_64-linux-release.sh | 124 ------ ci/x86_64-macos-release.sh | 78 ---- ci/x86_64-windows-debug.ps1 | 110 ----- ci/x86_64-windows-release.ps1 | 109 ----- lib/std/Build/Step/RemoveDir.zig | 12 +- lib/std/posix.zig | 5 +- 19 files changed, 1172 insertions(+), 977 deletions(-) delete mode 100644 ci/aarch64-linux-debug.sh delete mode 100644 ci/aarch64-linux-release.sh delete mode 100755 ci/aarch64-macos-debug.sh delete mode 100755 ci/aarch64-macos-release.sh delete mode 100644 ci/aarch64-windows.ps1 create mode 100644 ci/build.zig create mode 100644 ci/build.zig.zon create mode 100644 ci/chmod.zig create mode 100644 ci/cmp.zig create mode 100644 ci/run.zig delete mode 100755 ci/x86_64-linux-debug.sh delete mode 100755 ci/x86_64-linux-release.sh delete mode 100755 ci/x86_64-macos-release.sh delete mode 100644 ci/x86_64-windows-debug.ps1 delete mode 100644 ci/x86_64-windows-release.ps1 diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 04be33bb6b..dd7e73f70d 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -4,95 +4,184 @@ on: push: branches: - master - - llvm18 -concurrency: - # Cancels pending runs when a PR gets updated. - group: ${{ github.head_ref || github.run_id }}-${{ github.actor }} - cancel-in-progress: true + - ci-scripts +env: + ci-zig-version: 0.13.0-dev.76+dee9f82f6 jobs: x86_64-linux-debug: - timeout-minutes: 420 + if: github.repository_owner == 'ziglang' runs-on: [self-hosted, Linux, x86_64] steps: - name: Checkout uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Build and Test - run: sh ci/x86_64-linux-debug.sh + working-directory: ci + run: ~/deps/zig-x86_64-linux-musl-${{env.ci-zig-version}}/bin/zig build --maxrss 21000000000 -Dbuild-type=Debug -Dextra-target=arm-linux-musleabihf test-cmake-bootstrap update-stage1 x86_64-linux-release: - timeout-minutes: 420 + if: github.repository_owner == 'ziglang' runs-on: [self-hosted, Linux, x86_64] steps: - name: Checkout uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Build and Test - run: sh ci/x86_64-linux-release.sh + working-directory: ci + run: ~/deps/zig-x86_64-linux-musl-${{env.ci-zig-version}}/bin/zig build --maxrss 21000000000 -Dbuild-type=Release -Dextra-target=arm-linux-musleabihf -Dcc=cc test-cc-bootstrap test-cmake-bootstrap reproducible update-stage1 aarch64-linux-debug: - timeout-minutes: 480 + if: github.repository_owner == 'ziglang' runs-on: [self-hosted, Linux, aarch64] steps: - name: Checkout uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Build and Test - run: sh ci/aarch64-linux-debug.sh + working-directory: ci + run: ~/deps/zig-aarch64-linux-musl-${{env.ci-zig-version}}/bin/zig build --maxrss 24696061952 -Dbuild-type=Debug -Dextra-target=arm-linux-musleabihf test-cmake-bootstrap update-stage1 aarch64-linux-release: - timeout-minutes: 480 + if: github.repository_owner == 'ziglang' runs-on: [self-hosted, Linux, aarch64] steps: - name: Checkout uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Build and Test - run: sh ci/aarch64-linux-release.sh + working-directory: ci + run: ~/deps/zig-aarch64-linux-musl-${{env.ci-zig-version}}/bin/zig build --maxrss 24696061952 -Dbuild-type=Release -Dextra-target=arm-linux-musleabihf test-cmake-bootstrap reproducible update-stage1 + x86_64-macos-debug: + if: github.repository_owner == 'ziglang' + runs-on: macos-12 + steps: + - name: Restore Zig Cache + id: zig-cache + uses: actions/cache/restore@v4 + with: + path: ~/deps/zig-x86_64-macos-none-${{env.ci-zig-version}} + key: zig-x86_64-macos-none-${{env.ci-zig-version}} + - name: Download Zig + if: steps.zig-cache.outputs.cache-hit != 'true' + run: 'mkdir -p ~/deps && curl https://jacobly.com/deps/zig-x86_64-macos-none-${{env.ci-zig-version}}.tar.xz | tar xJ -C ~/deps' + - name: Save Zig Cache + if: steps.zig-cache.outputs.cache-hit != 'true' + uses: actions/cache/save@v4 + with: + path: ~/deps/zig-x86_64-macos-none-${{env.ci-zig-version}} + key: ${{steps.zig-cache.outputs.cache-primary-key}} + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Restore Package Cache + id: package-cache + uses: actions/cache/restore@v4 + with: + path: ~/.cache/zig + key: x86_64-macos-package-${{hashFiles('ci/build.zig.zon')}} + restore-keys: x86_64-macos-package- + - name: Build and Test + working-directory: ci + run: ~/deps/zig-x86_64-macos-none-${{env.ci-zig-version}}/bin/zig build -Dbuild-type=Debug -Dskip-non-native test-cmake-bootstrap update-stage1 + - name: Save Package Cache + if: steps.package-cache.outputs.cache-hit != 'true' + uses: actions/cache/save@v4 + with: + path: ~/.cache/zig + key: ${{steps.package-cache.outputs.cache-primary-key}} x86_64-macos-release: - runs-on: "macos-12" - env: - ARCH: "x86_64" + if: github.repository_owner == 'ziglang' + runs-on: macos-12 steps: + - name: Restore Zig Cache + id: zig-cache + uses: actions/cache/restore@v4 + with: + path: ~/deps/zig-x86_64-macos-none-${{env.ci-zig-version}} + key: zig-x86_64-macos-none-${{env.ci-zig-version}} + - name: Download Zig + if: steps.zig-cache.outputs.cache-hit != 'true' + run: 'mkdir -p ~/deps && curl https://jacobly.com/deps/zig-x86_64-macos-none-${{env.ci-zig-version}}.tar.xz | tar xJ -C ~/deps' + - name: Save Zig Cache + if: steps.zig-cache.outputs.cache-hit != 'true' + uses: actions/cache/save@v4 + with: + path: ~/deps/zig-x86_64-macos-none-${{env.ci-zig-version}} + key: ${{steps.zig-cache.outputs.cache-primary-key}} - name: Checkout uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Restore Package Cache + id: package-cache + uses: actions/cache/restore@v4 + with: + path: ~/.cache/zig + key: x86_64-macos-package-${{hashFiles('ci/build.zig.zon')}} + restore-keys: x86_64-macos-package- - name: Build and Test - run: ci/x86_64-macos-release.sh + working-directory: ci + run: ~/deps/zig-x86_64-macos-none-${{env.ci-zig-version}}/bin/zig build -Dbuild-type=Release -Dcc=cc -Dskip-non-native test-cc-bootstrap test-cmake-bootstrap reproducible update-stage1 + - name: Save Package Cache + if: steps.package-cache.outputs.cache-hit != 'true' + uses: actions/cache/save@v4 + with: + path: ~/.cache/zig + key: ${{steps.package-cache.outputs.cache-primary-key}} aarch64-macos-debug: + if: github.repository_owner == 'ziglang' runs-on: [self-hosted, macOS, aarch64] - env: - ARCH: "aarch64" steps: - name: Checkout uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Build and Test - run: ci/aarch64-macos-debug.sh + working-directory: ci + run: ~/deps/zig-aarch64-macos-none-${{env.ci-zig-version}}/bin/zig build -Dbuild-type=Debug -Dskip-non-native test-cmake-bootstrap update-stage1 aarch64-macos-release: + if: github.repository_owner == 'ziglang' runs-on: [self-hosted, macOS, aarch64] - env: - ARCH: "aarch64" steps: - name: Checkout uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Build and Test - run: ci/aarch64-macos-release.sh + working-directory: ci + run: ~/deps/zig-aarch64-macos-none-${{env.ci-zig-version}}/bin/zig build -Dbuild-type=Release -Dskip-non-native test-cmake-bootstrap reproducible update-stage1 x86_64-windows-debug: + if: github.repository_owner == 'ziglang' runs-on: [self-hosted, Windows, x86_64] - env: - ARCH: "x86_64" steps: - name: Checkout uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Build and Test - run: ci/x86_64-windows-debug.ps1 + working-directory: ci + run: '& $Env:USERPROFILE\deps\zig-x86_64-windows-gnu-${{env.ci-zig-version}}\bin\zig.exe build -Dbuild-type=Debug -Dskip-non-native test-cmake-bootstrap update-stage1 msvc' x86_64-windows-release: + if: github.repository_owner == 'ziglang' runs-on: [self-hosted, Windows, x86_64] - env: - ARCH: "x86_64" steps: - name: Checkout uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Build and Test - run: ci/x86_64-windows-release.ps1 - aarch64-windows: + working-directory: ci + run: '& $Env:USERPROFILE\deps\zig-x86_64-windows-gnu-${{env.ci-zig-version}}\bin\zig.exe build -Dbuild-type=Release -Dskip-non-native test-cmake-bootstrap update-stage1 msvc' # reproducible + aarch64-windows-release: + if: github.repository_owner == 'ziglang' runs-on: [self-hosted, Windows, aarch64] - env: - ARCH: "aarch64" steps: - name: Checkout uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Build and Test - run: ci/aarch64-windows.ps1 + working-directory: ci + run: '& $Env:USERPROFILE\deps\zig-aarch64-windows-gnu-${{env.ci-zig-version}}\bin\zig.exe build -Dbuild-type=Release -Dskip-non-native test-cmake-bootstrap' # reproducible diff --git a/CMakeLists.txt b/CMakeLists.txt index c074da9588..b766921178 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -944,10 +944,12 @@ set(ZIG_BUILD_ARGS if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") list(APPEND ZIG_BUILD_ARGS -Doptimize=Debug) +elseif("${CMAKE_BUILD_TYPE}" STREQUAL "Release") + list(APPEND ZIG_BUILD_ARGS -Doptimize=ReleaseFast -Dstrip) elseif("${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo") list(APPEND ZIG_BUILD_ARGS -Doptimize=ReleaseFast) -else() - list(APPEND ZIG_BUILD_ARGS -Doptimize=ReleaseFast -Dstrip) +elseif("${CMAKE_BUILD_TYPE}" STREQUAL "MinSizeRel") + list(APPEND ZIG_BUILD_ARGS -Doptimize=ReleaseSmall) endif() if(ZIG_STATIC AND NOT MSVC) diff --git a/ci/aarch64-linux-debug.sh b/ci/aarch64-linux-debug.sh deleted file mode 100644 index 7a7ae5e4b3..0000000000 --- a/ci/aarch64-linux-debug.sh +++ /dev/null @@ -1,100 +0,0 @@ -#!/bin/sh - -# Requires cmake ninja-build - -set -x -set -e - -ARCH="$(uname -m)" -TARGET="$ARCH-linux-musl" -MCPU="baseline" -CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.13.0-dev.130+98a30acad" -PREFIX="$HOME/deps/$CACHE_BASENAME" -ZIG="$PREFIX/bin/zig" - -export PATH="$HOME/deps/wasmtime-v10.0.2-$ARCH-linux:$PATH" - -# Make the `zig version` number consistent. -# This will affect the cmake command below. -git fetch --unshallow || true -git fetch --tags - -export CC="$ZIG cc -target $TARGET -mcpu=$MCPU" -export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU" - -rm -rf build-debug -mkdir build-debug -cd build-debug - -# Override the cache directories because they won't actually help other CI runs -# which will be testing alternate versions of zig, and ultimately would just -# fill up space on the hard drive for no reason. -export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache" -export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache" - -cmake .. \ - -DCMAKE_INSTALL_PREFIX="stage3-debug" \ - -DCMAKE_PREFIX_PATH="$PREFIX" \ - -DCMAKE_BUILD_TYPE=Debug \ - -DZIG_TARGET_TRIPLE="$TARGET" \ - -DZIG_TARGET_MCPU="$MCPU" \ - -DZIG_STATIC=ON \ - -DZIG_NO_LIB=ON \ - -GNinja - -# Now cmake will use zig as the C/C++ compiler. We reset the environment variables -# so that installation and testing do not get affected by them. -unset CC -unset CXX - -ninja install - -# simultaneously test building self-hosted without LLVM and with 32-bit arm -stage3-debug/bin/zig build \ - -Dtarget=arm-linux-musleabihf \ - -Dno-lib - -# TODO: add -fqemu back to this line -stage3-debug/bin/zig build test docs \ - --maxrss 24696061952 \ - -fwasmtime \ - -Dstatic-llvm \ - -Dtarget=native-native-musl \ - --search-prefix "$PREFIX" \ - --zig-lib-dir "$PWD/../lib" \ - -Denable-tidy - -# Ensure that updating the wasm binary from this commit will result in a viable build. -stage3-debug/bin/zig build update-zig1 - -rm -rf ../build-new -mkdir ../build-new -cd ../build-new - -export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache" -export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache" -export CC="$ZIG cc -target $TARGET -mcpu=$MCPU" -export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU" - -cmake .. \ - -DCMAKE_PREFIX_PATH="$PREFIX" \ - -DCMAKE_BUILD_TYPE=Debug \ - -DZIG_TARGET_TRIPLE="$TARGET" \ - -DZIG_TARGET_MCPU="$MCPU" \ - -DZIG_STATIC=ON \ - -DZIG_NO_LIB=ON \ - -GNinja - -unset CC -unset CXX - -ninja install - -stage3/bin/zig test ../test/behavior.zig -stage3/bin/zig build -p stage4 \ - -Dstatic-llvm \ - -Dtarget=native-native-musl \ - -Dno-lib \ - --search-prefix "$PREFIX" \ - --zig-lib-dir "$PWD/../lib" -stage4/bin/zig test ../test/behavior.zig diff --git a/ci/aarch64-linux-release.sh b/ci/aarch64-linux-release.sh deleted file mode 100644 index 04d4fb20b8..0000000000 --- a/ci/aarch64-linux-release.sh +++ /dev/null @@ -1,100 +0,0 @@ -#!/bin/sh - -# Requires cmake ninja-build - -set -x -set -e - -ARCH="$(uname -m)" -TARGET="$ARCH-linux-musl" -MCPU="baseline" -CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.13.0-dev.130+98a30acad" -PREFIX="$HOME/deps/$CACHE_BASENAME" -ZIG="$PREFIX/bin/zig" - -export PATH="$HOME/deps/wasmtime-v10.0.2-$ARCH-linux:$PATH" - -# Make the `zig version` number consistent. -# This will affect the cmake command below. -git fetch --unshallow || true -git fetch --tags - -export CC="$ZIG cc -target $TARGET -mcpu=$MCPU" -export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU" - -rm -rf build-release -mkdir build-release -cd build-release - -# Override the cache directories because they won't actually help other CI runs -# which will be testing alternate versions of zig, and ultimately would just -# fill up space on the hard drive for no reason. -export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache" -export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache" - -cmake .. \ - -DCMAKE_INSTALL_PREFIX="stage3-release" \ - -DCMAKE_PREFIX_PATH="$PREFIX" \ - -DCMAKE_BUILD_TYPE=Release \ - -DZIG_TARGET_TRIPLE="$TARGET" \ - -DZIG_TARGET_MCPU="$MCPU" \ - -DZIG_STATIC=ON \ - -DZIG_NO_LIB=ON \ - -GNinja - -# Now cmake will use zig as the C/C++ compiler. We reset the environment variables -# so that installation and testing do not get affected by them. -unset CC -unset CXX - -ninja install - -# simultaneously test building self-hosted without LLVM and with 32-bit arm -stage3-release/bin/zig build \ - -Dtarget=arm-linux-musleabihf \ - -Dno-lib - -# TODO: add -fqemu back to this line -stage3-release/bin/zig build test docs \ - --maxrss 24696061952 \ - -fwasmtime \ - -Dstatic-llvm \ - -Dtarget=native-native-musl \ - --search-prefix "$PREFIX" \ - --zig-lib-dir "$PWD/../lib" \ - -Denable-tidy - -# Ensure that updating the wasm binary from this commit will result in a viable build. -stage3-release/bin/zig build update-zig1 - -rm -rf ../build-new -mkdir ../build-new -cd ../build-new - -export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache" -export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache" -export CC="$ZIG cc -target $TARGET -mcpu=$MCPU" -export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU" - -cmake .. \ - -DCMAKE_PREFIX_PATH="$PREFIX" \ - -DCMAKE_BUILD_TYPE=Release \ - -DZIG_TARGET_TRIPLE="$TARGET" \ - -DZIG_TARGET_MCPU="$MCPU" \ - -DZIG_STATIC=ON \ - -DZIG_NO_LIB=ON \ - -GNinja - -unset CC -unset CXX - -ninja install - -stage3/bin/zig test ../test/behavior.zig -stage3/bin/zig build -p stage4 \ - -Dstatic-llvm \ - -Dtarget=native-native-musl \ - -Dno-lib \ - --search-prefix "$PREFIX" \ - --zig-lib-dir "$PWD/../lib" -stage4/bin/zig test ../test/behavior.zig diff --git a/ci/aarch64-macos-debug.sh b/ci/aarch64-macos-debug.sh deleted file mode 100755 index 9283321c1f..0000000000 --- a/ci/aarch64-macos-debug.sh +++ /dev/null @@ -1,58 +0,0 @@ -#!/bin/sh - -set -x -set -e - -# Script assumes the presence of the following: -# s3cmd - -ZIGDIR="$PWD" -TARGET="$ARCH-macos-none" -MCPU="baseline" -CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.13.0-dev.130+98a30acad" -PREFIX="$HOME/$CACHE_BASENAME" -ZIG="$PREFIX/bin/zig" - -if [ ! -d "$PREFIX" ]; then - cd $HOME - curl -L -O "https://ziglang.org/deps/$CACHE_BASENAME.tar.xz" - tar xf "$CACHE_BASENAME.tar.xz" -fi - -cd $ZIGDIR - -# Make the `zig version` number consistent. -# This will affect the cmake command below. -git fetch --unshallow || true -git fetch --tags - -rm -rf build-debug -mkdir build-debug -cd build-debug - -# Override the cache directories because they won't actually help other CI runs -# which will be testing alternate versions of zig, and ultimately would just -# fill up space on the hard drive for no reason. -export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache" -export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache" - -PATH="$HOME/local/bin:$PATH" cmake .. \ - -DCMAKE_INSTALL_PREFIX="stage3-debug" \ - -DCMAKE_PREFIX_PATH="$PREFIX" \ - -DCMAKE_BUILD_TYPE=Debug \ - -DCMAKE_C_COMPILER="$ZIG;cc;-target;$TARGET;-mcpu=$MCPU" \ - -DCMAKE_CXX_COMPILER="$ZIG;c++;-target;$TARGET;-mcpu=$MCPU" \ - -DZIG_TARGET_TRIPLE="$TARGET" \ - -DZIG_TARGET_MCPU="$MCPU" \ - -DZIG_STATIC=ON \ - -DZIG_NO_LIB=ON \ - -GNinja - -$HOME/local/bin/ninja install - -stage3-debug/bin/zig build test docs \ - --zig-lib-dir "$PWD/../lib" \ - -Denable-macos-sdk \ - -Dstatic-llvm \ - -Dskip-non-native \ - --search-prefix "$PREFIX" diff --git a/ci/aarch64-macos-release.sh b/ci/aarch64-macos-release.sh deleted file mode 100755 index 396aa1d464..0000000000 --- a/ci/aarch64-macos-release.sh +++ /dev/null @@ -1,74 +0,0 @@ -#!/bin/sh - -set -x -set -e - -# Script assumes the presence of the following: -# s3cmd - -ZIGDIR="$PWD" -TARGET="$ARCH-macos-none" -MCPU="baseline" -CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.13.0-dev.130+98a30acad" -PREFIX="$HOME/$CACHE_BASENAME" -ZIG="$PREFIX/bin/zig" - -if [ ! -d "$PREFIX" ]; then - cd $HOME - curl -L -O "https://ziglang.org/deps/$CACHE_BASENAME.tar.xz" - tar xf "$CACHE_BASENAME.tar.xz" -fi - -cd $ZIGDIR - -# Make the `zig version` number consistent. -# This will affect the cmake command below. -git fetch --unshallow || true -git fetch --tags - -rm -rf build-release -mkdir build-release -cd build-release - -# Override the cache directories because they won't actually help other CI runs -# which will be testing alternate versions of zig, and ultimately would just -# fill up space on the hard drive for no reason. -export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache" -export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache" - -PATH="$HOME/local/bin:$PATH" cmake .. \ - -DCMAKE_INSTALL_PREFIX="stage3-release" \ - -DCMAKE_PREFIX_PATH="$PREFIX" \ - -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_C_COMPILER="$ZIG;cc;-target;$TARGET;-mcpu=$MCPU" \ - -DCMAKE_CXX_COMPILER="$ZIG;c++;-target;$TARGET;-mcpu=$MCPU" \ - -DZIG_TARGET_TRIPLE="$TARGET" \ - -DZIG_TARGET_MCPU="$MCPU" \ - -DZIG_STATIC=ON \ - -DZIG_NO_LIB=ON \ - -GNinja - -$HOME/local/bin/ninja install - -stage3-release/bin/zig build test docs \ - --zig-lib-dir "$PWD/../lib" \ - -Denable-macos-sdk \ - -Dstatic-llvm \ - -Dskip-non-native \ - --search-prefix "$PREFIX" - -# Ensure that stage3 and stage4 are byte-for-byte identical. -stage3-release/bin/zig build \ - --prefix stage4-release \ - -Denable-llvm \ - -Dno-lib \ - -Doptimize=ReleaseFast \ - -Dstrip \ - -Dtarget=$TARGET \ - -Duse-zig-libcxx \ - -Dversion-string="$(stage3-release/bin/zig version)" - -# diff returns an error code if the files differ. -echo "If the following command fails, it means nondeterminism has been" -echo "introduced, making stage3 and stage4 no longer byte-for-byte identical." -diff stage3-release/bin/zig stage4-release/bin/zig diff --git a/ci/aarch64-windows.ps1 b/ci/aarch64-windows.ps1 deleted file mode 100644 index 8365ff285d..0000000000 --- a/ci/aarch64-windows.ps1 +++ /dev/null @@ -1,71 +0,0 @@ -$TARGET = "$($Env:ARCH)-windows-gnu" -$ZIG_LLVM_CLANG_LLD_NAME = "zig+llvm+lld+clang-$TARGET-0.13.0-dev.130+98a30acad" -$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" - -if (!(Test-Path "..\$ZIG_LLVM_CLANG_LLD_NAME.zip")) { - 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\..") -} - -function CheckLastExitCode { - if (!$?) { - exit 1 - } - return 0 -} - -# Make the `zig version` number consistent. -# This will affect the `zig build` command below which uses `git describe`. -git fetch --tags - -if ((git rev-parse --is-shallow-repository) -eq "true") { - git fetch --unshallow # `git describe` won't work on a shallow repo -} - -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' - -# Override the cache directories because they won't actually help other CI runs -# which will be testing alternate versions of zig, and ultimately would just -# fill up space on the hard drive for no reason. -$Env:ZIG_GLOBAL_CACHE_DIR="$(Get-Location)\zig-global-cache" -$Env:ZIG_LOCAL_CACHE_DIR="$(Get-Location)\zig-local-cache" - -# 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" ` - -DCMAKE_AR="$ZIG" ` - -DZIG_AR_WORKAROUND=ON ` - -DZIG_TARGET_TRIPLE="$TARGET" ` - -DZIG_TARGET_MCPU="$MCPU" ` - -DZIG_STATIC=ON ` - -DZIG_NO_LIB=ON -CheckLastExitCode - -ninja install -CheckLastExitCode - -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 diff --git a/ci/build.zig b/ci/build.zig new file mode 100644 index 0000000000..41c6552eff --- /dev/null +++ b/ci/build.zig @@ -0,0 +1,665 @@ +const std = @import("std"); + +pub fn build(b: *std.Build) void { + const host_target = b.standardTargetOptions(.{ + .whitelist = &.{ + .{ + .cpu_arch = .x86_64, + .cpu_model = .baseline, + .os_tag = .linux, + .abi = .musl, + }, + .{ + .cpu_arch = .aarch64, + .cpu_model = .baseline, + .os_tag = .linux, + .abi = .musl, + }, + .{ + .cpu_arch = .aarch64, + .cpu_model = .baseline, + .os_tag = .macos, + .abi = .none, + }, + .{ + .cpu_arch = .x86_64, + .cpu_model = .baseline, + .os_tag = .windows, + .abi = .gnu, + }, + .{ + .cpu_arch = .aarch64, + .cpu_model = .baseline, + .os_tag = .windows, + .abi = .gnu, + }, + }, + .default_target = .{ + .cpu_arch = b.graph.host.result.cpu.arch, + .cpu_model = .baseline, + .os_tag = b.graph.host.result.os.tag, + .abi = if (b.graph.host.result.os.tag == .windows) + .gnu + else if (b.graph.host.result.isDarwin()) + .none + else + .musl, + }, + }); + const host_triple = host_target.result.linuxTriple(b.allocator) catch @panic("OOM"); + const host_cpu = host_target.query.serializeCpuAlloc(b.allocator) catch @panic("OOM"); + const host_exe_file_ext = host_target.result.exeFileExt(); + const build_type = b.option(enum { None, Debug, Release, RelWithDebInfo, MinSizeRel }, "build-type", "CMake build type") orelse .Debug; + const tool_optimize = b.option( + std.builtin.OptimizeMode, + "tool-optimize", + "Prioritize performance, safety, or binary size for build tools", + ) orelse .ReleaseSafe; + + const binaryen_lazy_dep = if (host_target.result.cpu.arch != .aarch64 or host_target.result.os.tag != .windows) + b.lazyDependency(b.fmt("binaryen-{s}", .{host_triple}), .{}) + else + null; + const cmake_lazy_dep = b.lazyDependency(b.fmt("cmake-{s}", .{host_triple}), .{}); + const ninja_lazy_dep = b.lazyDependency(b.fmt("ninja-{s}", .{host_triple}), .{}); + const qemu_lazy_dep = if (host_target.result.cpu.arch == .x86_64 and host_target.result.os.tag == .linux) + b.lazyDependency(b.fmt("qemu-{s}", .{host_triple}), .{}) + else + null; + const tidy_lazy_dep = b.lazyDependency(b.fmt("tidy-{s}", .{host_triple}), .{}); + const wasmtime_lazy_dep = if (host_target.result.cpu.arch != .aarch64 or host_target.result.os.tag != .windows) + b.lazyDependency(b.fmt("wasmtime-{s}", .{host_triple}), .{}) + else + null; + const zig_llvm_lld_clang_lazy_dep = + b.lazyDependency(b.fmt("zig+llvm+lld+clang-{s}", .{host_triple}), .{}); + + const cmake_dep = cmake_lazy_dep orelse return; + const ninja_dep = ninja_lazy_dep orelse return; + const zig_llvm_lld_clang_dep = zig_llvm_lld_clang_lazy_dep orelse return; + + const cmake_exe = cmake_dep.path(b.fmt("{s}bin/cmake{s}", .{ + if (host_target.result.isDarwin()) "CMake.app/Contents/" else "", + host_exe_file_ext, + })); + const ninja_exe = ninja_dep.path(b.fmt("ninja{s}", .{host_exe_file_ext})); + + const build_file = b.path("../build.zig"); + const local_cache_dir = b.path(".zig-local-cache"); + const global_cache_dir = b.path(".zig-global-cache"); + + const clean_step = b.step("clean", "Cleanup previous CI runs"); + clean_step.dependOn(&b.addRemoveDirTree(b.cache_root.path orelse ".").step); + clean_step.dependOn(&b.addRemoveDirTree(b.pathFromRoot("../.zig-cache")).step); + clean_step.dependOn(&b.addRemoveDirTree(local_cache_dir.getPath(b)).step); + clean_step.dependOn(&b.addRemoveDirTree(global_cache_dir.getPath(b)).step); + + const run_exe = b.addExecutable(.{ + .name = "run", + .root_source_file = b.path("run.zig"), + .target = host_target, + .optimize = tool_optimize, + .strip = false, + }); + run_exe.step.max_rss = 281_214_976; + + const run_chmod_step = if (host_target.result.isDarwin()) steps: { + const chmod_exe = b.addExecutable(.{ + .name = "chmod", + .root_source_file = b.path("chmod.zig"), + .target = host_target, + .optimize = tool_optimize, + .strip = false, + }); + chmod_exe.step.max_rss = 267_157_504; + + const run_chmod = b.addRunArtifact(chmod_exe); + run_chmod.step.max_rss = 1_212_416; + if (binaryen_lazy_dep) |binaryen_dep| for ([_][]const u8{ + "binaryen-unittests", + "wasm2js", + "wasm-as", + "wasm-ctor-eval", + "wasm-dis", + "wasm-emscripten-finalize", + "wasm-fuzz-lattices", + "wasm-fuzz-types", + "wasm-merge", + "wasm-metadce", + "wasm-opt", + "wasm-reduce", + "wasm-shell", + "wasm-split", + }) |exe| run_chmod.addFileArg(binaryen_dep.path(b.fmt("bin/{s}{s}", .{ exe, host_exe_file_ext }))); + run_chmod.addFileArg(cmake_exe); + run_chmod.addFileArg(ninja_exe); + if (qemu_lazy_dep) |qemu_dep| for ([_][]const u8{ + "cris", + "mips64el", + "ppc64", + "loongarch64", + "sparc", + "aarch64", + "sparc64", + "alpha", + "sparc32plus", + "sh4", + "hexagon", + "xtensaeb", + "riscv64", + "aarch64_be", + "i386", + "armeb", + "mips", + "s390x", + "mips64", + "ppc64le", + "mipsel", + "x86_64", + "arm", + "hppa", + "ppc", + "or1k", + "xtensa", + "microblaze", + "riscv32", + "m68k", + "sh4eb", + "mipsn32el", + "nios2", + "microblazeel", + "mipsn32", + }) |qemu_target| run_chmod.addFileArg(qemu_dep.path(b.fmt("bin/qemu-{s}{s}", .{ qemu_target, host_exe_file_ext }))); + if (tidy_lazy_dep) |tidy_dep| run_chmod.addFileArg(tidy_dep.path(b.fmt("bin/tidy{s}", .{host_exe_file_ext}))); + if (wasmtime_lazy_dep) |wasmtime_dep| run_chmod.addFileArg(wasmtime_dep.path(b.fmt("wasmtime{s}", .{host_exe_file_ext}))); + run_chmod.addFileArg(zig_llvm_lld_clang_dep.path(b.fmt("bin/zig{s}", .{host_exe_file_ext}))); + + break :steps &run_chmod.step; + } else null; + + const build_cc_stage2_step = if (b.option( + []const u8, + "cc", + "System C compiler to use for cc bootstrap", + )) |cc| steps: { + const cc_bootstrap_step = b.step("cc-bootstrap", "build cc bootstrap"); + const test_cc_bootstrap_step = b.step("test-cc-bootstrap", "test cc bootstrap"); + + const build_bootstrap = b.addSystemCommand(&.{ cc, "-o" }); + build_bootstrap.step.max_rss = 94_011_392; + const bootstrap_exe = build_bootstrap.addOutputFileArg("bootstrap"); + build_bootstrap.addArgs(&.{ "-MD", "-MF" }); + _ = build_bootstrap.addDepFileOutputArg("bootstrap.d"); + build_bootstrap.addFileArg(b.path("../bootstrap.c")); + build_bootstrap.setCwd(b.path("..")); + + const build_stage2 = std.Build.Step.Run.create(b, "build cc bootstrap"); + build_stage2.step.max_rss = 5_953_224_704; + build_stage2.addArtifactArg(run_exe); + build_stage2.addArgs(&.{ + "$0", + "--delete", + "zig-wasm2c", + "zig1.c", + "zig1", + "config.zig", + "zig2.c", + "compiler_rt.c", + "--rename", + "zig2", + "$1", + "--", + }); + build_stage2.addFileArg(bootstrap_exe); + const stage2_exe = build_stage2.addOutputFileArg("zig2"); + build_stage2.setEnvironmentVariable("CC", cc); + build_stage2.setCwd(b.path("..")); + + const build_stage3 = std.Build.Step.Run.create(b, "build cc bootstrap"); + build_stage3.step.max_rss = 736_362_496; + build_stage3.addFileArg(stage2_exe); + build_stage3.addArgs(&.{ + "build", + "--maxrss", + b.fmt("{}", .{@max(build_stage3.step.max_rss, 7_000_000_000)}), + "--build-file", + }); + build_stage3.addFileArg(build_file); + build_stage3.addArg("--prefix"); + const stage3_out = build_stage3.addOutputDirectoryArg("stage3"); + build_stage3.addArg("--cache-dir"); + build_stage3.addDirectoryArg(local_cache_dir); + build_stage3.addArg("--global-cache-dir"); + build_stage3.addDirectoryArg(global_cache_dir); + build_stage3.addArg("-Dno-lib"); + + cc_bootstrap_step.dependOn(&b.addInstallDirectory(.{ + .source_dir = stage3_out, + .install_dir = .prefix, + .install_subdir = "cc", + }).step); + const stage3_exe = stage3_out.path(b, b.fmt("bin/zig{s}", .{host_exe_file_ext})); + + const run_tests = std.Build.Step.Run.create(b, "test cc bootstrap (stage3)"); + run_tests.step.max_rss = 451_231_744; + run_tests.addFileArg(stage3_exe); + run_tests.addArg("test"); + run_tests.addFileArg(b.path("../test/behavior.zig")); + test_cc_bootstrap_step.dependOn(&run_tests.step); + + break :steps &build_stage2.step; + } else null; + + { + const cmake_bootstrap_step = b.step("cmake-bootstrap", "build cmake bootstrap"); + const test_cmake_bootstrap_step = b.step("test-cmake-bootstrap", "test cmake bootstrap"); + + const build_stage3 = std.Build.Step.Run.create(b, "build cmake bootstrap"); + build_stage3.step.max_rss = 10_620_571_648; + build_stage3.addArtifactArg(run_exe); + build_stage3.addArgs(&.{ + "$4", + "-GNinja", + "-S..", + "-B$6", + "-DCMAKE_MAKE_PROGRAM=$5", + "-DCMAKE_BUILD_TYPE=$2", + "-DCMAKE_PREFIX_PATH=$7", + "-DCMAKE_C_COMPILER=$7/bin/zig$3;cc;-target;$0;-mcpu=$1", + "-DCMAKE_CXX_COMPILER=$7/bin/zig$3;c++;-target;$0;-mcpu=$1", + "-DCMAKE_AR=$7/bin/zig$3", + "-DZIG_AR_WORKAROUND=ON", + "-DZIG_TARGET_TRIPLE=$0", + "-DZIG_TARGET_MCPU=$1", + "-DZIG_STATIC=ON", + "-DZIG_STATIC_CURSES=OFF", + "-DZIG_NO_LIB=ON", + "--then", + "$5", + "-C", + "$6", + "install", + "--", + host_triple, + host_cpu, + @tagName(build_type), + host_exe_file_ext, + }); + build_stage3.addFileArg(cmake_exe); + build_stage3.addFileArg(ninja_exe); + const stage3_out = build_stage3.addOutputDirectoryArg("build").path(b, "stage3"); + build_stage3.addDirectoryArg(zig_llvm_lld_clang_dep.path("")); + build_stage3.addFileInput(b.path("../stage1/zig1.wasm")); + build_stage3.addFileInput(b.path("../stage1/zig.h")); + if (run_chmod_step) |step| build_stage3.step.dependOn(step); + + cmake_bootstrap_step.dependOn(&b.addInstallDirectory(.{ + .source_dir = stage3_out, + .install_dir = .prefix, + .install_subdir = "cmake", + }).step); + const stage3_exe = stage3_out.path(b, b.fmt("bin/zig{s}", .{host_exe_file_ext})); + + const run_tests = std.Build.Step.Run.create(b, "test cmake bootstrap (stage3)"); + run_tests.step.max_rss = 12_676_628_480; + run_tests.addArtifactArg(run_exe); + run_tests.addArgs(&.{ + "$0", + "build", + "$--maxrss", + b.fmt("{}", .{run_tests.step.max_rss}), + "$--build-file", + "$1", + "$--prefix", + "$2", + "$--cache-dir", + "$3", + "$--global-cache-dir", + "$4", + "test-fmt", + "test", + "docs", + "-Dstatic-llvm", + "$--search-prefix", + "$5", + }); + if (host_target.result.isDarwin()) run_tests.addArg("-Denable-macos-sdk"); + if (host_target.result.os.tag == .windows) run_tests.addArgs(&.{"-Denable-symlinks-windows"}); + if (b.option(bool, "skip-non-native", "Skip non-native tests") orelse false) + run_tests.addArg("-Dskip-non-native"); + if (qemu_lazy_dep) |_| run_tests.addArg("-fqemu"); + if (tidy_lazy_dep) |_| run_tests.addArg("-Denable-tidy"); + if (wasmtime_lazy_dep) |_| run_tests.addArg("-fwasmtime"); + run_tests.addArg("--path"); + { + var index: usize = 6; + for ([_]?*std.Build.Dependency{ + qemu_lazy_dep, + tidy_lazy_dep, + wasmtime_lazy_dep, + }) |maybe_dep| if (maybe_dep) |_| { + run_tests.addArg(b.fmt("${}", .{index})); + index += 1; + }; + } + run_tests.addArg("--"); + run_tests.addFileArg(stage3_exe); + run_tests.addFileArg(build_file); + _ = run_tests.addOutputDirectoryArg("tests"); + run_tests.addDirectoryArg(local_cache_dir); + run_tests.addDirectoryArg(global_cache_dir); + run_tests.addDirectoryArg(zig_llvm_lld_clang_dep.path("")); + if (qemu_lazy_dep) |qemu_dep| run_tests.addDirectoryArg(qemu_dep.path("bin")); + if (tidy_lazy_dep) |tidy_dep| run_tests.addDirectoryArg(tidy_dep.path("bin")); + if (wasmtime_lazy_dep) |wasmtime_dep| run_tests.addDirectoryArg(wasmtime_dep.path("")); + if (run_chmod_step) |step| run_tests.step.dependOn(step); + test_cmake_bootstrap_step.dependOn(&run_tests.step); + + for (b.option([]const []const u8, "extra-target", "Extra targets to build") orelse &.{}) |build_target| { + const build_stage4 = std.Build.Step.Run.create(b, "build"); + build_stage4.step.max_rss = 4_483_489_792; + build_stage4.addFileArg(stage3_exe); + build_stage4.addArgs(&.{ + "build", + "--maxrss", + b.fmt("{}", .{@max(build_stage4.step.max_rss, 7_000_000_000)}), + "--build-file", + }); + build_stage4.addFileArg(build_file); + build_stage4.addArg("--prefix"); + _ = build_stage4.addOutputDirectoryArg(b.fmt("stage4-{s}", .{build_target})); + build_stage4.addArg("--cache-dir"); + build_stage4.addDirectoryArg(local_cache_dir); + build_stage4.addArg("--global-cache-dir"); + build_stage4.addDirectoryArg(global_cache_dir); + build_stage4.addArgs(&.{ b.fmt("-Dtarget={s}", .{build_target}), "-Dno-lib" }); + test_cmake_bootstrap_step.dependOn(&build_stage4.step); + } + + switch (build_type) { + .None, .Debug, .RelWithDebInfo, .MinSizeRel => {}, + .Release => { + const reproducible_step = b.step("reproducible", "Ensure that stage3 and stage4 are byte-for-byte identical"); + + const run_stage3_version = std.Build.Step.Run.create(b, "get stage3 version"); + run_stage3_version.step.max_rss = 40_452_096; + run_stage3_version.addFileArg(stage3_exe); + run_stage3_version.addArg("version"); + const stage3_version = run_stage3_version.captureStdOut(); + + const build_stage4 = b.addRunArtifact(run_exe); + build_stage4.step.max_rss = 4_361_846_784; + build_stage4.addArgs(&.{ + "$2", + "build", + "$--maxrss", + b.fmt("{}", .{@max(build_stage4.step.max_rss, 7_000_000_000)}), + "$--build-file", + "$3", + "$--prefix", + "$4", + "$--cache-dir", + "$5", + "$--global-cache-dir", + "$6", + "-Denable-llvm", + "-Dno-lib", + "-Doptimize=ReleaseFast", + "-Dstrip", + "-Dtarget=$0", + "-Dcpu=$1", + "-Duse-zig-libcxx", + "-Dversion-string=@7", + "--", + host_triple, + host_cpu, + }); + build_stage4.addFileArg(stage3_exe); + build_stage4.addFileArg(build_file); + const stage4_prefix = build_stage4.addOutputDirectoryArg("stage4"); + build_stage4.addDirectoryArg(local_cache_dir); + build_stage4.addDirectoryArg(global_cache_dir); + build_stage4.addFileArg(stage3_version); + + const cmp_exe = b.addExecutable(.{ + .name = "cmp", + .root_source_file = b.path("cmp.zig"), + .target = host_target, + .optimize = tool_optimize, + .strip = false, + }); + cmp_exe.step.max_rss = 267_403_264; + + const run_cmp = std.Build.Step.Run.create(b, "Check stage3 and stage4 are byte-for-byte identical"); + run_cmp.step.max_rss = 8_495_104; + run_cmp.addArtifactArg(cmp_exe); + run_cmp.addFileArg(stage3_exe); + run_cmp.addFileArg(stage4_prefix.path(b, b.fmt("bin/zig{s}", .{host_exe_file_ext}))); + reproducible_step.dependOn(&run_cmp.step); + }, + } + + if (binaryen_lazy_dep) |binaryen_dep| { + const update_stage1_step = b.step("update-stage1", "Test bootstrap after updating the stage1 wasm binary"); + + const update_zig1 = std.Build.Step.Run.create(b, "update zig1"); + update_zig1.step.max_rss = 1_815_281_664; + update_zig1.addArtifactArg(run_exe); + update_zig1.addArgs(&.{ + "$0", + "build", + "$--maxrss", + b.fmt("{}", .{@max(update_zig1.step.max_rss, 7_000_000_000)}), + "$--build-file", + "$1", + "$--cache-dir", + "$2", + "$--global-cache-dir", + "$3", + "update-zig1", + "--path", + "$4", + "--", + }); + update_zig1.addFileArg(stage3_exe); + update_zig1.addFileArg(build_file); + update_zig1.addDirectoryArg(local_cache_dir); + update_zig1.addDirectoryArg(global_cache_dir); + update_zig1.addDirectoryArg(binaryen_dep.path("bin")); + if (run_chmod_step) |step| update_zig1.step.dependOn(step); + // Clobbering stage1 depends on all steps that use the original stage1 + if (build_cc_stage2_step) |step| update_zig1.step.dependOn(step); + update_zig1.step.dependOn(&build_stage3.step); + + const build_updated_stage3 = std.Build.Step.Run.create(b, "build updated cmake bootstrap"); + build_updated_stage3.step.max_rss = 10_600_501_248; + build_updated_stage3.addArtifactArg(run_exe); + build_updated_stage3.addArgs(&.{ + "$4", + "-GNinja", + "-S..", + "-B$6", + "-DCMAKE_MAKE_PROGRAM=$5", + "-DCMAKE_BUILD_TYPE=$2", + "-DCMAKE_PREFIX_PATH=$7", + "-DCMAKE_C_COMPILER=$7/bin/zig$3;cc;-target;$0;-mcpu=$1", + "-DCMAKE_CXX_COMPILER=$7/bin/zig$3;c++;-target;$0;-mcpu=$1", + "-DCMAKE_AR=$7/bin/zig$3", + "-DZIG_AR_WORKAROUND=ON", + "-DZIG_TARGET_TRIPLE=$0", + "-DZIG_TARGET_MCPU=$1", + "-DZIG_STATIC=ON", + "-DZIG_STATIC_CURSES=OFF", + "-DZIG_NO_LIB=ON", + "--then", + "$5", + "-C", + "$6", + "install", + "--", + host_triple, + host_cpu, + @tagName(build_type), + host_exe_file_ext, + }); + build_updated_stage3.addFileArg(cmake_exe); + build_updated_stage3.addFileArg(ninja_exe); + const updated_stage3_exe = build_updated_stage3.addOutputDirectoryArg("build") + .path(b, b.fmt("stage3/bin/zig{s}", .{host_exe_file_ext})); + build_updated_stage3.addDirectoryArg(zig_llvm_lld_clang_dep.path("")); + build_updated_stage3.addFileInput(b.path("../stage1/zig1.wasm")); + build_updated_stage3.addFileInput(b.path("../stage1/zig.h")); + if (run_chmod_step) |step| build_updated_stage3.step.dependOn(step); + build_updated_stage3.step.dependOn(&update_zig1.step); + + const build_updated_stage4 = b.addRunArtifact(run_exe); + build_updated_stage4.step.max_rss = 4_499_849_216; + build_updated_stage4.addArgs(&.{ + "$2", + "build", + "$--maxrss", + b.fmt("{}", .{@max(build_updated_stage4.step.max_rss, 7_000_000_000)}), + "$--build-file", + "$3", + "$--prefix", + "$4", + "$--cache-dir", + "$5", + "$--global-cache-dir", + "$6", + "-Denable-llvm", + "-Dno-lib", + "-Doptimize=ReleaseFast", + "-Dstrip", + "-Dtarget=$0", + "-Dcpu=$1", + "-Duse-zig-libcxx", + "--", + host_triple, + host_cpu, + }); + build_updated_stage4.addFileArg(updated_stage3_exe); + build_updated_stage4.addFileArg(build_file); + const updated_stage4_prefix = build_updated_stage4.addOutputDirectoryArg("stage4"); + build_updated_stage4.addDirectoryArg(local_cache_dir); + build_updated_stage4.addDirectoryArg(global_cache_dir); + + const run_tests_with_updated_stage4 = std.Build.Step.Run.create(b, "test updated cmake bootstrap (stage3)"); + run_tests_with_updated_stage4.step.max_rss = 696_287_232; + run_tests_with_updated_stage4.addFileArg(updated_stage4_prefix.path(b, b.fmt("bin/zig{s}", .{host_exe_file_ext}))); + run_tests_with_updated_stage4.addArg("test"); + run_tests_with_updated_stage4.addFileArg(b.path("../test/behavior.zig")); + update_stage1_step.dependOn(&run_tests_with_updated_stage4.step); + } + + msvc: { + const msvc_target = target: { + var target = host_target.result; + target.abi = .msvc; + break :target target; + }; + const libc = std.zig.LibCDirs.detect( + b.allocator, + b.pathFromRoot("../lib"), + msvc_target, + true, + true, + null, + ) catch |err| switch (err) { + error.WindowsSdkNotFound => break :msvc, + else => |e| @panic(@errorName(e)), + }; + const msvc_arch = switch (host_target.result.cpu.arch) { + .x86 => "x86", + .x86_64 => "x64", + .arm, .armeb, .thumb, .thumbeb => "arm", + .aarch64 => "arm64", + else => break :msvc, + }; + const cl_exe = b.pathResolve(&.{ + (libc.libc_installation orelse break :msvc).msvc_lib_dir orelse break :msvc, + "..", + "..", + "bin", + b.fmt("Host{s}", .{msvc_arch}), + msvc_arch, + b.fmt("cl{s}", .{host_exe_file_ext}), + }); + const msvc_triple = msvc_target.linuxTriple(b.allocator) catch @panic("OOM"); + + const msvc_step = b.step("msvc", "Run the behavior tests compiled with MSVC"); + + const build_msvc_behavior_tests = std.Build.Step.Run.create(b, "build msvc behavior tests"); + build_msvc_behavior_tests.step.max_rss = 213_237_760; + build_msvc_behavior_tests.addFileArg(stage3_exe); + build_msvc_behavior_tests.addArgs(&.{ + "test", + "-ofmt=c", + "--test-no-exec", + "-target", + msvc_triple, + "-lc", + }); + build_msvc_behavior_tests.addFileArg(b.path("../test/behavior.zig")); + const behavior_msvc_source = + build_msvc_behavior_tests.addPrefixedOutputFileArg("-femit-bin=", "behavior-msvc.c"); + + const build_msvc_compiler_rt = std.Build.Step.Run.create(b, "build msvc compiler-rt"); + build_msvc_compiler_rt.step.max_rss = 217_788_416; + build_msvc_compiler_rt.addFileArg(stage3_exe); + build_msvc_compiler_rt.addArgs(&.{ + "build-obj", + "-ofmt=c", + "-OReleaseSmall", + "--name", + "compiler_rt", + "-target", + msvc_triple, + "-lc", + }); + build_msvc_compiler_rt.addFileArg(b.path("../lib/compiler_rt.zig")); + const compiler_rt_msvc_source = + build_msvc_compiler_rt.addPrefixedOutputFileArg("-femit-bin=", "compiler_rt-msvc.c"); + + const build_msvc_tests = std.Build.Step.Run.create(b, "build msvc tests"); + build_msvc_tests.step.max_rss = 599_506_944; + build_msvc_tests.addArgs(&.{ cl_exe, "/W3", "/Z7" }); + build_msvc_tests.addPrefixedDirectoryArg("/I", b.path("../lib")); + build_msvc_tests.addFileArg(behavior_msvc_source); + build_msvc_tests.addFileArg(compiler_rt_msvc_source); + const msvc_tests_exe = build_msvc_tests.addPrefixedOutputFileArg( + "/Fe:", + b.fmt("behavior-msvc{s}", .{host_exe_file_ext}), + ); + // Link args must appear after all other args. + build_msvc_tests.addArgs(&.{ + "/link", + "/nologo", + "/debug", + "/subsystem:console", + "kernel32.lib", + "ntdll.lib", + "libcmt.lib", + }); + build_msvc_tests.setEnvironmentVariable("INCLUDE", std.mem.join( + b.allocator, + &.{std.fs.path.delimiter}, + libc.libc_include_dir_list, + ) catch @panic("OOM")); + build_msvc_tests.setEnvironmentVariable("LIB", std.mem.join( + b.allocator, + &.{std.fs.path.delimiter}, + &.{ + libc.libc_installation.?.msvc_lib_dir.?, + libc.libc_installation.?.crt_dir.?, + libc.libc_installation.?.kernel32_lib_dir.?, + }, + ) catch @panic("OOM")); + + const run_msvc_tests = std.Build.Step.Run.create(b, "run msvc tests"); + run_msvc_tests.step.max_rss = 6_574_080; + run_msvc_tests.addFileArg(msvc_tests_exe); + msvc_step.dependOn(&run_msvc_tests.step); + } + } +} diff --git a/ci/build.zig.zon b/ci/build.zig.zon new file mode 100644 index 0000000000..f400879396 --- /dev/null +++ b/ci/build.zig.zon @@ -0,0 +1,188 @@ +.{ + .name = "zig/ci", + .version = "0.0.0", + .paths = .{""}, + .dependencies = .{ + .@"binaryen-x86_64-linux-musl" = .{ + .hash = "12207d5dd577b7cc822cc007bdc06411fac7f536243afff77f6a181df1987f99b610", + .url = "https://github.com/WebAssembly/binaryen/releases/download/version_117/binaryen-version_117-x86_64-linux.tar.gz", + .lazy = true, + }, + .@"binaryen-aarch64-linux-musl" = .{ + .hash = "12207fa9d8edc6d3cb3e56ad5df7ed6205bea4a0712946d1115689ec4e8b6c6013c7", + .url = "https://github.com/WebAssembly/binaryen/releases/download/version_117/binaryen-version_117-aarch64-linux.tar.gz", + .lazy = true, + }, + .@"binaryen-x86_64-macos-none" = .{ + .hash = "12207e36613e24971953f70ee13654f5b91a279f95f71c930702ba913878b19a91d3", + .url = "https://github.com/WebAssembly/binaryen/releases/download/version_117/binaryen-version_117-x86_64-macos.tar.gz", + .lazy = true, + }, + .@"binaryen-aarch64-macos-none" = .{ + .hash = "122042c3690f6a477febcb4c68568c03bd3409c517e0d9037e06010fff003a4efcc0", + .url = "https://github.com/WebAssembly/binaryen/releases/download/version_117/binaryen-version_117-arm64-macos.tar.gz", + .lazy = true, + }, + .@"binaryen-x86_64-windows-gnu" = .{ + .hash = "122046d1b9b8e32c6198520178862b2079ffd2021a03a1f5f8dd6f5b474672dd0217", + .url = "https://github.com/WebAssembly/binaryen/releases/download/version_117/binaryen-version_117-x86_64-windows.tar.gz", + .lazy = true, + }, + + .@"cmake-x86_64-linux-musl" = .{ + .hash = "1220e08f2db1f68d20caeb41d923d1e468ef53e0973d02c1a00c2d517b011e121c40", + .url = "https://github.com/Kitware/CMake/releases/download/v3.29.2/cmake-3.29.2-linux-x86_64.tar.gz", + .lazy = true, + }, + .@"cmake-aarch64-linux-musl" = .{ + .hash = "1220a16a663bb2be43a236cb945bac8957be27c6edac8f630e81123fc99f7b2b2de9", + .url = "https://github.com/Kitware/CMake/releases/download/v3.29.2/cmake-3.29.2-linux-aarch64.tar.gz", + .lazy = true, + }, + .@"cmake-x86_64-macos-none" = .{ + .hash = "1220d158a5c05cfa2f20d339ec5503c79e96d61a21fe81fd6710c815f2cdcf6e3da0", + .url = "https://github.com/Kitware/CMake/releases/download/v3.29.2/cmake-3.29.2-macos-universal.tar.gz", + .lazy = true, + }, + .@"cmake-aarch64-macos-none" = .{ + .hash = "1220d158a5c05cfa2f20d339ec5503c79e96d61a21fe81fd6710c815f2cdcf6e3da0", + .url = "https://github.com/Kitware/CMake/releases/download/v3.29.2/cmake-3.29.2-macos-universal.tar.gz", + .lazy = true, + }, + .@"cmake-x86_64-windows-gnu" = .{ + .hash = "12204ff75c21a274e8d4803b77d4699d37f42974d039e398b28cdea7ea2cc1fa3376", + .url = "https://github.com/Kitware/CMake/releases/download/v3.29.2/cmake-3.29.2-windows-x86_64.zip", + .lazy = true, + }, + .@"cmake-aarch64-windows-gnu" = .{ + .hash = "12201d1c55e49eecfcbcf0347af9edc4396c2f3a12ab682f3da61d6f310b617753a2", + .url = "https://github.com/Kitware/CMake/releases/download/v3.29.2/cmake-3.29.2-windows-arm64.zip", + .lazy = true, + }, + + .@"ninja-x86_64-linux-musl" = .{ + .hash = "12206a681b6a380e8b380120f8c4e6688bc67b587b01091b019d722f74dca33ad012", + .url = "https://github.com/ninja-build/ninja/releases/download/v1.12.0/ninja-linux.zip", + .lazy = true, + }, + .@"ninja-aarch64-linux-musl" = .{ + .hash = "1220480757926ac5ade22fc2a4b39bde33e03480eb0d5e7087474ca4b81b8426e6b6", + .url = "https://github.com/ninja-build/ninja/releases/download/v1.12.0/ninja-linux-aarch64.zip", + .lazy = true, + }, + .@"ninja-x86_64-macos-none" = .{ + .hash = "1220978a9f52d9dff7614814ec52381aa709ea63a333249549c02f0b917c65733f5a", + .url = "https://github.com/ninja-build/ninja/releases/download/v1.12.0/ninja-mac.zip", + .lazy = true, + }, + .@"ninja-aarch64-macos-none" = .{ + .hash = "1220978a9f52d9dff7614814ec52381aa709ea63a333249549c02f0b917c65733f5a", + .url = "https://github.com/ninja-build/ninja/releases/download/v1.12.0/ninja-mac.zip", + .lazy = true, + }, + .@"ninja-x86_64-windows-gnu" = .{ + .hash = "1220543c9071fd6d5f16d2d5a64473cf252266b2928f9947c3b87a87de6d983724df", + .url = "https://github.com/ninja-build/ninja/releases/download/v1.12.0/ninja-win.zip", + .lazy = true, + }, + .@"ninja-aarch64-windows-gnu" = .{ + .hash = "12207d071c13ee8539a3445ea198243c12c917492411c3e7dfd8b54ff1714d759a73", + .url = "https://github.com/ninja-build/ninja/releases/download/v1.12.0/ninja-winarm64.zip", + .lazy = true, + }, + + .@"qemu-x86_64-linux-musl" = .{ + .hash = "122077e46a30ef6fee9b98aedc50bc613a5d37c038d2ac823445951d1cd8bbc0e162", + .url = "https://ziglang.org/deps/qemu-linux-x86_64-8.2.1.tar.xz", + .lazy = true, + }, + + .@"tidy-x86_64-linux-musl" = .{ + .hash = "1220b07c11837da15ae5f44201327cf3a1d554c650b384429f48d8234be8942ddc9d", + .url = "https://github.com/jacobly0/zig-tidy/releases/download/5.8.0/tidy-5.8.0-x86_64-linux-musl.tar.xz", + .lazy = true, + }, + .@"tidy-aarch64-linux-musl" = .{ + .hash = "122006a2ede0400f00789abe48e47861e5bbab7f8ca16789db4bd9e351299c4ac590", + .url = "https://github.com/jacobly0/zig-tidy/releases/download/5.8.0/tidy-5.8.0-aarch64-linux-musl.tar.xz", + .lazy = true, + }, + .@"tidy-x86_64-macos-none" = .{ + .hash = "1220f18256987f627618a21fde39f3cda13ac7bd6f01f35c9ccbb9e07ea81ca77cfc", + .url = "https://github.com/jacobly0/zig-tidy/releases/download/5.8.0/tidy-5.8.0-x86_64-macos-none.tar.xz", + .lazy = true, + }, + .@"tidy-aarch64-macos-none" = .{ + .hash = "1220a8ee39addf48e3be546616fe14853e3db1cb49522bd90a24bade371330176826", + .url = "https://github.com/jacobly0/zig-tidy/releases/download/5.8.0/tidy-5.8.0-aarch64-macos-none.tar.xz", + .lazy = true, + }, + .@"tidy-x86_64-windows-gnu" = .{ + .hash = "12205c2cb107a59e552947a51a302296912bd097fcf1414e9a7521ce8ededb915574", + .url = "https://github.com/jacobly0/zig-tidy/releases/download/5.8.0/tidy-5.8.0-x86_64-windows-gnu.zip", + .lazy = true, + }, + .@"tidy-aarch64-windows-gnu" = .{ + .hash = "1220dce14dc654e391c06c7e1d5b078355195286350cb8cab8e1f21f3a08df716736", + .url = "https://github.com/jacobly0/zig-tidy/releases/download/5.8.0/tidy-5.8.0-aarch64-windows-gnu.zip", + .lazy = true, + }, + + .@"wasmtime-x86_64-linux-musl" = .{ + .hash = "122062e8c3f052636b68b60f096eab11618a010ee67e5ec772d5c41362e471c30607", + .url = "https://github.com/bytecodealliance/wasmtime/releases/download/v13.0.1/wasmtime-v13.0.1-x86_64-linux.tar.xz", + .lazy = true, + }, + .@"wasmtime-aarch64-linux-musl" = .{ + .hash = "122069362558cae6da16d5de27a23b793bcd604bbbeb908ee8af25a1f9e48ce0d87b", + .url = "https://github.com/bytecodealliance/wasmtime/releases/download/v13.0.1/wasmtime-v13.0.1-aarch64-linux.tar.xz", + .lazy = true, + }, + .@"wasmtime-x86_64-macos-none" = .{ + .hash = "12205fbb7d93b7e41f74565b1b8df5862834d5b8e1676ad9d5814127f8ea79c6d923", + .url = "https://github.com/bytecodealliance/wasmtime/releases/download/v13.0.1/wasmtime-v13.0.1-x86_64-macos.tar.xz", + .lazy = true, + }, + .@"wasmtime-aarch64-macos-none" = .{ + .hash = "122021a51bda85da636583101f1815432b4b421d1506db459640af13fe28795ad5a0", + .url = "https://github.com/bytecodealliance/wasmtime/releases/download/v13.0.1/wasmtime-v13.0.1-aarch64-macos.tar.xz", + .lazy = true, + }, + .@"wasmtime-x86_64-windows-gnu" = .{ + .hash = "12206dd597841bb2e048996c650ae66b621c25c0e59d2555b4abf242d4b6deb16151", + .url = "https://github.com/bytecodealliance/wasmtime/releases/download/v13.0.1/wasmtime-v13.0.1-x86_64-windows.zip", + .lazy = true, + }, + + .@"zig+llvm+lld+clang-x86_64-linux-musl" = .{ + .hash = "12202441821c4e916ab128580655d8189610ca66c85fcc2545629c509e211cc88f8f", + .url = "https://ziglang.org/deps/zig+llvm+lld+clang-x86_64-linux-musl-0.13.0-dev.130+98a30acad.tar.xz", + .lazy = true, + }, + .@"zig+llvm+lld+clang-aarch64-linux-musl" = .{ + .hash = "122007c945ba64a5103b6ee10455c7e6b89d8d5de5887034df5b9d1b5c1dc8a0a4c1", + .url = "https://ziglang.org/deps/zig+llvm+lld+clang-aarch64-linux-musl-0.13.0-dev.130+98a30acad.tar.xz", + .lazy = true, + }, + .@"zig+llvm+lld+clang-x86_64-macos-none" = .{ + .hash = "1220451d009ecda5092b59835ba65ea5d5ca04046436aab6f2fd113c00c7e794b860", + .url = "https://ziglang.org/deps/zig+llvm+lld+clang-x86_64-macos-none-0.13.0-dev.130+98a30acad.tar.xz", + .lazy = true, + }, + .@"zig+llvm+lld+clang-aarch64-macos-none" = .{ + .hash = "1220c6e8b6fd8eb397a8e54139ae0baec6583a7f72e509623437ff255ebc278822a1", + .url = "https://ziglang.org/deps/zig+llvm+lld+clang-aarch64-macos-none-0.13.0-dev.130+98a30acad.tar.xz", + .lazy = true, + }, + .@"zig+llvm+lld+clang-x86_64-windows-gnu" = .{ + .hash = "12204a122b74c73de3b84d0626b99a5e355a037fc7b1c8ffa14c9d7bdc2e9a40d3d3", + .url = "https://ziglang.org/deps/zig+llvm+lld+clang-x86_64-windows-gnu-0.13.0-dev.130+98a30acad.zip", + .lazy = true, + }, + .@"zig+llvm+lld+clang-aarch64-windows-gnu" = .{ + .hash = "1220f756f38997a4f89d620aa77a2db21463ed7cc2dff5574e835894bb1969dfca95", + .url = "https://ziglang.org/deps/zig+llvm+lld+clang-aarch64-windows-gnu-0.13.0-dev.130+98a30acad.zip", + .lazy = true, + }, + }, +} diff --git a/ci/chmod.zig b/ci/chmod.zig new file mode 100644 index 0000000000..c0c1e5c8ce --- /dev/null +++ b/ci/chmod.zig @@ -0,0 +1,32 @@ +const std = @import("std"); + +pub fn main() !void { + var args_it = try std.process.argsWithAllocator(std.heap.page_allocator); + defer args_it.deinit(); + _ = args_it.skip(); + while (args_it.next()) |path| { + const file = std.fs.cwd().openFile(path, .{}) catch |err| switch (err) { + error.FileNotFound, error.NotDir => continue, + else => |e| return e, + }; + defer file.close(); + var got_access_denied = false; + while (true) { + const old_mode = try file.mode(); + const new_mode = old_mode | (std.posix.S.IXUSR | std.posix.S.IXGRP | std.posix.S.IXOTH); + if (new_mode != old_mode) file.chmod(new_mode) catch |err| switch (err) { + // This can happen on macOS during a race condition where another process adds the + // executable bits and executes the file between this process reading the old mode + // and setting the new mode. In the case, getting the mode again will return the + // newly set executable bits and so this code will not be reached the second time. + error.AccessDenied => |e| { + if (got_access_denied) return e; + got_access_denied = true; + continue; + }, + else => |e| return e, + }; + break; + } + } +} diff --git a/ci/cmp.zig b/ci/cmp.zig new file mode 100644 index 0000000000..705bc3bc11 --- /dev/null +++ b/ci/cmp.zig @@ -0,0 +1,28 @@ +const std = @import("std"); + +pub fn main() !void { + var args = try std.process.argsWithAllocator(std.heap.page_allocator); + _ = args.skip(); + const first_path = args.next().?; + const first_file = try std.fs.cwd().openFile(first_path, .{}); + const second_path = args.next().?; + const second_file = try std.fs.cwd().openFile(second_path, .{}); + + var first_buffer: [1 << 18]u8 = undefined; + var second_buffer: [1 << 18]u8 = undefined; + var offset: u64 = 0; + while (true) { + const first_data = first_buffer[0..try first_file.reader().readAll(&first_buffer)]; + const second_data = second_buffer[0..try second_file.reader().readAll(&second_buffer)]; + if (std.mem.indexOfDiff(u8, first_data, second_data)) |diff_index| { + try std.io.getStdErr().writer().print("{s} {s} differ: byte {d}\n", .{ + first_path, + second_path, + offset + diff_index + 1, + }); + std.process.exit(1); + } + offset += first_data.len; + if (first_data.len < first_buffer.len) break; + } +} diff --git a/ci/run.zig b/ci/run.zig new file mode 100644 index 0000000000..d1b8b1a95a --- /dev/null +++ b/ci/run.zig @@ -0,0 +1,126 @@ +//! ./runner command0 [arg0 arg1 ...] [--then command1 arg0 arg1 ...] [--path path0 path1 ...] [--cwd cwd] [--delete file0 file1 ...] [--rename old0 new0 [old1 new1 ...]] -- [replacement0 replacement1 ... replacement9] +//! Replaces $0 through $9 in all non-option arguments with replacement0 through replacement9, +//! which have native path separators replaced with posix path separators. +//! Replaces @0 through @9 in all non-option arguments with the contents of the file +//! replacement0 through replacement9. +//! Then, executes the command before any option arguments with extra paths after --path and at optional cwd after --cwd. +//! Then, executes the command after --then with extra paths after --path and at optional cwd after --cwd. +//! Then, optionally deletes files after --delete. +//! Then, optionally renomes pairs of files after --rename. + +const std = @import("std"); + +pub fn main() !void { + var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); + const allocator = arena.allocator(); + + const args = try std.process.argsAlloc(allocator); + var first: [][]u8 = &.{}; + var then: [][]u8 = &.{}; + var cwd: [][]u8 = &.{}; + var path: [][]u8 = &.{}; + var delete: [][]u8 = &.{}; + var rename: [][]u8 = &.{}; + var replacements: [][]u8 = &.{}; + + var prev_separator_index: usize = 0; + var separator_index: usize = 1; + while (separator_index < args.len) : (separator_index += 1) { + if (!std.mem.startsWith(u8, args[separator_index], "--")) continue; + const separated_args = args[prev_separator_index + 1 .. separator_index]; + if (prev_separator_index == 0) + first = separated_args + else if (std.mem.eql(u8, args[prev_separator_index], "--then")) + then = separated_args + else if (std.mem.eql(u8, args[prev_separator_index], "--cwd")) + cwd = separated_args + else if (std.mem.eql(u8, args[prev_separator_index], "--path")) + path = separated_args + else if (std.mem.eql(u8, args[prev_separator_index], "--delete")) + delete = separated_args + else if (std.mem.eql(u8, args[prev_separator_index], "--rename")) + rename = separated_args + else + std.debug.panic("unexpected '{s}'", .{args[prev_separator_index]}); + if (args[separator_index].len == 2) { + replacements = args[separator_index + 1 ..]; + break; + } + prev_separator_index = separator_index; + } else std.debug.panic("expected '--'", .{}); + + if (first.len == 0) std.debug.panic("expected arguments", .{}); + if (cwd.len > 1) std.debug.panic("expected at most 1 cwd argument", .{}); + if (rename.len % 2 != 0) std.debug.panic("expected even rename arguments", .{}); + + for (replacements) |replacement| std.mem.replaceScalar( + u8, + replacement, + std.fs.path.sep, + std.fs.path.sep_posix, + ); + for ([_][][]u8{ first, then, cwd, path, delete, rename }) |patterns| for (patterns) |*pattern| { + var replaced = std.ArrayList(u8).init(allocator); + var pos: usize = 0; + while (std.mem.indexOfAnyPos(u8, pattern.*, pos, "$@")) |special_pos| { + try replaced.appendSlice(pattern.*[pos..special_pos]); + const special = pattern.*[special_pos..][0..2]; + if (std.fmt.charToDigit(special[1], 10)) |special_index| switch (special[0]) { + '$' => try replaced.appendSlice(replacements[special_index]), + '@' => { + const special_file = try std.fs.cwd().openFile(replacements[special_index], .{}); + defer special_file.close(); + try special_file.reader().readAllArrayList(&replaced, 1 << 12); + replaced.shrinkRetainingCapacity(std.mem.trimRight(u8, replaced.items, &std.ascii.whitespace).len); + }, + else => unreachable, + } else |_| switch (special[0]) { + '$' => try replaced.append(special[1]), + else => unreachable, + } + pos = special_pos + 2; + } + try replaced.appendSlice(pattern.*[pos..]); + pattern.* = replaced.items; + }; + + var path_buffer = std.ArrayList(u8).init(allocator); + for (path) |path_path| { + try path_buffer.appendSlice(path_path); + try path_buffer.append(std.fs.path.delimiter); + } + var env = try std.process.getEnvMap(allocator); + if (env.getPtr("PATH")) |env_path| { + try path_buffer.appendSlice(env_path.*); + env_path.* = try path_buffer.toOwnedSlice(); + } else if (path_buffer.items.len > 0) try env.putMove( + try allocator.dupe(u8, "PATH"), + path_buffer.items[0 .. path_buffer.items.len - 1], + ); + + var first_child = std.process.Child.init(first, allocator); + first_child.env_map = &env; + if (cwd.len == 1) first_child.cwd = cwd[0]; + switch (try first_child.spawnAndWait()) { + .Exited => |status| if (status != 0) std.process.exit(status), + else => |term| std.debug.panic("{}", .{term}), + } + + if (then.len > 0) { + var then_child = std.process.Child.init(then, allocator); + then_child.env_map = &env; + if (cwd.len == 1) then_child.cwd = cwd[0]; + switch (try then_child.spawnAndWait()) { + .Exited => |status| if (status != 0) std.process.exit(status), + else => |term| std.debug.panic("{}", .{term}), + } + } + + for (delete) |delete_path| try std.fs.cwd().deleteFile(delete_path); + + var rename_index: usize = 0; + while (rename_index < rename.len) : (rename_index += 2) try std.fs.cwd().rename( + rename[rename_index + 0], + rename[rename_index + 1], + ); +} diff --git a/ci/x86_64-linux-debug.sh b/ci/x86_64-linux-debug.sh deleted file mode 100755 index 2ec21566e1..0000000000 --- a/ci/x86_64-linux-debug.sh +++ /dev/null @@ -1,108 +0,0 @@ -#!/bin/sh - -# Requires cmake ninja-build - -set -x -set -e - -ARCH="$(uname -m)" -TARGET="$ARCH-linux-musl" -MCPU="baseline" -CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.13.0-dev.130+98a30acad" -PREFIX="$HOME/deps/$CACHE_BASENAME" -ZIG="$PREFIX/bin/zig" - -export PATH="$HOME/deps/wasmtime-v10.0.2-$ARCH-linux:$HOME/deps/qemu-linux-x86_64-8.2.1/bin:$PATH" - -# Make the `zig version` number consistent. -# This will affect the cmake command below. -git fetch --unshallow || true -git fetch --tags - -# Test building from source without LLVM. -git clean -fd -rm -rf zig-out -cc -o bootstrap bootstrap.c -./bootstrap -./zig2 build -Dno-lib -./zig-out/bin/zig test test/behavior.zig - -export CC="$ZIG cc -target $TARGET -mcpu=$MCPU" -export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU" - -rm -rf build-debug -mkdir build-debug -cd build-debug - -# Override the cache directories because they won't actually help other CI runs -# which will be testing alternate versions of zig, and ultimately would just -# fill up space on the hard drive for no reason. -export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache" -export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache" - -cmake .. \ - -DCMAKE_INSTALL_PREFIX="stage3-debug" \ - -DCMAKE_PREFIX_PATH="$PREFIX" \ - -DCMAKE_BUILD_TYPE=Debug \ - -DZIG_TARGET_TRIPLE="$TARGET" \ - -DZIG_TARGET_MCPU="$MCPU" \ - -DZIG_STATIC=ON \ - -DZIG_NO_LIB=ON \ - -GNinja - -# Now cmake will use zig as the C/C++ compiler. We reset the environment variables -# so that installation and testing do not get affected by them. -unset CC -unset CXX - -ninja install - -# simultaneously test building self-hosted without LLVM and with 32-bit arm -stage3-debug/bin/zig build \ - -Dtarget=arm-linux-musleabihf \ - -Dno-lib - -stage3-debug/bin/zig build test docs \ - --maxrss 21000000000 \ - -fqemu \ - -fwasmtime \ - -Dstatic-llvm \ - -Dtarget=native-native-musl \ - --search-prefix "$PREFIX" \ - --zig-lib-dir "$PWD/../lib" \ - -Denable-tidy - -# Ensure that updating the wasm binary from this commit will result in a viable build. -stage3-debug/bin/zig build update-zig1 - -rm -rf ../build-new -mkdir ../build-new -cd ../build-new - -export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache" -export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache" -export CC="$ZIG cc -target $TARGET -mcpu=$MCPU" -export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU" - -cmake .. \ - -DCMAKE_PREFIX_PATH="$PREFIX" \ - -DCMAKE_BUILD_TYPE=Debug \ - -DZIG_TARGET_TRIPLE="$TARGET" \ - -DZIG_TARGET_MCPU="$MCPU" \ - -DZIG_STATIC=ON \ - -DZIG_NO_LIB=ON \ - -GNinja - -unset CC -unset CXX - -ninja install - -stage3/bin/zig test ../test/behavior.zig -stage3/bin/zig build -p stage4 \ - -Dstatic-llvm \ - -Dtarget=native-native-musl \ - -Dno-lib \ - --search-prefix "$PREFIX" \ - --zig-lib-dir "$PWD/../lib" -stage4/bin/zig test ../test/behavior.zig diff --git a/ci/x86_64-linux-release.sh b/ci/x86_64-linux-release.sh deleted file mode 100755 index 97257eb3b5..0000000000 --- a/ci/x86_64-linux-release.sh +++ /dev/null @@ -1,124 +0,0 @@ -#!/bin/sh - -# Requires cmake ninja-build - -set -x -set -e - -ARCH="$(uname -m)" -TARGET="$ARCH-linux-musl" -MCPU="baseline" -CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.13.0-dev.130+98a30acad" -PREFIX="$HOME/deps/$CACHE_BASENAME" -ZIG="$PREFIX/bin/zig" - -export PATH="$HOME/deps/wasmtime-v10.0.2-$ARCH-linux:$HOME/deps/qemu-linux-x86_64-8.2.1/bin:$PATH" - -# Make the `zig version` number consistent. -# This will affect the cmake command below. -git fetch --unshallow || true -git fetch --tags - -# Test building from source without LLVM. -git clean -fd -rm -rf zig-out -cc -o bootstrap bootstrap.c -./bootstrap -./zig2 build -Dno-lib -./zig-out/bin/zig test test/behavior.zig - -export CC="$ZIG cc -target $TARGET -mcpu=$MCPU" -export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU" - -rm -rf build-release -mkdir build-release -cd build-release - -# Override the cache directories because they won't actually help other CI runs -# which will be testing alternate versions of zig, and ultimately would just -# fill up space on the hard drive for no reason. -export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache" -export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache" - -cmake .. \ - -DCMAKE_INSTALL_PREFIX="stage3-release" \ - -DCMAKE_PREFIX_PATH="$PREFIX" \ - -DCMAKE_BUILD_TYPE=Release \ - -DZIG_TARGET_TRIPLE="$TARGET" \ - -DZIG_TARGET_MCPU="$MCPU" \ - -DZIG_STATIC=ON \ - -DZIG_NO_LIB=ON \ - -GNinja - -# Now cmake will use zig as the C/C++ compiler. We reset the environment variables -# so that installation and testing do not get affected by them. -unset CC -unset CXX - -ninja install - -# simultaneously test building self-hosted without LLVM and with 32-bit arm -stage3-release/bin/zig build \ - -Dtarget=arm-linux-musleabihf \ - -Dno-lib - -stage3-release/bin/zig build test docs \ - --maxrss 21000000000 \ - -fqemu \ - -fwasmtime \ - -Dstatic-llvm \ - -Dtarget=native-native-musl \ - --search-prefix "$PREFIX" \ - --zig-lib-dir "$PWD/../lib" \ - -Denable-tidy - -# Ensure that stage3 and stage4 are byte-for-byte identical. -stage3-release/bin/zig build \ - --prefix stage4-release \ - -Denable-llvm \ - -Dno-lib \ - -Doptimize=ReleaseFast \ - -Dstrip \ - -Dtarget=$TARGET \ - -Duse-zig-libcxx \ - -Dversion-string="$(stage3-release/bin/zig version)" - -# diff returns an error code if the files differ. -echo "If the following command fails, it means nondeterminism has been" -echo "introduced, making stage3 and stage4 no longer byte-for-byte identical." -diff stage3-release/bin/zig stage4-release/bin/zig - -# Ensure that updating the wasm binary from this commit will result in a viable build. -stage3-release/bin/zig build update-zig1 - -rm -rf ../build-new -mkdir ../build-new -cd ../build-new - -export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache" -export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache" -export CC="$ZIG cc -target $TARGET -mcpu=$MCPU" -export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU" - -cmake .. \ - -DCMAKE_PREFIX_PATH="$PREFIX" \ - -DCMAKE_BUILD_TYPE=Release \ - -DZIG_TARGET_TRIPLE="$TARGET" \ - -DZIG_TARGET_MCPU="$MCPU" \ - -DZIG_STATIC=ON \ - -DZIG_NO_LIB=ON \ - -GNinja - -unset CC -unset CXX - -ninja install - -stage3/bin/zig test ../test/behavior.zig -stage3/bin/zig build -p stage4 \ - -Dstatic-llvm \ - -Dtarget=native-native-musl \ - -Dno-lib \ - --search-prefix "$PREFIX" \ - --zig-lib-dir "$PWD/../lib" -stage4/bin/zig test ../test/behavior.zig diff --git a/ci/x86_64-macos-release.sh b/ci/x86_64-macos-release.sh deleted file mode 100755 index acf2b91d9a..0000000000 --- a/ci/x86_64-macos-release.sh +++ /dev/null @@ -1,78 +0,0 @@ -#!/bin/sh - -set -x -set -e - -ZIGDIR="$PWD" -TARGET="$ARCH-macos-none" -MCPU="baseline" -CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.13.0-dev.130+98a30acad" -PREFIX="$HOME/$CACHE_BASENAME" -JOBS="-j3" -ZIG="$PREFIX/bin/zig" - -if [ ! -d "$PREFIX" ]; then - cd $HOME - curl -L -O "https://ziglang.org/deps/$CACHE_BASENAME.tar.xz" - tar xf "$CACHE_BASENAME.tar.xz" -fi - -cd $ZIGDIR - -# Make the `zig version` number consistent. -# This will affect the cmake command below. -git fetch --unshallow || true -git fetch --tags - -# Test building from source without LLVM. -git clean -fd -rm -rf zig-out -cc -o bootstrap bootstrap.c -./bootstrap -./zig2 build -Dno-lib -./zig-out/bin/zig test test/behavior.zig - -rm -rf build -mkdir build -cd build - -# Override the cache directories because they won't actually help other CI runs -# which will be testing alternate versions of zig, and ultimately would just -# fill up space on the hard drive for no reason. -export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache" -export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache" - -cmake .. \ - -DCMAKE_PREFIX_PATH="$PREFIX" \ - -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_C_COMPILER="$ZIG;cc;-target;$TARGET;-mcpu=$MCPU" \ - -DCMAKE_CXX_COMPILER="$ZIG;c++;-target;$TARGET;-mcpu=$MCPU" \ - -DZIG_TARGET_TRIPLE="$TARGET" \ - -DZIG_TARGET_MCPU="$MCPU" \ - -DZIG_STATIC=ON \ - -DZIG_NO_LIB=ON - -make $JOBS install - -stage3/bin/zig build test docs \ - --zig-lib-dir "$PWD/../lib" \ - -Denable-macos-sdk \ - -Dstatic-llvm \ - -Dskip-non-native \ - --search-prefix "$PREFIX" - -# Ensure that stage3 and stage4 are byte-for-byte identical. -stage3/bin/zig build \ - --prefix stage4 \ - -Denable-llvm \ - -Dno-lib \ - -Doptimize=ReleaseFast \ - -Dstrip \ - -Dtarget=$TARGET \ - -Duse-zig-libcxx \ - -Dversion-string="$(stage3/bin/zig version)" - -# diff returns an error code if the files differ. -echo "If the following command fails, it means nondeterminism has been" -echo "introduced, making stage3 and stage4 no longer byte-for-byte identical." -diff stage3/bin/zig stage4/bin/zig diff --git a/ci/x86_64-windows-debug.ps1 b/ci/x86_64-windows-debug.ps1 deleted file mode 100644 index 057f85c331..0000000000 --- a/ci/x86_64-windows-debug.ps1 +++ /dev/null @@ -1,110 +0,0 @@ -$TARGET = "$($Env:ARCH)-windows-gnu" -$ZIG_LLVM_CLANG_LLD_NAME = "zig+llvm+lld+clang-$TARGET-0.13.0-dev.130+98a30acad" -$MCPU = "baseline" -$ZIG_LLVM_CLANG_LLD_URL = "https://ziglang.org/deps/$ZIG_LLVM_CLANG_LLD_NAME.zip" -$PREFIX_PATH = "$($Env:USERPROFILE)\$ZIG_LLVM_CLANG_LLD_NAME" -$ZIG = "$PREFIX_PATH\bin\zig.exe" -$ZIG_LIB_DIR = "$(Get-Location)\lib" - -if (!(Test-Path "$PREFIX_PATH.zip")) { - Write-Output "Downloading $ZIG_LLVM_CLANG_LLD_URL" - Invoke-WebRequest -Uri "$ZIG_LLVM_CLANG_LLD_URL" -OutFile "$PREFIX_PATH.zip" - - Write-Output "Extracting..." - Add-Type -AssemblyName System.IO.Compression.FileSystem ; - [System.IO.Compression.ZipFile]::ExtractToDirectory("$PREFIX_PATH.zip", "$PREFIX_PATH\..") -} - -function CheckLastExitCode { - if (!$?) { - exit 1 - } - return 0 -} - -# Make the `zig version` number consistent. -# This will affect the `zig build` command below which uses `git describe`. -git fetch --tags - -if ((git rev-parse --is-shallow-repository) -eq "true") { - git fetch --unshallow # `git describe` won't work on a shallow repo -} - -Write-Output "Building from source..." -Remove-Item -Path 'build-debug' -Recurse -Force -ErrorAction Ignore -New-Item -Path 'build-debug' -ItemType Directory -Set-Location -Path 'build-debug' - -# Override the cache directories because they won't actually help other CI runs -# which will be testing alternate versions of zig, and ultimately would just -# fill up space on the hard drive for no reason. -$Env:ZIG_GLOBAL_CACHE_DIR="$(Get-Location)\zig-global-cache" -$Env:ZIG_LOCAL_CACHE_DIR="$(Get-Location)\zig-local-cache" - -# 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-debug" ` - -DCMAKE_PREFIX_PATH="$($PREFIX_PATH -Replace "\\", "/")" ` - -DCMAKE_BUILD_TYPE=Debug ` - -DCMAKE_C_COMPILER="$($ZIG -Replace "\\", "/");cc;-target;$TARGET;-mcpu=$MCPU" ` - -DCMAKE_CXX_COMPILER="$($ZIG -Replace "\\", "/");c++;-target;$TARGET;-mcpu=$MCPU" ` - -DCMAKE_AR="$($ZIG -Replace "\\", "/")" ` - -DZIG_AR_WORKAROUND=ON ` - -DZIG_TARGET_TRIPLE="$TARGET" ` - -DZIG_TARGET_MCPU="$MCPU" ` - -DZIG_STATIC=ON ` - -DZIG_NO_LIB=ON -CheckLastExitCode - -ninja install -CheckLastExitCode - -Write-Output "Main test suite..." -& "stage3-debug\bin\zig.exe" build test docs ` - --zig-lib-dir "$ZIG_LIB_DIR" ` - --search-prefix "$PREFIX_PATH" ` - -Dstatic-llvm ` - -Dskip-non-native ` - -Dskip-release ` - -Denable-symlinks-windows -CheckLastExitCode - -Write-Output "Build x86_64-windows-msvc behavior tests using the C backend..." -& "stage3-debug\bin\zig.exe" test ` - ..\test\behavior.zig ` - --zig-lib-dir "$ZIG_LIB_DIR" ` - -ofmt=c ` - -femit-bin="test-x86_64-windows-msvc.c" ` - --test-no-exec ` - -target x86_64-windows-msvc ` - -lc -CheckLastExitCode - -& "stage3-debug\bin\zig.exe" build-obj ` - --zig-lib-dir "$ZIG_LIB_DIR" ` - -ofmt=c ` - -OReleaseSmall ` - --name compiler_rt ` - -femit-bin="compiler_rt-x86_64-windows-msvc.c" ` - --dep build_options ` - -target x86_64-windows-msvc ` - --mod root ..\lib\compiler_rt.zig ` - --mod build_options config.zig -CheckLastExitCode - -Import-Module "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\Microsoft.VisualStudio.DevShell.dll" -CheckLastExitCode - -Enter-VsDevShell -VsInstallPath "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools" ` - -DevCmdArguments '-arch=x64 -no_logo' ` - -StartInPath $(Get-Location) -CheckLastExitCode - -Write-Output "Build and run behavior tests with msvc..." -& cl.exe -I..\lib test-x86_64-windows-msvc.c compiler_rt-x86_64-windows-msvc.c /W3 /Z7 -link -nologo -debug -subsystem:console kernel32.lib ntdll.lib libcmt.lib -CheckLastExitCode - -& .\test-x86_64-windows-msvc.exe -CheckLastExitCode diff --git a/ci/x86_64-windows-release.ps1 b/ci/x86_64-windows-release.ps1 deleted file mode 100644 index 1bb2057530..0000000000 --- a/ci/x86_64-windows-release.ps1 +++ /dev/null @@ -1,109 +0,0 @@ -$TARGET = "$($Env:ARCH)-windows-gnu" -$ZIG_LLVM_CLANG_LLD_NAME = "zig+llvm+lld+clang-$TARGET-0.13.0-dev.130+98a30acad" -$MCPU = "baseline" -$ZIG_LLVM_CLANG_LLD_URL = "https://ziglang.org/deps/$ZIG_LLVM_CLANG_LLD_NAME.zip" -$PREFIX_PATH = "$($Env:USERPROFILE)\$ZIG_LLVM_CLANG_LLD_NAME" -$ZIG = "$PREFIX_PATH\bin\zig.exe" -$ZIG_LIB_DIR = "$(Get-Location)\lib" - -if (!(Test-Path "$PREFIX_PATH.zip")) { - Write-Output "Downloading $ZIG_LLVM_CLANG_LLD_URL" - Invoke-WebRequest -Uri "$ZIG_LLVM_CLANG_LLD_URL" -OutFile "$PREFIX_PATH.zip" - - Write-Output "Extracting..." - Add-Type -AssemblyName System.IO.Compression.FileSystem ; - [System.IO.Compression.ZipFile]::ExtractToDirectory("$PREFIX_PATH.zip", "$PREFIX_PATH\..") -} - -function CheckLastExitCode { - if (!$?) { - exit 1 - } - return 0 -} - -# Make the `zig version` number consistent. -# This will affect the `zig build` command below which uses `git describe`. -git fetch --tags - -if ((git rev-parse --is-shallow-repository) -eq "true") { - git fetch --unshallow # `git describe` won't work on a shallow repo -} - -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' - -# Override the cache directories because they won't actually help other CI runs -# which will be testing alternate versions of zig, and ultimately would just -# fill up space on the hard drive for no reason. -$Env:ZIG_GLOBAL_CACHE_DIR="$(Get-Location)\zig-global-cache" -$Env:ZIG_LOCAL_CACHE_DIR="$(Get-Location)\zig-local-cache" - -# 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" ` - -DCMAKE_AR="$($ZIG -Replace "\\", "/")" ` - -DZIG_AR_WORKAROUND=ON ` - -DZIG_TARGET_TRIPLE="$TARGET" ` - -DZIG_TARGET_MCPU="$MCPU" ` - -DZIG_STATIC=ON ` - -DZIG_NO_LIB=ON -CheckLastExitCode - -ninja install -CheckLastExitCode - -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 "Build x86_64-windows-msvc behavior tests using the C backend..." -& "stage3-release\bin\zig.exe" test ` - ..\test\behavior.zig ` - --zig-lib-dir "$ZIG_LIB_DIR" ` - -ofmt=c ` - -femit-bin="test-x86_64-windows-msvc.c" ` - --test-no-exec ` - -target x86_64-windows-msvc ` - -lc -CheckLastExitCode - -& "stage3-release\bin\zig.exe" build-obj ` - --zig-lib-dir "$ZIG_LIB_DIR" ` - -ofmt=c ` - -OReleaseSmall ` - --name compiler_rt ` - -femit-bin="compiler_rt-x86_64-windows-msvc.c" ` - --dep build_options ` - -target x86_64-windows-msvc ` - --mod root ..\lib\compiler_rt.zig ` - --mod build_options config.zig -CheckLastExitCode - -Import-Module "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\Microsoft.VisualStudio.DevShell.dll" -CheckLastExitCode - -Enter-VsDevShell -VsInstallPath "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools" ` - -DevCmdArguments '-arch=x64 -no_logo' ` - -StartInPath $(Get-Location) -CheckLastExitCode - -Write-Output "Build and run behavior tests with msvc..." -& cl.exe -I..\lib test-x86_64-windows-msvc.c compiler_rt-x86_64-windows-msvc.c /W3 /Z7 -link -nologo -debug -subsystem:console kernel32.lib ntdll.lib libcmt.lib -CheckLastExitCode - -& .\test-x86_64-windows-msvc.exe -CheckLastExitCode diff --git a/lib/std/Build/Step/RemoveDir.zig b/lib/std/Build/Step/RemoveDir.zig index e2d4c02abc..bb4e98318c 100644 --- a/lib/std/Build/Step/RemoveDir.zig +++ b/lib/std/Build/Step/RemoveDir.zig @@ -35,14 +35,8 @@ fn make(step: *Step, options: Step.MakeOptions) !void { const full_doomed_path = remove_dir.doomed_path.getPath2(b, step); b.build_root.handle.deleteTree(full_doomed_path) catch |err| { - if (b.build_root.path) |base| { - return step.fail("unable to recursively delete path '{s}/{s}': {s}", .{ - base, full_doomed_path, @errorName(err), - }); - } else { - return step.fail("unable to recursively delete path '{s}': {s}", .{ - full_doomed_path, @errorName(err), - }); - } + return step.fail("unable to recursively delete path '{s}': {s}", .{ + b.pathFromRoot(full_doomed_path), @errorName(err), + }); }; } diff --git a/lib/std/posix.zig b/lib/std/posix.zig index bcb5dc7744..4a4d9a24cf 100644 --- a/lib/std/posix.zig +++ b/lib/std/posix.zig @@ -7353,7 +7353,10 @@ const lfs64_abi = native_os == .linux and builtin.link_libc and builtin.abi.isGn /// If this happens the fix is to add the error code to the corresponding /// switch expression, possibly introduce a new error in the error set, and /// send a patch to Zig. -pub const unexpected_error_tracing = builtin.zig_backend == .stage2_llvm and builtin.mode == .Debug; +pub const unexpected_error_tracing = switch (builtin.zig_backend) { + .stage2_c, .stage2_llvm, .stage2_x86_64 => true, + else => false, +}; pub const UnexpectedError = error{ /// The Operating System returned an undocumented error code.