| author | |
| committer | |
| log | 544397ce6d2926858217eb013dfcfcd0a5b3e3c6 |
| tree | a40e383b10a7e7c2f33429780df7d67ec2970236 |
| parent | 130fb5cb0fb9039e79450c9db58d6590c5bee3b3 |
| parent | 71ccdb5a66da500f8447018553ff0ac32e55face |
| signature |
ci: add self-hosted `x86_64 windows`14 files changed, 332 insertions(+), 315 deletions(-)
.github/workflows/ci.yaml+2-2| ... | @@ -69,7 +69,7 @@ jobs: | ... | @@ -69,7 +69,7 @@ jobs: |
| 69 | - name: Build and Test | 69 | - name: Build and Test |
| 70 | run: ci/aarch64-macos-release.sh | 70 | run: ci/aarch64-macos-release.sh |
| 71 | x86_64-windows-debug: | 71 | x86_64-windows-debug: |
| 72 | runs-on: windows-latest | 72 | runs-on: [self-hosted, Windows, x86_64] |
| 73 | env: | 73 | env: |
| 74 | ARCH: "x86_64" | 74 | ARCH: "x86_64" |
| 75 | steps: | 75 | steps: |
| ... | @@ -78,7 +78,7 @@ jobs: | ... | @@ -78,7 +78,7 @@ jobs: |
| 78 | - name: Build and Test | 78 | - name: Build and Test |
| 79 | run: ci/x86_64-windows-debug.ps1 | 79 | run: ci/x86_64-windows-debug.ps1 |
| 80 | x86_64-windows-release: | 80 | x86_64-windows-release: |
| 81 | runs-on: windows-latest | 81 | runs-on: [self-hosted, Windows, x86_64] |
| 82 | env: | 82 | env: |
| 83 | ARCH: "x86_64" | 83 | ARCH: "x86_64" |
| 84 | steps: | 84 | steps: |
ci/aarch64-linux-debug.sh+6-6| ... | @@ -29,8 +29,8 @@ cd build-debug | ... | @@ -29,8 +29,8 @@ cd build-debug |
| 29 | # Override the cache directories because they won't actually help other CI runs | 29 | # Override the cache directories because they won't actually help other CI runs |
| 30 | # which will be testing alternate versions of zig, and ultimately would just | 30 | # which will be testing alternate versions of zig, and ultimately would just |
| 31 | # fill up space on the hard drive for no reason. | 31 | # fill up space on the hard drive for no reason. |
| 32 | export ZIG_GLOBAL_CACHE_DIR="$(pwd)/zig-global-cache" | 32 | export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache" |
| 33 | export ZIG_LOCAL_CACHE_DIR="$(pwd)/zig-local-cache" | 33 | export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache" |
| 34 | 34 | ||
| 35 | cmake .. \ | 35 | cmake .. \ |
| 36 | -DCMAKE_INSTALL_PREFIX="stage3-debug" \ | 36 | -DCMAKE_INSTALL_PREFIX="stage3-debug" \ |
| ... | @@ -67,7 +67,7 @@ stage3-debug/bin/zig build test docs \ | ... | @@ -67,7 +67,7 @@ stage3-debug/bin/zig build test docs \ |
| 67 | -Dstatic-llvm \ | 67 | -Dstatic-llvm \ |
| 68 | -Dtarget=native-native-musl \ | 68 | -Dtarget=native-native-musl \ |
| 69 | --search-prefix "$PREFIX" \ | 69 | --search-prefix "$PREFIX" \ |
| 70 | --zig-lib-dir "$(pwd)/../lib" | 70 | --zig-lib-dir "$PWD/../lib" |
| 71 | 71 | ||
| 72 | # Look for HTML errors. | 72 | # Look for HTML errors. |
| 73 | # TODO: move this to a build.zig flag (-Denable-tidy) | 73 | # TODO: move this to a build.zig flag (-Denable-tidy) |
| ... | @@ -80,8 +80,8 @@ rm -rf ../build-new | ... | @@ -80,8 +80,8 @@ rm -rf ../build-new |
| 80 | mkdir ../build-new | 80 | mkdir ../build-new |
| 81 | cd ../build-new | 81 | cd ../build-new |
| 82 | 82 | ||
| 83 | export ZIG_GLOBAL_CACHE_DIR="$(pwd)/zig-global-cache" | 83 | export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache" |
| 84 | export ZIG_LOCAL_CACHE_DIR="$(pwd)/zig-local-cache" | 84 | export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache" |
| 85 | export CC="$ZIG cc -target $TARGET -mcpu=$MCPU" | 85 | export CC="$ZIG cc -target $TARGET -mcpu=$MCPU" |
| 86 | export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU" | 86 | export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU" |
| 87 | 87 | ||
| ... | @@ -105,5 +105,5 @@ stage3/bin/zig build -p stage4 \ | ... | @@ -105,5 +105,5 @@ stage3/bin/zig build -p stage4 \ |
| 105 | -Dtarget=native-native-musl \ | 105 | -Dtarget=native-native-musl \ |
| 106 | -Dno-lib \ | 106 | -Dno-lib \ |
| 107 | --search-prefix "$PREFIX" \ | 107 | --search-prefix "$PREFIX" \ |
| 108 | --zig-lib-dir "$(pwd)/../lib" | 108 | --zig-lib-dir "$PWD/../lib" |
| 109 | stage4/bin/zig test ../test/behavior.zig | 109 | stage4/bin/zig test ../test/behavior.zig |
ci/aarch64-linux-release.sh+6-6| ... | @@ -29,8 +29,8 @@ cd build-release | ... | @@ -29,8 +29,8 @@ cd build-release |
| 29 | # Override the cache directories because they won't actually help other CI runs | 29 | # Override the cache directories because they won't actually help other CI runs |
| 30 | # which will be testing alternate versions of zig, and ultimately would just | 30 | # which will be testing alternate versions of zig, and ultimately would just |
| 31 | # fill up space on the hard drive for no reason. | 31 | # fill up space on the hard drive for no reason. |
| 32 | export ZIG_GLOBAL_CACHE_DIR="$(pwd)/zig-global-cache" | 32 | export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache" |
| 33 | export ZIG_LOCAL_CACHE_DIR="$(pwd)/zig-local-cache" | 33 | export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache" |
| 34 | 34 | ||
| 35 | cmake .. \ | 35 | cmake .. \ |
| 36 | -DCMAKE_INSTALL_PREFIX="stage3-release" \ | 36 | -DCMAKE_INSTALL_PREFIX="stage3-release" \ |
| ... | @@ -67,7 +67,7 @@ stage3-release/bin/zig build test docs \ | ... | @@ -67,7 +67,7 @@ stage3-release/bin/zig build test docs \ |
| 67 | -Dstatic-llvm \ | 67 | -Dstatic-llvm \ |
| 68 | -Dtarget=native-native-musl \ | 68 | -Dtarget=native-native-musl \ |
| 69 | --search-prefix "$PREFIX" \ | 69 | --search-prefix "$PREFIX" \ |
| 70 | --zig-lib-dir "$(pwd)/../lib" | 70 | --zig-lib-dir "$PWD/../lib" |
| 71 | 71 | ||
| 72 | # Look for HTML errors. | 72 | # Look for HTML errors. |
| 73 | # TODO: move this to a build.zig flag (-Denable-tidy) | 73 | # TODO: move this to a build.zig flag (-Denable-tidy) |
| ... | @@ -80,8 +80,8 @@ rm -rf ../build-new | ... | @@ -80,8 +80,8 @@ rm -rf ../build-new |
| 80 | mkdir ../build-new | 80 | mkdir ../build-new |
| 81 | cd ../build-new | 81 | cd ../build-new |
| 82 | 82 | ||
| 83 | export ZIG_GLOBAL_CACHE_DIR="$(pwd)/zig-global-cache" | 83 | export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache" |
| 84 | export ZIG_LOCAL_CACHE_DIR="$(pwd)/zig-local-cache" | 84 | export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache" |
| 85 | export CC="$ZIG cc -target $TARGET -mcpu=$MCPU" | 85 | export CC="$ZIG cc -target $TARGET -mcpu=$MCPU" |
| 86 | export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU" | 86 | export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU" |
| 87 | 87 | ||
| ... | @@ -105,5 +105,5 @@ stage3/bin/zig build -p stage4 \ | ... | @@ -105,5 +105,5 @@ stage3/bin/zig build -p stage4 \ |
| 105 | -Dtarget=native-native-musl \ | 105 | -Dtarget=native-native-musl \ |
| 106 | -Dno-lib \ | 106 | -Dno-lib \ |
| 107 | --search-prefix "$PREFIX" \ | 107 | --search-prefix "$PREFIX" \ |
| 108 | --zig-lib-dir "$(pwd)/../lib" | 108 | --zig-lib-dir "$PWD/../lib" |
| 109 | stage4/bin/zig test ../test/behavior.zig | 109 | stage4/bin/zig test ../test/behavior.zig |
ci/aarch64-macos-debug.sh+4-4| ... | @@ -6,7 +6,7 @@ set -e | ... | @@ -6,7 +6,7 @@ set -e |
| 6 | # Script assumes the presence of the following: | 6 | # Script assumes the presence of the following: |
| 7 | # s3cmd | 7 | # s3cmd |
| 8 | 8 | ||
| 9 | ZIGDIR="$(pwd)" | 9 | ZIGDIR="$PWD" |
| 10 | TARGET="$ARCH-macos-none" | 10 | TARGET="$ARCH-macos-none" |
| 11 | MCPU="baseline" | 11 | MCPU="baseline" |
| 12 | CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.12.0-dev.467+0345d7866" | 12 | CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.12.0-dev.467+0345d7866" |
| ... | @@ -26,8 +26,8 @@ cd build | ... | @@ -26,8 +26,8 @@ cd build |
| 26 | # Override the cache directories because they won't actually help other CI runs | 26 | # Override the cache directories because they won't actually help other CI runs |
| 27 | # which will be testing alternate versions of zig, and ultimately would just | 27 | # which will be testing alternate versions of zig, and ultimately would just |
| 28 | # fill up space on the hard drive for no reason. | 28 | # fill up space on the hard drive for no reason. |
| 29 | export ZIG_GLOBAL_CACHE_DIR="$(pwd)/zig-global-cache" | 29 | export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache" |
| 30 | export ZIG_LOCAL_CACHE_DIR="$(pwd)/zig-local-cache" | 30 | export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache" |
| 31 | 31 | ||
| 32 | PATH="$HOME/local/bin:$PATH" cmake .. \ | 32 | PATH="$HOME/local/bin:$PATH" cmake .. \ |
| 33 | -DCMAKE_INSTALL_PREFIX="stage3-debug" \ | 33 | -DCMAKE_INSTALL_PREFIX="stage3-debug" \ |
| ... | @@ -44,7 +44,7 @@ PATH="$HOME/local/bin:$PATH" cmake .. \ | ... | @@ -44,7 +44,7 @@ PATH="$HOME/local/bin:$PATH" cmake .. \ |
| 44 | $HOME/local/bin/ninja install | 44 | $HOME/local/bin/ninja install |
| 45 | 45 | ||
| 46 | stage3-debug/bin/zig build test docs \ | 46 | stage3-debug/bin/zig build test docs \ |
| 47 | --zig-lib-dir "$(pwd)/../lib" \ | 47 | --zig-lib-dir "$PWD/../lib" \ |
| 48 | -Denable-macos-sdk \ | 48 | -Denable-macos-sdk \ |
| 49 | -Dstatic-llvm \ | 49 | -Dstatic-llvm \ |
| 50 | -Dskip-non-native \ | 50 | -Dskip-non-native \ |
ci/aarch64-macos-release.sh+4-4| ... | @@ -6,7 +6,7 @@ set -e | ... | @@ -6,7 +6,7 @@ set -e |
| 6 | # Script assumes the presence of the following: | 6 | # Script assumes the presence of the following: |
| 7 | # s3cmd | 7 | # s3cmd |
| 8 | 8 | ||
| 9 | ZIGDIR="$(pwd)" | 9 | ZIGDIR="$PWD" |
| 10 | TARGET="$ARCH-macos-none" | 10 | TARGET="$ARCH-macos-none" |
| 11 | MCPU="baseline" | 11 | MCPU="baseline" |
| 12 | CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.12.0-dev.467+0345d7866" | 12 | CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.12.0-dev.467+0345d7866" |
| ... | @@ -26,8 +26,8 @@ cd build | ... | @@ -26,8 +26,8 @@ cd build |
| 26 | # Override the cache directories because they won't actually help other CI runs | 26 | # Override the cache directories because they won't actually help other CI runs |
| 27 | # which will be testing alternate versions of zig, and ultimately would just | 27 | # which will be testing alternate versions of zig, and ultimately would just |
| 28 | # fill up space on the hard drive for no reason. | 28 | # fill up space on the hard drive for no reason. |
| 29 | export ZIG_GLOBAL_CACHE_DIR="$(pwd)/zig-global-cache" | 29 | export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache" |
| 30 | export ZIG_LOCAL_CACHE_DIR="$(pwd)/zig-local-cache" | 30 | export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache" |
| 31 | 31 | ||
| 32 | PATH="$HOME/local/bin:$PATH" cmake .. \ | 32 | PATH="$HOME/local/bin:$PATH" cmake .. \ |
| 33 | -DCMAKE_INSTALL_PREFIX="stage3-release" \ | 33 | -DCMAKE_INSTALL_PREFIX="stage3-release" \ |
| ... | @@ -44,7 +44,7 @@ PATH="$HOME/local/bin:$PATH" cmake .. \ | ... | @@ -44,7 +44,7 @@ PATH="$HOME/local/bin:$PATH" cmake .. \ |
| 44 | $HOME/local/bin/ninja install | 44 | $HOME/local/bin/ninja install |
| 45 | 45 | ||
| 46 | stage3-release/bin/zig build test docs \ | 46 | stage3-release/bin/zig build test docs \ |
| 47 | --zig-lib-dir "$(pwd)/../lib" \ | 47 | --zig-lib-dir "$PWD/../lib" \ |
| 48 | -Denable-macos-sdk \ | 48 | -Denable-macos-sdk \ |
| 49 | -Dstatic-llvm \ | 49 | -Dstatic-llvm \ |
| 50 | -Dskip-non-native \ | 50 | -Dskip-non-native \ |
ci/x86_64-linux-debug.sh+6-6| ... | @@ -37,8 +37,8 @@ cd build-debug | ... | @@ -37,8 +37,8 @@ cd build-debug |
| 37 | # Override the cache directories because they won't actually help other CI runs | 37 | # Override the cache directories because they won't actually help other CI runs |
| 38 | # which will be testing alternate versions of zig, and ultimately would just | 38 | # which will be testing alternate versions of zig, and ultimately would just |
| 39 | # fill up space on the hard drive for no reason. | 39 | # fill up space on the hard drive for no reason. |
| 40 | export ZIG_GLOBAL_CACHE_DIR="$(pwd)/zig-global-cache" | 40 | export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache" |
| 41 | export ZIG_LOCAL_CACHE_DIR="$(pwd)/zig-local-cache" | 41 | export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache" |
| 42 | 42 | ||
| 43 | cmake .. \ | 43 | cmake .. \ |
| 44 | -DCMAKE_INSTALL_PREFIX="stage3-debug" \ | 44 | -DCMAKE_INSTALL_PREFIX="stage3-debug" \ |
| ... | @@ -75,7 +75,7 @@ stage3-debug/bin/zig build test docs \ | ... | @@ -75,7 +75,7 @@ stage3-debug/bin/zig build test docs \ |
| 75 | -Dstatic-llvm \ | 75 | -Dstatic-llvm \ |
| 76 | -Dtarget=native-native-musl \ | 76 | -Dtarget=native-native-musl \ |
| 77 | --search-prefix "$PREFIX" \ | 77 | --search-prefix "$PREFIX" \ |
| 78 | --zig-lib-dir "$(pwd)/../lib" | 78 | --zig-lib-dir "$PWD/../lib" |
| 79 | 79 | ||
| 80 | # Look for HTML errors. | 80 | # Look for HTML errors. |
| 81 | # TODO: move this to a build.zig flag (-Denable-tidy) | 81 | # TODO: move this to a build.zig flag (-Denable-tidy) |
| ... | @@ -88,8 +88,8 @@ rm -rf ../build-new | ... | @@ -88,8 +88,8 @@ rm -rf ../build-new |
| 88 | mkdir ../build-new | 88 | mkdir ../build-new |
| 89 | cd ../build-new | 89 | cd ../build-new |
| 90 | 90 | ||
| 91 | export ZIG_GLOBAL_CACHE_DIR="$(pwd)/zig-global-cache" | 91 | export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache" |
| 92 | export ZIG_LOCAL_CACHE_DIR="$(pwd)/zig-local-cache" | 92 | export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache" |
| 93 | export CC="$ZIG cc -target $TARGET -mcpu=$MCPU" | 93 | export CC="$ZIG cc -target $TARGET -mcpu=$MCPU" |
| 94 | export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU" | 94 | export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU" |
| 95 | 95 | ||
| ... | @@ -113,5 +113,5 @@ stage3/bin/zig build -p stage4 \ | ... | @@ -113,5 +113,5 @@ stage3/bin/zig build -p stage4 \ |
| 113 | -Dtarget=native-native-musl \ | 113 | -Dtarget=native-native-musl \ |
| 114 | -Dno-lib \ | 114 | -Dno-lib \ |
| 115 | --search-prefix "$PREFIX" \ | 115 | --search-prefix "$PREFIX" \ |
| 116 | --zig-lib-dir "$(pwd)/../lib" | 116 | --zig-lib-dir "$PWD/../lib" |
| 117 | stage4/bin/zig test ../test/behavior.zig | 117 | stage4/bin/zig test ../test/behavior.zig |
ci/x86_64-linux-release.sh+6-6| ... | @@ -37,8 +37,8 @@ cd build-release | ... | @@ -37,8 +37,8 @@ cd build-release |
| 37 | # Override the cache directories because they won't actually help other CI runs | 37 | # Override the cache directories because they won't actually help other CI runs |
| 38 | # which will be testing alternate versions of zig, and ultimately would just | 38 | # which will be testing alternate versions of zig, and ultimately would just |
| 39 | # fill up space on the hard drive for no reason. | 39 | # fill up space on the hard drive for no reason. |
| 40 | export ZIG_GLOBAL_CACHE_DIR="$(pwd)/zig-global-cache" | 40 | export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache" |
| 41 | export ZIG_LOCAL_CACHE_DIR="$(pwd)/zig-local-cache" | 41 | export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache" |
| 42 | 42 | ||
| 43 | cmake .. \ | 43 | cmake .. \ |
| 44 | -DCMAKE_INSTALL_PREFIX="stage3-release" \ | 44 | -DCMAKE_INSTALL_PREFIX="stage3-release" \ |
| ... | @@ -76,7 +76,7 @@ stage3-release/bin/zig build test docs \ | ... | @@ -76,7 +76,7 @@ stage3-release/bin/zig build test docs \ |
| 76 | -Dstatic-llvm \ | 76 | -Dstatic-llvm \ |
| 77 | -Dtarget=native-native-musl \ | 77 | -Dtarget=native-native-musl \ |
| 78 | --search-prefix "$PREFIX" \ | 78 | --search-prefix "$PREFIX" \ |
| 79 | --zig-lib-dir "$(pwd)/../lib" | 79 | --zig-lib-dir "$PWD/../lib" |
| 80 | 80 | ||
| 81 | # Look for HTML errors. | 81 | # Look for HTML errors. |
| 82 | # TODO: move this to a build.zig flag (-Denable-tidy) | 82 | # TODO: move this to a build.zig flag (-Denable-tidy) |
| ... | @@ -105,8 +105,8 @@ rm -rf ../build-new | ... | @@ -105,8 +105,8 @@ rm -rf ../build-new |
| 105 | mkdir ../build-new | 105 | mkdir ../build-new |
| 106 | cd ../build-new | 106 | cd ../build-new |
| 107 | 107 | ||
| 108 | export ZIG_GLOBAL_CACHE_DIR="$(pwd)/zig-global-cache" | 108 | export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache" |
| 109 | export ZIG_LOCAL_CACHE_DIR="$(pwd)/zig-local-cache" | 109 | export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache" |
| 110 | export CC="$ZIG cc -target $TARGET -mcpu=$MCPU" | 110 | export CC="$ZIG cc -target $TARGET -mcpu=$MCPU" |
| 111 | export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU" | 111 | export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU" |
| 112 | 112 | ||
| ... | @@ -130,5 +130,5 @@ stage3/bin/zig build -p stage4 \ | ... | @@ -130,5 +130,5 @@ stage3/bin/zig build -p stage4 \ |
| 130 | -Dtarget=native-native-musl \ | 130 | -Dtarget=native-native-musl \ |
| 131 | -Dno-lib \ | 131 | -Dno-lib \ |
| 132 | --search-prefix "$PREFIX" \ | 132 | --search-prefix "$PREFIX" \ |
| 133 | --zig-lib-dir "$(pwd)/../lib" | 133 | --zig-lib-dir "$PWD/../lib" |
| 134 | stage4/bin/zig test ../test/behavior.zig | 134 | stage4/bin/zig test ../test/behavior.zig |
ci/x86_64-macos-release.sh+4-4| ... | @@ -3,7 +3,7 @@ | ... | @@ -3,7 +3,7 @@ |
| 3 | set -x | 3 | set -x |
| 4 | set -e | 4 | set -e |
| 5 | 5 | ||
| 6 | ZIGDIR="$(pwd)" | 6 | ZIGDIR="$PWD" |
| 7 | TARGET="$ARCH-macos-none" | 7 | TARGET="$ARCH-macos-none" |
| 8 | MCPU="baseline" | 8 | MCPU="baseline" |
| 9 | CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.12.0-dev.467+0345d7866" | 9 | CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.12.0-dev.467+0345d7866" |
| ... | @@ -40,8 +40,8 @@ cd build | ... | @@ -40,8 +40,8 @@ cd build |
| 40 | # Override the cache directories because they won't actually help other CI runs | 40 | # Override the cache directories because they won't actually help other CI runs |
| 41 | # which will be testing alternate versions of zig, and ultimately would just | 41 | # which will be testing alternate versions of zig, and ultimately would just |
| 42 | # fill up space on the hard drive for no reason. | 42 | # fill up space on the hard drive for no reason. |
| 43 | export ZIG_GLOBAL_CACHE_DIR="$(pwd)/zig-global-cache" | 43 | export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache" |
| 44 | export ZIG_LOCAL_CACHE_DIR="$(pwd)/zig-local-cache" | 44 | export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache" |
| 45 | 45 | ||
| 46 | cmake .. \ | 46 | cmake .. \ |
| 47 | -DCMAKE_PREFIX_PATH="$PREFIX" \ | 47 | -DCMAKE_PREFIX_PATH="$PREFIX" \ |
| ... | @@ -56,7 +56,7 @@ cmake .. \ | ... | @@ -56,7 +56,7 @@ cmake .. \ |
| 56 | make $JOBS install | 56 | make $JOBS install |
| 57 | 57 | ||
| 58 | stage3/bin/zig build test docs \ | 58 | stage3/bin/zig build test docs \ |
| 59 | --zig-lib-dir "$(pwd)/../lib" \ | 59 | --zig-lib-dir "$PWD/../lib" \ |
| 60 | -Denable-macos-sdk \ | 60 | -Denable-macos-sdk \ |
| 61 | -Dstatic-llvm \ | 61 | -Dstatic-llvm \ |
| 62 | -Dskip-non-native \ | 62 | -Dskip-non-native \ |
ci/x86_64-windows-debug.ps1+5-12| ... | @@ -1,19 +1,10 @@ | ... | @@ -1,19 +1,10 @@ |
| 1 | $TARGET = "$($Env:ARCH)-windows-gnu" | 1 | $TARGET = "$($Env:ARCH)-windows-gnu" |
| 2 | $ZIG_LLVM_CLANG_LLD_NAME = "zig+llvm+lld+clang-$TARGET-0.12.0-dev.2073+402fe565a" | 2 | $ZIG_LLVM_CLANG_LLD_NAME = "zig+llvm+lld+clang-$TARGET-0.12.0-dev.2073+402fe565a" |
| 3 | $MCPU = "baseline" | 3 | $MCPU = "baseline" |
| 4 | $ZIG_LLVM_CLANG_LLD_URL = "https://ziglang.org/deps/$ZIG_LLVM_CLANG_LLD_NAME.zip" | 4 | $PREFIX_PATH = "$($Env:USERPROFILE)\$ZIG_LLVM_CLANG_LLD_NAME" |
| 5 | $PREFIX_PATH = "$(Get-Location)\$ZIG_LLVM_CLANG_LLD_NAME" | ||
| 6 | $ZIG = "$PREFIX_PATH\bin\zig.exe" | 5 | $ZIG = "$PREFIX_PATH\bin\zig.exe" |
| 7 | $ZIG_LIB_DIR = "$(Get-Location)\lib" | 6 | $ZIG_LIB_DIR = "$(Get-Location)\lib" |
| 8 | 7 | ||
| 9 | choco install ninja | ||
| 10 | Write-Output "Downloading $ZIG_LLVM_CLANG_LLD_URL" | ||
| 11 | Invoke-WebRequest -Uri "$ZIG_LLVM_CLANG_LLD_URL" -OutFile "$ZIG_LLVM_CLANG_LLD_NAME.zip" | ||
| 12 | |||
| 13 | Write-Output "Extracting..." | ||
| 14 | Add-Type -AssemblyName System.IO.Compression.FileSystem ; | ||
| 15 | [System.IO.Compression.ZipFile]::ExtractToDirectory("$PWD/$ZIG_LLVM_CLANG_LLD_NAME.zip", "$PWD") | ||
| 16 | |||
| 17 | function CheckLastExitCode { | 8 | function CheckLastExitCode { |
| 18 | if (!$?) { | 9 | if (!$?) { |
| 19 | exit 1 | 10 | exit 1 |
| ... | @@ -43,6 +34,8 @@ Set-Location -Path 'build-debug' | ... | @@ -43,6 +34,8 @@ Set-Location -Path 'build-debug' |
| 43 | -DCMAKE_BUILD_TYPE=Debug ` | 34 | -DCMAKE_BUILD_TYPE=Debug ` |
| 44 | -DCMAKE_C_COMPILER="$($ZIG -Replace "\\", "/");cc;-target;$TARGET;-mcpu=$MCPU" ` | 35 | -DCMAKE_C_COMPILER="$($ZIG -Replace "\\", "/");cc;-target;$TARGET;-mcpu=$MCPU" ` |
| 45 | -DCMAKE_CXX_COMPILER="$($ZIG -Replace "\\", "/");c++;-target;$TARGET;-mcpu=$MCPU" ` | 36 | -DCMAKE_CXX_COMPILER="$($ZIG -Replace "\\", "/");c++;-target;$TARGET;-mcpu=$MCPU" ` |
| 37 | -DCMAKE_AR="$($ZIG -Replace "\\", "/")" ` | ||
| 38 | -DZIG_AR_WORKAROUND=ON ` | ||
| 46 | -DZIG_TARGET_TRIPLE="$TARGET" ` | 39 | -DZIG_TARGET_TRIPLE="$TARGET" ` |
| 47 | -DZIG_TARGET_MCPU="$MCPU" ` | 40 | -DZIG_TARGET_MCPU="$MCPU" ` |
| 48 | -DZIG_STATIC=ON ` | 41 | -DZIG_STATIC=ON ` |
| ... | @@ -85,10 +78,10 @@ CheckLastExitCode | ... | @@ -85,10 +78,10 @@ CheckLastExitCode |
| 85 | --mod build_options config.zig | 78 | --mod build_options config.zig |
| 86 | CheckLastExitCode | 79 | CheckLastExitCode |
| 87 | 80 | ||
| 88 | Import-Module "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\Microsoft.VisualStudio.DevShell.dll" | 81 | Import-Module "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\Microsoft.VisualStudio.DevShell.dll" |
| 89 | CheckLastExitCode | 82 | CheckLastExitCode |
| 90 | 83 | ||
| 91 | Enter-VsDevShell -VsInstallPath "C:\Program Files\Microsoft Visual Studio\2022\Enterprise" ` | 84 | Enter-VsDevShell -VsInstallPath "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools" ` |
| 92 | -DevCmdArguments '-arch=x64 -no_logo' ` | 85 | -DevCmdArguments '-arch=x64 -no_logo' ` |
| 93 | -StartInPath $(Get-Location) | 86 | -StartInPath $(Get-Location) |
| 94 | CheckLastExitCode | 87 | CheckLastExitCode |
ci/x86_64-windows-release.ps1+5-12| ... | @@ -1,19 +1,10 @@ | ... | @@ -1,19 +1,10 @@ |
| 1 | $TARGET = "$($Env:ARCH)-windows-gnu" | 1 | $TARGET = "$($Env:ARCH)-windows-gnu" |
| 2 | $ZIG_LLVM_CLANG_LLD_NAME = "zig+llvm+lld+clang-$TARGET-0.12.0-dev.2073+402fe565a" | 2 | $ZIG_LLVM_CLANG_LLD_NAME = "zig+llvm+lld+clang-$TARGET-0.12.0-dev.2073+402fe565a" |
| 3 | $MCPU = "baseline" | 3 | $MCPU = "baseline" |
| 4 | $ZIG_LLVM_CLANG_LLD_URL = "https://ziglang.org/deps/$ZIG_LLVM_CLANG_LLD_NAME.zip" | 4 | $PREFIX_PATH = "$($Env:USERPROFILE)\$ZIG_LLVM_CLANG_LLD_NAME" |
| 5 | $PREFIX_PATH = "$(Get-Location)\$ZIG_LLVM_CLANG_LLD_NAME" | ||
| 6 | $ZIG = "$PREFIX_PATH\bin\zig.exe" | 5 | $ZIG = "$PREFIX_PATH\bin\zig.exe" |
| 7 | $ZIG_LIB_DIR = "$(Get-Location)\lib" | 6 | $ZIG_LIB_DIR = "$(Get-Location)\lib" |
| 8 | 7 | ||
| 9 | choco install ninja | ||
| 10 | Write-Output "Downloading $ZIG_LLVM_CLANG_LLD_URL" | ||
| 11 | Invoke-WebRequest -Uri "$ZIG_LLVM_CLANG_LLD_URL" -OutFile "$ZIG_LLVM_CLANG_LLD_NAME.zip" | ||
| 12 | |||
| 13 | Write-Output "Extracting..." | ||
| 14 | Add-Type -AssemblyName System.IO.Compression.FileSystem ; | ||
| 15 | [System.IO.Compression.ZipFile]::ExtractToDirectory("$PWD/$ZIG_LLVM_CLANG_LLD_NAME.zip", "$PWD") | ||
| 16 | |||
| 17 | function CheckLastExitCode { | 8 | function CheckLastExitCode { |
| 18 | if (!$?) { | 9 | if (!$?) { |
| 19 | exit 1 | 10 | exit 1 |
| ... | @@ -43,6 +34,8 @@ Set-Location -Path 'build-release' | ... | @@ -43,6 +34,8 @@ Set-Location -Path 'build-release' |
| 43 | -DCMAKE_BUILD_TYPE=Release ` | 34 | -DCMAKE_BUILD_TYPE=Release ` |
| 44 | -DCMAKE_C_COMPILER="$($ZIG -Replace "\\", "/");cc;-target;$TARGET;-mcpu=$MCPU" ` | 35 | -DCMAKE_C_COMPILER="$($ZIG -Replace "\\", "/");cc;-target;$TARGET;-mcpu=$MCPU" ` |
| 45 | -DCMAKE_CXX_COMPILER="$($ZIG -Replace "\\", "/");c++;-target;$TARGET;-mcpu=$MCPU" ` | 36 | -DCMAKE_CXX_COMPILER="$($ZIG -Replace "\\", "/");c++;-target;$TARGET;-mcpu=$MCPU" ` |
| 37 | -DCMAKE_AR="$($ZIG -Replace "\\", "/")" ` | ||
| 38 | -DZIG_AR_WORKAROUND=ON ` | ||
| 46 | -DZIG_TARGET_TRIPLE="$TARGET" ` | 39 | -DZIG_TARGET_TRIPLE="$TARGET" ` |
| 47 | -DZIG_TARGET_MCPU="$MCPU" ` | 40 | -DZIG_TARGET_MCPU="$MCPU" ` |
| 48 | -DZIG_STATIC=ON ` | 41 | -DZIG_STATIC=ON ` |
| ... | @@ -84,10 +77,10 @@ CheckLastExitCode | ... | @@ -84,10 +77,10 @@ CheckLastExitCode |
| 84 | --mod build_options config.zig | 77 | --mod build_options config.zig |
| 85 | CheckLastExitCode | 78 | CheckLastExitCode |
| 86 | 79 | ||
| 87 | Import-Module "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\Microsoft.VisualStudio.DevShell.dll" | 80 | Import-Module "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\Microsoft.VisualStudio.DevShell.dll" |
| 88 | CheckLastExitCode | 81 | CheckLastExitCode |
| 89 | 82 | ||
| 90 | Enter-VsDevShell -VsInstallPath "C:\Program Files\Microsoft Visual Studio\2022\Enterprise" ` | 83 | Enter-VsDevShell -VsInstallPath "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools" ` |
| 91 | -DevCmdArguments '-arch=x64 -no_logo' ` | 84 | -DevCmdArguments '-arch=x64 -no_logo' ` |
| 92 | -StartInPath $(Get-Location) | 85 | -StartInPath $(Get-Location) |
| 93 | CheckLastExitCode | 86 | CheckLastExitCode |
lib/std/math.zig+25| ... | @@ -1588,6 +1588,31 @@ pub const Order = enum { | ... | @@ -1588,6 +1588,31 @@ pub const Order = enum { |
| 1588 | try testing.expect(Order.invert(order(-1, 0)) == .gt); | 1588 | try testing.expect(Order.invert(order(-1, 0)) == .gt); |
| 1589 | } | 1589 | } |
| 1590 | 1590 | ||
| 1591 | pub fn differ(self: Order) ?Order { | ||
| 1592 | return if (self != .eq) self else null; | ||
| 1593 | } | ||
| 1594 | |||
| 1595 | test differ { | ||
| 1596 | const neg: i32 = -1; | ||
| 1597 | const zero: i32 = 0; | ||
| 1598 | const pos: i32 = 1; | ||
| 1599 | try testing.expect(order(zero, neg).differ() orelse | ||
| 1600 | order(pos, zero) == .gt); | ||
| 1601 | try testing.expect(order(zero, zero).differ() orelse | ||
| 1602 | order(zero, zero) == .eq); | ||
| 1603 | try testing.expect(order(pos, pos).differ() orelse | ||
| 1604 | order(neg, zero) == .lt); | ||
| 1605 | try testing.expect(order(zero, zero).differ() orelse | ||
| 1606 | order(pos, neg).differ() orelse | ||
| 1607 | order(neg, zero) == .gt); | ||
| 1608 | try testing.expect(order(pos, pos).differ() orelse | ||
| 1609 | order(pos, pos).differ() orelse | ||
| 1610 | order(neg, neg) == .eq); | ||
| 1611 | try testing.expect(order(zero, pos).differ() orelse | ||
| 1612 | order(neg, pos).differ() orelse | ||
| 1613 | order(pos, neg) == .lt); | ||
| 1614 | } | ||
| 1615 | |||
| 1591 | pub fn compare(self: Order, op: CompareOperator) bool { | 1616 | pub fn compare(self: Order, op: CompareOperator) bool { |
| 1592 | return switch (self) { | 1617 | return switch (self) { |
| 1593 | .lt => switch (op) { | 1618 | .lt => switch (op) { |
lib/std/os/windows.zig+8| ... | @@ -3672,7 +3672,15 @@ pub const SEC_LARGE_PAGES = 0x80000000; | ... | @@ -3672,7 +3672,15 @@ pub const SEC_LARGE_PAGES = 0x80000000; |
| 3672 | pub const HKEY = *opaque {}; | 3672 | pub const HKEY = *opaque {}; |
| 3673 | 3673 | ||
| 3674 | pub const HKEY_CLASSES_ROOT: HKEY = @ptrFromInt(0x80000000); | 3674 | pub const HKEY_CLASSES_ROOT: HKEY = @ptrFromInt(0x80000000); |
| 3675 | pub const HKEY_CURRENT_USER: HKEY = @ptrFromInt(0x80000001); | ||
| 3675 | pub const HKEY_LOCAL_MACHINE: HKEY = @ptrFromInt(0x80000002); | 3676 | pub const HKEY_LOCAL_MACHINE: HKEY = @ptrFromInt(0x80000002); |
| 3677 | pub const HKEY_USERS: HKEY = @ptrFromInt(0x80000003); | ||
| 3678 | pub const HKEY_PERFORMANCE_DATA: HKEY = @ptrFromInt(0x80000004); | ||
| 3679 | pub const HKEY_PERFORMANCE_TEXT: HKEY = @ptrFromInt(0x80000050); | ||
| 3680 | pub const HKEY_PERFORMANCE_NLSTEXT: HKEY = @ptrFromInt(0x80000060); | ||
| 3681 | pub const HKEY_CURRENT_CONFIG: HKEY = @ptrFromInt(0x80000005); | ||
| 3682 | pub const HKEY_DYN_DATA: HKEY = @ptrFromInt(0x80000006); | ||
| 3683 | pub const HKEY_CURRENT_USER_LOCAL_SETTINGS: HKEY = @ptrFromInt(0x80000007); | ||
| 3676 | 3684 | ||
| 3677 | /// Combines the STANDARD_RIGHTS_REQUIRED, KEY_QUERY_VALUE, KEY_SET_VALUE, KEY_CREATE_SUB_KEY, | 3685 | /// Combines the STANDARD_RIGHTS_REQUIRED, KEY_QUERY_VALUE, KEY_SET_VALUE, KEY_CREATE_SUB_KEY, |
| 3678 | /// KEY_ENUMERATE_SUB_KEYS, KEY_NOTIFY, and KEY_CREATE_LINK access rights. | 3686 | /// KEY_ENUMERATE_SUB_KEYS, KEY_NOTIFY, and KEY_CREATE_LINK access rights. |
lib/std/zig/LibCInstallation.zig+33-41| ... | @@ -182,18 +182,18 @@ pub fn findNative(args: FindNativeOptions) FindError!LibCInstallation { | ... | @@ -182,18 +182,18 @@ pub fn findNative(args: FindNativeOptions) FindError!LibCInstallation { |
| 182 | }); | 182 | }); |
| 183 | return self; | 183 | return self; |
| 184 | } else if (is_windows) { | 184 | } else if (is_windows) { |
| 185 | var sdk = std.zig.WindowsSdk.find(args.allocator) catch |err| switch (err) { | 185 | const sdk = std.zig.WindowsSdk.find(args.allocator) catch |err| switch (err) { |
| 186 | error.NotFound => return error.WindowsSdkNotFound, | 186 | error.NotFound => return error.WindowsSdkNotFound, |
| 187 | error.PathTooLong => return error.WindowsSdkNotFound, | 187 | error.PathTooLong => return error.WindowsSdkNotFound, |
| 188 | error.OutOfMemory => return error.OutOfMemory, | 188 | error.OutOfMemory => return error.OutOfMemory, |
| 189 | }; | 189 | }; |
| 190 | defer sdk.free(args.allocator); | 190 | defer sdk.free(args.allocator); |
| 191 | 191 | ||
| 192 | try self.findNativeMsvcIncludeDir(args, &sdk); | 192 | try self.findNativeMsvcIncludeDir(args, sdk); |
| 193 | try self.findNativeMsvcLibDir(args, &sdk); | 193 | try self.findNativeMsvcLibDir(args, sdk); |
| 194 | try self.findNativeKernel32LibDir(args, &sdk); | 194 | try self.findNativeKernel32LibDir(args, sdk); |
| 195 | try self.findNativeIncludeDirWindows(args, &sdk); | 195 | try self.findNativeIncludeDirWindows(args, sdk); |
| 196 | try self.findNativeCrtDirWindows(args, &sdk); | 196 | try self.findNativeCrtDirWindows(args, sdk); |
| 197 | } else if (is_haiku) { | 197 | } else if (is_haiku) { |
| 198 | try self.findNativeIncludeDirPosix(args); | 198 | try self.findNativeIncludeDirPosix(args); |
| 199 | try self.findNativeGccDirHaiku(args); | 199 | try self.findNativeGccDirHaiku(args); |
| ... | @@ -358,19 +358,19 @@ fn findNativeIncludeDirPosix(self: *LibCInstallation, args: FindNativeOptions) F | ... | @@ -358,19 +358,19 @@ fn findNativeIncludeDirPosix(self: *LibCInstallation, args: FindNativeOptions) F |
| 358 | fn findNativeIncludeDirWindows( | 358 | fn findNativeIncludeDirWindows( |
| 359 | self: *LibCInstallation, | 359 | self: *LibCInstallation, |
| 360 | args: FindNativeOptions, | 360 | args: FindNativeOptions, |
| 361 | sdk: *std.zig.WindowsSdk, | 361 | sdk: std.zig.WindowsSdk, |
| 362 | ) FindError!void { | 362 | ) FindError!void { |
| 363 | const allocator = args.allocator; | 363 | const allocator = args.allocator; |
| 364 | 364 | ||
| 365 | var search_buf: [2]Search = undefined; | 365 | var install_buf: [2]std.zig.WindowsSdk.Installation = undefined; |
| 366 | const searches = fillSearch(&search_buf, sdk); | 366 | const installs = fillInstallations(&install_buf, sdk); |
| 367 | 367 | ||
| 368 | var result_buf = std.ArrayList(u8).init(allocator); | 368 | var result_buf = std.ArrayList(u8).init(allocator); |
| 369 | defer result_buf.deinit(); | 369 | defer result_buf.deinit(); |
| 370 | 370 | ||
| 371 | for (searches) |search| { | 371 | for (installs) |install| { |
| 372 | result_buf.shrinkAndFree(0); | 372 | result_buf.shrinkAndFree(0); |
| 373 | try result_buf.writer().print("{s}\\Include\\{s}\\ucrt", .{ search.path, search.version }); | 373 | try result_buf.writer().print("{s}\\Include\\{s}\\ucrt", .{ install.path, install.version }); |
| 374 | 374 | ||
| 375 | var dir = fs.cwd().openDir(result_buf.items, .{}) catch |err| switch (err) { | 375 | var dir = fs.cwd().openDir(result_buf.items, .{}) catch |err| switch (err) { |
| 376 | error.FileNotFound, | 376 | error.FileNotFound, |
| ... | @@ -397,12 +397,12 @@ fn findNativeIncludeDirWindows( | ... | @@ -397,12 +397,12 @@ fn findNativeIncludeDirWindows( |
| 397 | fn findNativeCrtDirWindows( | 397 | fn findNativeCrtDirWindows( |
| 398 | self: *LibCInstallation, | 398 | self: *LibCInstallation, |
| 399 | args: FindNativeOptions, | 399 | args: FindNativeOptions, |
| 400 | sdk: *std.zig.WindowsSdk, | 400 | sdk: std.zig.WindowsSdk, |
| 401 | ) FindError!void { | 401 | ) FindError!void { |
| 402 | const allocator = args.allocator; | 402 | const allocator = args.allocator; |
| 403 | 403 | ||
| 404 | var search_buf: [2]Search = undefined; | 404 | var install_buf: [2]std.zig.WindowsSdk.Installation = undefined; |
| 405 | const searches = fillSearch(&search_buf, sdk); | 405 | const installs = fillInstallations(&install_buf, sdk); |
| 406 | 406 | ||
| 407 | var result_buf = std.ArrayList(u8).init(allocator); | 407 | var result_buf = std.ArrayList(u8).init(allocator); |
| 408 | defer result_buf.deinit(); | 408 | defer result_buf.deinit(); |
| ... | @@ -415,9 +415,9 @@ fn findNativeCrtDirWindows( | ... | @@ -415,9 +415,9 @@ fn findNativeCrtDirWindows( |
| 415 | else => return error.UnsupportedArchitecture, | 415 | else => return error.UnsupportedArchitecture, |
| 416 | }; | 416 | }; |
| 417 | 417 | ||
| 418 | for (searches) |search| { | 418 | for (installs) |install| { |
| 419 | result_buf.shrinkAndFree(0); | 419 | result_buf.shrinkAndFree(0); |
| 420 | try result_buf.writer().print("{s}\\Lib\\{s}\\ucrt\\{s}", .{ search.path, search.version, arch_sub_dir }); | 420 | try result_buf.writer().print("{s}\\Lib\\{s}\\ucrt\\{s}", .{ install.path, install.version, arch_sub_dir }); |
| 421 | 421 | ||
| 422 | var dir = fs.cwd().openDir(result_buf.items, .{}) catch |err| switch (err) { | 422 | var dir = fs.cwd().openDir(result_buf.items, .{}) catch |err| switch (err) { |
| 423 | error.FileNotFound, | 423 | error.FileNotFound, |
| ... | @@ -464,12 +464,12 @@ fn findNativeGccDirHaiku(self: *LibCInstallation, args: FindNativeOptions) FindE | ... | @@ -464,12 +464,12 @@ fn findNativeGccDirHaiku(self: *LibCInstallation, args: FindNativeOptions) FindE |
| 464 | fn findNativeKernel32LibDir( | 464 | fn findNativeKernel32LibDir( |
| 465 | self: *LibCInstallation, | 465 | self: *LibCInstallation, |
| 466 | args: FindNativeOptions, | 466 | args: FindNativeOptions, |
| 467 | sdk: *std.zig.WindowsSdk, | 467 | sdk: std.zig.WindowsSdk, |
| 468 | ) FindError!void { | 468 | ) FindError!void { |
| 469 | const allocator = args.allocator; | 469 | const allocator = args.allocator; |
| 470 | 470 | ||
| 471 | var search_buf: [2]Search = undefined; | 471 | var install_buf: [2]std.zig.WindowsSdk.Installation = undefined; |
| 472 | const searches = fillSearch(&search_buf, sdk); | 472 | const installs = fillInstallations(&install_buf, sdk); |
| 473 | 473 | ||
| 474 | var result_buf = std.ArrayList(u8).init(allocator); | 474 | var result_buf = std.ArrayList(u8).init(allocator); |
| 475 | defer result_buf.deinit(); | 475 | defer result_buf.deinit(); |
| ... | @@ -482,10 +482,10 @@ fn findNativeKernel32LibDir( | ... | @@ -482,10 +482,10 @@ fn findNativeKernel32LibDir( |
| 482 | else => return error.UnsupportedArchitecture, | 482 | else => return error.UnsupportedArchitecture, |
| 483 | }; | 483 | }; |
| 484 | 484 | ||
| 485 | for (searches) |search| { | 485 | for (installs) |install| { |
| 486 | result_buf.shrinkAndFree(0); | 486 | result_buf.shrinkAndFree(0); |
| 487 | const stream = result_buf.writer(); | 487 | const stream = result_buf.writer(); |
| 488 | try stream.print("{s}\\Lib\\{s}\\um\\{s}", .{ search.path, search.version, arch_sub_dir }); | 488 | try stream.print("{s}\\Lib\\{s}\\um\\{s}", .{ install.path, install.version, arch_sub_dir }); |
| 489 | 489 | ||
| 490 | var dir = fs.cwd().openDir(result_buf.items, .{}) catch |err| switch (err) { | 490 | var dir = fs.cwd().openDir(result_buf.items, .{}) catch |err| switch (err) { |
| 491 | error.FileNotFound, | 491 | error.FileNotFound, |
| ... | @@ -511,7 +511,7 @@ fn findNativeKernel32LibDir( | ... | @@ -511,7 +511,7 @@ fn findNativeKernel32LibDir( |
| 511 | fn findNativeMsvcIncludeDir( | 511 | fn findNativeMsvcIncludeDir( |
| 512 | self: *LibCInstallation, | 512 | self: *LibCInstallation, |
| 513 | args: FindNativeOptions, | 513 | args: FindNativeOptions, |
| 514 | sdk: *std.zig.WindowsSdk, | 514 | sdk: std.zig.WindowsSdk, |
| 515 | ) FindError!void { | 515 | ) FindError!void { |
| 516 | const allocator = args.allocator; | 516 | const allocator = args.allocator; |
| 517 | 517 | ||
| ... | @@ -543,7 +543,7 @@ fn findNativeMsvcIncludeDir( | ... | @@ -543,7 +543,7 @@ fn findNativeMsvcIncludeDir( |
| 543 | fn findNativeMsvcLibDir( | 543 | fn findNativeMsvcLibDir( |
| 544 | self: *LibCInstallation, | 544 | self: *LibCInstallation, |
| 545 | args: FindNativeOptions, | 545 | args: FindNativeOptions, |
| 546 | sdk: *std.zig.WindowsSdk, | 546 | sdk: std.zig.WindowsSdk, |
| 547 | ) FindError!void { | 547 | ) FindError!void { |
| 548 | const allocator = args.allocator; | 548 | const allocator = args.allocator; |
| 549 | const msvc_lib_dir = sdk.msvc_lib_dir orelse return error.LibCRuntimeNotFound; | 549 | const msvc_lib_dir = sdk.msvc_lib_dir orelse return error.LibCRuntimeNotFound; |
| ... | @@ -654,28 +654,20 @@ fn printVerboseInvocation( | ... | @@ -654,28 +654,20 @@ fn printVerboseInvocation( |
| 654 | } | 654 | } |
| 655 | } | 655 | } |
| 656 | 656 | ||
| 657 | const Search = struct { | 657 | fn fillInstallations( |
| 658 | path: []const u8, | 658 | installs: *[2]std.zig.WindowsSdk.Installation, |
| 659 | version: []const u8, | 659 | sdk: std.zig.WindowsSdk, |
| 660 | }; | 660 | ) []std.zig.WindowsSdk.Installation { |
| 661 | 661 | var installs_len: usize = 0; | |
| 662 | fn fillSearch(search_buf: *[2]Search, sdk: *std.zig.WindowsSdk) []Search { | ||
| 663 | var search_end: usize = 0; | ||
| 664 | if (sdk.windows10sdk) |windows10sdk| { | 662 | if (sdk.windows10sdk) |windows10sdk| { |
| 665 | search_buf[search_end] = .{ | 663 | installs[installs_len] = windows10sdk; |
| 666 | .path = windows10sdk.path, | 664 | installs_len += 1; |
| 667 | .version = windows10sdk.version, | ||
| 668 | }; | ||
| 669 | search_end += 1; | ||
| 670 | } | 665 | } |
| 671 | if (sdk.windows81sdk) |windows81sdk| { | 666 | if (sdk.windows81sdk) |windows81sdk| { |
| 672 | search_buf[search_end] = .{ | 667 | installs[installs_len] = windows81sdk; |
| 673 | .path = windows81sdk.path, | 668 | installs_len += 1; |
| 674 | .version = windows81sdk.version, | ||
| 675 | }; | ||
| 676 | search_end += 1; | ||
| 677 | } | 669 | } |
| 678 | return search_buf[0..search_end]; | 670 | return installs[0..installs_len]; |
| 679 | } | 671 | } |
| 680 | 672 | ||
| 681 | const inf_loop_env_key = "ZIG_IS_DETECTING_LIBC_PATHS"; | 673 | const inf_loop_env_key = "ZIG_IS_DETECTING_LIBC_PATHS"; |
lib/std/zig/WindowsSdk.zig+218-212| ... | @@ -1,5 +1,5 @@ | ... | @@ -1,5 +1,5 @@ |
| 1 | windows10sdk: ?Windows10Sdk, | 1 | windows10sdk: ?Installation, |
| 2 | windows81sdk: ?Windows81Sdk, | 2 | windows81sdk: ?Installation, |
| 3 | msvc_lib_dir: ?[]const u8, | 3 | msvc_lib_dir: ?[]const u8, |
| 4 | 4 | ||
| 5 | const WindowsSdk = @This(); | 5 | const WindowsSdk = @This(); |
| ... | @@ -9,7 +9,7 @@ const builtin = @import("builtin"); | ... | @@ -9,7 +9,7 @@ const builtin = @import("builtin"); |
| 9 | const windows = std.os.windows; | 9 | const windows = std.os.windows; |
| 10 | const RRF = windows.advapi32.RRF; | 10 | const RRF = windows.advapi32.RRF; |
| 11 | 11 | ||
| 12 | const WINDOWS_KIT_REG_KEY = "SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots"; | 12 | const windows_kits_reg_key = "SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots"; |
| 13 | 13 | ||
| 14 | // https://learn.microsoft.com/en-us/windows/win32/msi/productversion | 14 | // https://learn.microsoft.com/en-us/windows/win32/msi/productversion |
| 15 | const version_major_minor_max_length = "255.255".len; | 15 | const version_major_minor_max_length = "255.255".len; |
| ... | @@ -23,34 +23,24 @@ pub fn find(allocator: std.mem.Allocator) error{ OutOfMemory, NotFound, PathTooL | ... | @@ -23,34 +23,24 @@ pub fn find(allocator: std.mem.Allocator) error{ OutOfMemory, NotFound, PathTooL |
| 23 | if (builtin.os.tag != .windows) return error.NotFound; | 23 | if (builtin.os.tag != .windows) return error.NotFound; |
| 24 | 24 | ||
| 25 | //note(dimenus): If this key doesn't exist, neither the Win 8 SDK nor the Win 10 SDK is installed | 25 | //note(dimenus): If this key doesn't exist, neither the Win 8 SDK nor the Win 10 SDK is installed |
| 26 | const roots_key = RegistryWtf8.openKey(windows.HKEY_LOCAL_MACHINE, WINDOWS_KIT_REG_KEY) catch |err| switch (err) { | 26 | const roots_key = RegistryWtf8.openKey(windows.HKEY_LOCAL_MACHINE, windows_kits_reg_key) catch |err| switch (err) { |
| 27 | error.KeyNotFound => return error.NotFound, | 27 | error.KeyNotFound => return error.NotFound, |
| 28 | }; | 28 | }; |
| 29 | defer roots_key.closeKey(); | 29 | defer roots_key.closeKey(); |
| 30 | 30 | ||
| 31 | const windows10sdk: ?Windows10Sdk = blk: { | 31 | const windows10sdk = Installation.find(allocator, roots_key, "KitsRoot10", "", "v10.0") catch |err| switch (err) { |
| 32 | const windows10sdk = Windows10Sdk.find(allocator) catch |err| switch (err) { | 32 | error.InstallationNotFound => null, |
| 33 | error.Windows10SdkNotFound, | 33 | error.PathTooLong => null, |
| 34 | error.PathTooLong, | 34 | error.VersionTooLong => null, |
| 35 | error.VersionTooLong, | 35 | error.OutOfMemory => return error.OutOfMemory, |
| 36 | => break :blk null, | ||
| 37 | error.OutOfMemory => return error.OutOfMemory, | ||
| 38 | }; | ||
| 39 | const is_valid_version = windows10sdk.isValidVersion(); | ||
| 40 | if (!is_valid_version) break :blk null; | ||
| 41 | break :blk windows10sdk; | ||
| 42 | }; | 36 | }; |
| 43 | errdefer if (windows10sdk) |*w| w.free(allocator); | 37 | errdefer if (windows10sdk) |*w| w.free(allocator); |
| 44 | 38 | ||
| 45 | const windows81sdk: ?Windows81Sdk = blk: { | 39 | const windows81sdk = Installation.find(allocator, roots_key, "KitsRoot81", "winver", "v8.1") catch |err| switch (err) { |
| 46 | const windows81sdk = Windows81Sdk.find(allocator, &roots_key) catch |err| switch (err) { | 40 | error.InstallationNotFound => null, |
| 47 | error.Windows81SdkNotFound => break :blk null, | 41 | error.PathTooLong => null, |
| 48 | error.PathTooLong => break :blk null, | 42 | error.VersionTooLong => null, |
| 49 | error.VersionTooLong => break :blk null, | 43 | error.OutOfMemory => return error.OutOfMemory, |
| 50 | error.OutOfMemory => return error.OutOfMemory, | ||
| 51 | }; | ||
| 52 | // no check | ||
| 53 | break :blk windows81sdk; | ||
| 54 | }; | 44 | }; |
| 55 | errdefer if (windows81sdk) |*w| w.free(allocator); | 45 | errdefer if (windows81sdk) |*w| w.free(allocator); |
| 56 | 46 | ||
| ... | @@ -60,96 +50,91 @@ pub fn find(allocator: std.mem.Allocator) error{ OutOfMemory, NotFound, PathTooL | ... | @@ -60,96 +50,91 @@ pub fn find(allocator: std.mem.Allocator) error{ OutOfMemory, NotFound, PathTooL |
| 60 | }; | 50 | }; |
| 61 | errdefer allocator.free(msvc_lib_dir); | 51 | errdefer allocator.free(msvc_lib_dir); |
| 62 | 52 | ||
| 63 | return WindowsSdk{ | 53 | return .{ |
| 64 | .windows10sdk = windows10sdk, | 54 | .windows10sdk = windows10sdk, |
| 65 | .windows81sdk = windows81sdk, | 55 | .windows81sdk = windows81sdk, |
| 66 | .msvc_lib_dir = msvc_lib_dir, | 56 | .msvc_lib_dir = msvc_lib_dir, |
| 67 | }; | 57 | }; |
| 68 | } | 58 | } |
| 69 | 59 | ||
| 70 | pub fn free(self: *const WindowsSdk, allocator: std.mem.Allocator) void { | 60 | pub fn free(sdk: WindowsSdk, allocator: std.mem.Allocator) void { |
| 71 | if (self.windows10sdk) |*w10sdk| { | 61 | if (sdk.windows10sdk) |*w10sdk| { |
| 72 | w10sdk.free(allocator); | 62 | w10sdk.free(allocator); |
| 73 | } | 63 | } |
| 74 | if (self.windows81sdk) |*w81sdk| { | 64 | if (sdk.windows81sdk) |*w81sdk| { |
| 75 | w81sdk.free(allocator); | 65 | w81sdk.free(allocator); |
| 76 | } | 66 | } |
| 77 | if (self.msvc_lib_dir) |msvc_lib_dir| { | 67 | if (sdk.msvc_lib_dir) |msvc_lib_dir| { |
| 78 | allocator.free(msvc_lib_dir); | 68 | allocator.free(msvc_lib_dir); |
| 79 | } | 69 | } |
| 80 | } | 70 | } |
| 81 | 71 | ||
| 82 | /// Iterates via `iterator` and collects all folders with names starting with `optional_prefix` | 72 | /// Iterates via `iterator` and collects all folders with names starting with `strip_prefix` |
| 83 | /// and similar to SemVer. Returns slice of folder names sorted in descending order. | 73 | /// and a version. Returns slice of version strings sorted in descending order. |
| 84 | /// Caller owns result. | 74 | /// Caller owns result. |
| 85 | fn iterateAndFilterBySemVer( | 75 | fn iterateAndFilterByVersion( |
| 86 | iterator: *std.fs.Dir.Iterator, | 76 | iterator: *std.fs.Dir.Iterator, |
| 87 | allocator: std.mem.Allocator, | 77 | allocator: std.mem.Allocator, |
| 88 | comptime optional_prefix: ?[]const u8, | 78 | prefix: []const u8, |
| 89 | ) error{ OutOfMemory, VersionNotFound }![][]const u8 { | 79 | ) error{OutOfMemory}![][]const u8 { |
| 90 | var dirs_filtered_list = std.ArrayList([]const u8).init(allocator); | 80 | const Version = struct { |
| 91 | errdefer { | 81 | nums: [4]u32, |
| 92 | for (dirs_filtered_list.items) |filtered_dir| allocator.free(filtered_dir); | 82 | build: []const u8, |
| 93 | dirs_filtered_list.deinit(); | 83 | |
| 94 | } | 84 | fn parseNum(num: []const u8) ?u32 { |
| 95 | 85 | if (num[0] == '0' and num.len > 1) return null; | |
| 96 | var normalized_name_buf: [std.fs.MAX_NAME_BYTES + ".0+build.0".len]u8 = undefined; | 86 | return std.fmt.parseInt(u32, num, 10) catch null; |
| 97 | var normalized_name_fbs = std.io.fixedBufferStream(&normalized_name_buf); | 87 | } |
| 98 | const normalized_name_w = normalized_name_fbs.writer(); | ||
| 99 | iterate_folder: while (true) : (normalized_name_fbs.reset()) { | ||
| 100 | const maybe_entry = iterator.next() catch continue :iterate_folder; | ||
| 101 | const entry = maybe_entry orelse break :iterate_folder; | ||
| 102 | |||
| 103 | if (entry.kind != .directory) | ||
| 104 | continue :iterate_folder; | ||
| 105 | |||
| 106 | // invalidated on next iteration | ||
| 107 | const subfolder_name = blk: { | ||
| 108 | if (comptime optional_prefix) |prefix| { | ||
| 109 | if (!std.mem.startsWith(u8, entry.name, prefix)) continue :iterate_folder; | ||
| 110 | break :blk entry.name[prefix.len..]; | ||
| 111 | } else break :blk entry.name; | ||
| 112 | }; | ||
| 113 | |||
| 114 | { // check if subfolder name looks similar to SemVer | ||
| 115 | switch (std.mem.count(u8, subfolder_name, ".")) { | ||
| 116 | 0 => normalized_name_w.print("{s}.0.0+build.0", .{subfolder_name}) catch unreachable, // 17 => 17.0.0+build.0 | ||
| 117 | 1 => if (std.mem.indexOfScalar(u8, subfolder_name, '_')) |underscore_pos| blk: { // 17.0_9e9cbb98 => 17.0.1+build.9e9cbb98 | ||
| 118 | var subfolder_name_tmp_copy_buf: [std.fs.MAX_NAME_BYTES]u8 = undefined; | ||
| 119 | const subfolder_name_tmp_copy = subfolder_name_tmp_copy_buf[0..subfolder_name.len]; | ||
| 120 | @memcpy(subfolder_name_tmp_copy, subfolder_name); | ||
| 121 | |||
| 122 | subfolder_name_tmp_copy[underscore_pos] = '.'; // 17.0_9e9cbb98 => 17.0.9e9cbb98 | ||
| 123 | var subfolder_name_parts = std.mem.splitScalar(u8, subfolder_name_tmp_copy, '.'); // [ 17, 0, 9e9cbb98 ] | ||
| 124 | |||
| 125 | const first = subfolder_name_parts.first(); // 17 | ||
| 126 | const second = subfolder_name_parts.next().?; // 0 | ||
| 127 | const third = subfolder_name_parts.rest(); // 9e9cbb98 | ||
| 128 | 88 | ||
| 129 | break :blk normalized_name_w.print("{s}.{s}.1+build.{s}", .{ first, second, third }) catch unreachable; // [ 17, 0, 9e9cbb98 ] => 17.0.1+build.9e9cbb98 | 89 | fn order(lhs: @This(), rhs: @This()) std.math.Order { |
| 130 | } else normalized_name_w.print("{s}.0+build.0", .{subfolder_name}) catch unreachable, // 17.0 => 17.0.0+build.0 | 90 | return std.mem.order(u32, &lhs.nums, &rhs.nums).differ() orelse |
| 131 | else => normalized_name_w.print("{s}+build.0", .{subfolder_name}) catch unreachable, // 17.0.0 => 17.0.0+build.0 | 91 | std.mem.order(u8, lhs.build, rhs.build); |
| 132 | } | ||
| 133 | const subfolder_name_normalized: []const u8 = normalized_name_fbs.getWritten(); | ||
| 134 | const sem_ver = std.SemanticVersion.parse(subfolder_name_normalized); | ||
| 135 | _ = sem_ver catch continue :iterate_folder; | ||
| 136 | } | 92 | } |
| 137 | // entry.name passed check | 93 | }; |
| 94 | var versions = std.ArrayList(Version).init(allocator); | ||
| 95 | var dirs = std.ArrayList([]const u8).init(allocator); | ||
| 96 | defer { | ||
| 97 | versions.deinit(); | ||
| 98 | for (dirs.items) |filtered_dir| allocator.free(filtered_dir); | ||
| 99 | dirs.deinit(); | ||
| 100 | } | ||
| 101 | |||
| 102 | iterate: while (iterator.next() catch null) |entry| { | ||
| 103 | if (entry.kind != .directory) continue; | ||
| 104 | if (!std.mem.startsWith(u8, entry.name, prefix)) continue; | ||
| 138 | 105 | ||
| 139 | const subfolder_name_allocated = try allocator.dupe(u8, subfolder_name); | 106 | var version: Version = .{ |
| 140 | errdefer allocator.free(subfolder_name_allocated); | 107 | .nums = .{0} ** 4, |
| 141 | try dirs_filtered_list.append(subfolder_name_allocated); | 108 | .build = "", |
| 109 | }; | ||
| 110 | const suffix = entry.name[prefix.len..]; | ||
| 111 | const underscore = std.mem.indexOfScalar(u8, entry.name, '_'); | ||
| 112 | var num_it = std.mem.splitScalar(u8, suffix[0 .. underscore orelse suffix.len], '.'); | ||
| 113 | version.nums[0] = Version.parseNum(num_it.first()) orelse continue; | ||
| 114 | for (version.nums[1..]) |*num| | ||
| 115 | num.* = Version.parseNum(num_it.next() orelse break) orelse continue :iterate | ||
| 116 | else if (num_it.next()) |_| continue; | ||
| 117 | |||
| 118 | const name = try allocator.dupe(u8, suffix); | ||
| 119 | errdefer allocator.free(name); | ||
| 120 | if (underscore) |pos| version.build = name[pos + 1 ..]; | ||
| 121 | |||
| 122 | try versions.append(version); | ||
| 123 | try dirs.append(name); | ||
| 142 | } | 124 | } |
| 143 | 125 | ||
| 144 | const dirs_filtered_slice = try dirs_filtered_list.toOwnedSlice(); | 126 | std.mem.sortUnstableContext(0, dirs.items.len, struct { |
| 145 | // Keep in mind that order of these names is not guaranteed by Windows, | 127 | versions: []Version, |
| 146 | // so we cannot just reverse or "while (popOrNull())" this ArrayList. | 128 | dirs: [][]const u8, |
| 147 | std.mem.sortUnstable([]const u8, dirs_filtered_slice, {}, struct { | 129 | pub fn lessThan(context: @This(), lhs: usize, rhs: usize) bool { |
| 148 | fn desc(_: void, lhs: []const u8, rhs: []const u8) bool { | 130 | return context.versions[lhs].order(context.versions[rhs]).compare(.gt); |
| 149 | return std.mem.order(u8, lhs, rhs) == .gt; | 131 | } |
| 132 | pub fn swap(context: @This(), lhs: usize, rhs: usize) void { | ||
| 133 | std.mem.swap(Version, &context.versions[lhs], &context.versions[rhs]); | ||
| 134 | std.mem.swap([]const u8, &context.dirs[lhs], &context.dirs[rhs]); | ||
| 150 | } | 135 | } |
| 151 | }.desc); | 136 | }{ .versions = versions.items, .dirs = dirs.items }); |
| 152 | return dirs_filtered_slice; | 137 | return dirs.toOwnedSlice(); |
| 153 | } | 138 | } |
| 154 | 139 | ||
| 155 | const RegistryWtf8 = struct { | 140 | const RegistryWtf8 = struct { |
| ... | @@ -167,12 +152,12 @@ const RegistryWtf8 = struct { | ... | @@ -167,12 +152,12 @@ const RegistryWtf8 = struct { |
| 167 | }; | 152 | }; |
| 168 | 153 | ||
| 169 | const registry_wtf16le = try RegistryWtf16Le.openKey(hkey, key_wtf16le); | 154 | const registry_wtf16le = try RegistryWtf16Le.openKey(hkey, key_wtf16le); |
| 170 | return RegistryWtf8{ .key = registry_wtf16le.key }; | 155 | return .{ .key = registry_wtf16le.key }; |
| 171 | } | 156 | } |
| 172 | 157 | ||
| 173 | /// Closes key, after that usage is invalid | 158 | /// Closes key, after that usage is invalid |
| 174 | pub fn closeKey(self: *const RegistryWtf8) void { | 159 | pub fn closeKey(reg: RegistryWtf8) void { |
| 175 | const return_code_int: windows.HRESULT = windows.advapi32.RegCloseKey(self.key); | 160 | const return_code_int: windows.HRESULT = windows.advapi32.RegCloseKey(reg.key); |
| 176 | const return_code: windows.Win32Error = @enumFromInt(return_code_int); | 161 | const return_code: windows.Win32Error = @enumFromInt(return_code_int); |
| 177 | switch (return_code) { | 162 | switch (return_code) { |
| 178 | .SUCCESS => {}, | 163 | .SUCCESS => {}, |
| ... | @@ -182,7 +167,7 @@ const RegistryWtf8 = struct { | ... | @@ -182,7 +167,7 @@ const RegistryWtf8 = struct { |
| 182 | 167 | ||
| 183 | /// Get string from registry. | 168 | /// Get string from registry. |
| 184 | /// Caller owns result. | 169 | /// Caller owns result. |
| 185 | pub fn getString(self: *const RegistryWtf8, allocator: std.mem.Allocator, subkey: []const u8, value_name: []const u8) error{ OutOfMemory, ValueNameNotFound, NotAString, StringNotFound }![]u8 { | 170 | pub fn getString(reg: RegistryWtf8, allocator: std.mem.Allocator, subkey: []const u8, value_name: []const u8) error{ OutOfMemory, ValueNameNotFound, NotAString, StringNotFound }![]u8 { |
| 186 | const subkey_wtf16le: [:0]const u16 = subkey_wtf16le: { | 171 | const subkey_wtf16le: [:0]const u16 = subkey_wtf16le: { |
| 187 | var subkey_wtf16le_buf: [RegistryWtf16Le.key_name_max_len]u16 = undefined; | 172 | var subkey_wtf16le_buf: [RegistryWtf16Le.key_name_max_len]u16 = undefined; |
| 188 | const subkey_wtf16le_len: usize = std.unicode.wtf8ToWtf16Le(subkey_wtf16le_buf[0..], subkey) catch unreachable; | 173 | const subkey_wtf16le_len: usize = std.unicode.wtf8ToWtf16Le(subkey_wtf16le_buf[0..], subkey) catch unreachable; |
| ... | @@ -197,7 +182,7 @@ const RegistryWtf8 = struct { | ... | @@ -197,7 +182,7 @@ const RegistryWtf8 = struct { |
| 197 | break :value_name_wtf16le value_name_wtf16le_buf[0..value_name_wtf16le_len :0]; | 182 | break :value_name_wtf16le value_name_wtf16le_buf[0..value_name_wtf16le_len :0]; |
| 198 | }; | 183 | }; |
| 199 | 184 | ||
| 200 | const registry_wtf16le = RegistryWtf16Le{ .key = self.key }; | 185 | const registry_wtf16le: RegistryWtf16Le = .{ .key = reg.key }; |
| 201 | const value_wtf16le = try registry_wtf16le.getString(allocator, subkey_wtf16le, value_name_wtf16le); | 186 | const value_wtf16le = try registry_wtf16le.getString(allocator, subkey_wtf16le, value_name_wtf16le); |
| 202 | defer allocator.free(value_wtf16le); | 187 | defer allocator.free(value_wtf16le); |
| 203 | 188 | ||
| ... | @@ -208,7 +193,7 @@ const RegistryWtf8 = struct { | ... | @@ -208,7 +193,7 @@ const RegistryWtf8 = struct { |
| 208 | } | 193 | } |
| 209 | 194 | ||
| 210 | /// Get DWORD (u32) from registry. | 195 | /// Get DWORD (u32) from registry. |
| 211 | pub fn getDword(self: *const RegistryWtf8, subkey: []const u8, value_name: []const u8) error{ ValueNameNotFound, NotADword, DwordTooLong, DwordNotFound }!u32 { | 196 | pub fn getDword(reg: RegistryWtf8, subkey: []const u8, value_name: []const u8) error{ ValueNameNotFound, NotADword, DwordTooLong, DwordNotFound }!u32 { |
| 212 | const subkey_wtf16le: [:0]const u16 = subkey_wtf16le: { | 197 | const subkey_wtf16le: [:0]const u16 = subkey_wtf16le: { |
| 213 | var subkey_wtf16le_buf: [RegistryWtf16Le.key_name_max_len]u16 = undefined; | 198 | var subkey_wtf16le_buf: [RegistryWtf16Le.key_name_max_len]u16 = undefined; |
| 214 | const subkey_wtf16le_len: usize = std.unicode.wtf8ToWtf16Le(subkey_wtf16le_buf[0..], subkey) catch unreachable; | 199 | const subkey_wtf16le_len: usize = std.unicode.wtf8ToWtf16Le(subkey_wtf16le_buf[0..], subkey) catch unreachable; |
| ... | @@ -223,8 +208,8 @@ const RegistryWtf8 = struct { | ... | @@ -223,8 +208,8 @@ const RegistryWtf8 = struct { |
| 223 | break :value_name_wtf16le value_name_wtf16le_buf[0..value_name_wtf16le_len :0]; | 208 | break :value_name_wtf16le value_name_wtf16le_buf[0..value_name_wtf16le_len :0]; |
| 224 | }; | 209 | }; |
| 225 | 210 | ||
| 226 | const registry_wtf16le = RegistryWtf16Le{ .key = self.key }; | 211 | const registry_wtf16le: RegistryWtf16Le = .{ .key = reg.key }; |
| 227 | return try registry_wtf16le.getDword(subkey_wtf16le, value_name_wtf16le); | 212 | return registry_wtf16le.getDword(subkey_wtf16le, value_name_wtf16le); |
| 228 | } | 213 | } |
| 229 | 214 | ||
| 230 | /// Under private space with flags: | 215 | /// Under private space with flags: |
| ... | @@ -239,7 +224,7 @@ const RegistryWtf8 = struct { | ... | @@ -239,7 +224,7 @@ const RegistryWtf8 = struct { |
| 239 | }; | 224 | }; |
| 240 | 225 | ||
| 241 | const registry_wtf16le = try RegistryWtf16Le.loadFromPath(absolute_path_wtf16le); | 226 | const registry_wtf16le = try RegistryWtf16Le.loadFromPath(absolute_path_wtf16le); |
| 242 | return RegistryWtf8{ .key = registry_wtf16le.key }; | 227 | return .{ .key = registry_wtf16le.key }; |
| 243 | } | 228 | } |
| 244 | }; | 229 | }; |
| 245 | 230 | ||
| ... | @@ -272,12 +257,12 @@ const RegistryWtf16Le = struct { | ... | @@ -272,12 +257,12 @@ const RegistryWtf16Le = struct { |
| 272 | 257 | ||
| 273 | else => return error.KeyNotFound, | 258 | else => return error.KeyNotFound, |
| 274 | } | 259 | } |
| 275 | return RegistryWtf16Le{ .key = key }; | 260 | return .{ .key = key }; |
| 276 | } | 261 | } |
| 277 | 262 | ||
| 278 | /// Closes key, after that usage is invalid | 263 | /// Closes key, after that usage is invalid |
| 279 | fn closeKey(self: *const RegistryWtf16Le) void { | 264 | fn closeKey(reg: RegistryWtf16Le) void { |
| 280 | const return_code_int: windows.HRESULT = windows.advapi32.RegCloseKey(self.key); | 265 | const return_code_int: windows.HRESULT = windows.advapi32.RegCloseKey(reg.key); |
| 281 | const return_code: windows.Win32Error = @enumFromInt(return_code_int); | 266 | const return_code: windows.Win32Error = @enumFromInt(return_code_int); |
| 282 | switch (return_code) { | 267 | switch (return_code) { |
| 283 | .SUCCESS => {}, | 268 | .SUCCESS => {}, |
| ... | @@ -286,13 +271,13 @@ const RegistryWtf16Le = struct { | ... | @@ -286,13 +271,13 @@ const RegistryWtf16Le = struct { |
| 286 | } | 271 | } |
| 287 | 272 | ||
| 288 | /// Get string ([:0]const u16) from registry. | 273 | /// Get string ([:0]const u16) from registry. |
| 289 | fn getString(self: *const RegistryWtf16Le, allocator: std.mem.Allocator, subkey_wtf16le: [:0]const u16, value_name_wtf16le: [:0]const u16) error{ OutOfMemory, ValueNameNotFound, NotAString, StringNotFound }![]const u16 { | 274 | fn getString(reg: RegistryWtf16Le, allocator: std.mem.Allocator, subkey_wtf16le: [:0]const u16, value_name_wtf16le: [:0]const u16) error{ OutOfMemory, ValueNameNotFound, NotAString, StringNotFound }![]const u16 { |
| 290 | var actual_type: windows.ULONG = undefined; | 275 | var actual_type: windows.ULONG = undefined; |
| 291 | 276 | ||
| 292 | // Calculating length to allocate | 277 | // Calculating length to allocate |
| 293 | var value_wtf16le_buf_size: u32 = 0; // in bytes, including any terminating NUL character or characters. | 278 | var value_wtf16le_buf_size: u32 = 0; // in bytes, including any terminating NUL character or characters. |
| 294 | var return_code_int: windows.HRESULT = windows.advapi32.RegGetValueW( | 279 | var return_code_int: windows.HRESULT = windows.advapi32.RegGetValueW( |
| 295 | self.key, | 280 | reg.key, |
| 296 | subkey_wtf16le, | 281 | subkey_wtf16le, |
| 297 | value_name_wtf16le, | 282 | value_name_wtf16le, |
| 298 | RRF.RT_REG_SZ, | 283 | RRF.RT_REG_SZ, |
| ... | @@ -319,7 +304,7 @@ const RegistryWtf16Le = struct { | ... | @@ -319,7 +304,7 @@ const RegistryWtf16Le = struct { |
| 319 | errdefer allocator.free(value_wtf16le_buf); | 304 | errdefer allocator.free(value_wtf16le_buf); |
| 320 | 305 | ||
| 321 | return_code_int = windows.advapi32.RegGetValueW( | 306 | return_code_int = windows.advapi32.RegGetValueW( |
| 322 | self.key, | 307 | reg.key, |
| 323 | subkey_wtf16le, | 308 | subkey_wtf16le, |
| 324 | value_name_wtf16le, | 309 | value_name_wtf16le, |
| 325 | RRF.RT_REG_SZ, | 310 | RRF.RT_REG_SZ, |
| ... | @@ -355,13 +340,13 @@ const RegistryWtf16Le = struct { | ... | @@ -355,13 +340,13 @@ const RegistryWtf16Le = struct { |
| 355 | } | 340 | } |
| 356 | 341 | ||
| 357 | /// Get DWORD (u32) from registry. | 342 | /// Get DWORD (u32) from registry. |
| 358 | fn getDword(self: *const RegistryWtf16Le, subkey_wtf16le: [:0]const u16, value_name_wtf16le: [:0]const u16) error{ ValueNameNotFound, NotADword, DwordTooLong, DwordNotFound }!u32 { | 343 | fn getDword(reg: RegistryWtf16Le, subkey_wtf16le: [:0]const u16, value_name_wtf16le: [:0]const u16) error{ ValueNameNotFound, NotADword, DwordTooLong, DwordNotFound }!u32 { |
| 359 | var actual_type: windows.ULONG = undefined; | 344 | var actual_type: windows.ULONG = undefined; |
| 360 | var reg_size: u32 = @sizeOf(u32); | 345 | var reg_size: u32 = @sizeOf(u32); |
| 361 | var reg_value: u32 = 0; | 346 | var reg_value: u32 = 0; |
| 362 | 347 | ||
| 363 | const return_code_int: windows.HRESULT = windows.advapi32.RegGetValueW( | 348 | const return_code_int: windows.HRESULT = windows.advapi32.RegGetValueW( |
| 364 | self.key, | 349 | reg.key, |
| 365 | subkey_wtf16le, | 350 | subkey_wtf16le, |
| 366 | value_name_wtf16le, | 351 | value_name_wtf16le, |
| 367 | RRF.RT_REG_DWORD, | 352 | RRF.RT_REG_DWORD, |
| ... | @@ -405,28 +390,118 @@ const RegistryWtf16Le = struct { | ... | @@ -405,28 +390,118 @@ const RegistryWtf16Le = struct { |
| 405 | else => return error.KeyNotFound, | 390 | else => return error.KeyNotFound, |
| 406 | } | 391 | } |
| 407 | 392 | ||
| 408 | return RegistryWtf16Le{ .key = key }; | 393 | return .{ .key = key }; |
| 409 | } | 394 | } |
| 410 | }; | 395 | }; |
| 411 | 396 | ||
| 412 | pub const Windows10Sdk = struct { | 397 | pub const Installation = struct { |
| 413 | path: []const u8, | 398 | path: []const u8, |
| 414 | version: []const u8, | 399 | version: []const u8, |
| 415 | 400 | ||
| 416 | /// Find path and version of Windows 10 SDK. | 401 | /// Find path and version of Windows SDK. |
| 417 | /// Caller owns the result's fields. | 402 | /// Caller owns the result's fields. |
| 418 | /// After finishing work, call `free(allocator)`. | 403 | /// After finishing work, call `free(allocator)`. |
| 419 | fn find(allocator: std.mem.Allocator) error{ OutOfMemory, Windows10SdkNotFound, PathTooLong, VersionTooLong }!Windows10Sdk { | 404 | fn find( |
| 420 | const v10_key = RegistryWtf8.openKey(windows.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\v10.0") catch |err| switch (err) { | 405 | allocator: std.mem.Allocator, |
| 421 | error.KeyNotFound => return error.Windows10SdkNotFound, | 406 | roots_key: RegistryWtf8, |
| 407 | roots_subkey: []const u8, | ||
| 408 | prefix: []const u8, | ||
| 409 | version_key_name: []const u8, | ||
| 410 | ) error{ OutOfMemory, InstallationNotFound, PathTooLong, VersionTooLong }!Installation { | ||
| 411 | roots: { | ||
| 412 | const installation = findFromRoot(allocator, roots_key, roots_subkey, prefix) catch | ||
| 413 | break :roots; | ||
| 414 | if (installation.isValidVersion()) return installation; | ||
| 415 | installation.free(allocator); | ||
| 416 | } | ||
| 417 | { | ||
| 418 | const installation = try findFromInstallationFolder(allocator, version_key_name); | ||
| 419 | if (installation.isValidVersion()) return installation; | ||
| 420 | installation.free(allocator); | ||
| 421 | } | ||
| 422 | return error.InstallationNotFound; | ||
| 423 | } | ||
| 424 | |||
| 425 | fn findFromRoot( | ||
| 426 | allocator: std.mem.Allocator, | ||
| 427 | roots_key: RegistryWtf8, | ||
| 428 | roots_subkey: []const u8, | ||
| 429 | prefix: []const u8, | ||
| 430 | ) error{ OutOfMemory, InstallationNotFound, PathTooLong, VersionTooLong }!Installation { | ||
| 431 | const path = path: { | ||
| 432 | const path_maybe_with_trailing_slash = roots_key.getString(allocator, "", roots_subkey) catch |err| switch (err) { | ||
| 433 | error.NotAString => return error.InstallationNotFound, | ||
| 434 | error.ValueNameNotFound => return error.InstallationNotFound, | ||
| 435 | error.StringNotFound => return error.InstallationNotFound, | ||
| 436 | |||
| 437 | error.OutOfMemory => return error.OutOfMemory, | ||
| 438 | }; | ||
| 439 | if (path_maybe_with_trailing_slash.len > std.fs.MAX_PATH_BYTES or !std.fs.path.isAbsolute(path_maybe_with_trailing_slash)) { | ||
| 440 | allocator.free(path_maybe_with_trailing_slash); | ||
| 441 | return error.PathTooLong; | ||
| 442 | } | ||
| 443 | |||
| 444 | var path = std.ArrayList(u8).fromOwnedSlice(allocator, path_maybe_with_trailing_slash); | ||
| 445 | errdefer path.deinit(); | ||
| 446 | |||
| 447 | // String might contain trailing slash, so trim it here | ||
| 448 | if (path.items.len > "C:\\".len and path.getLast() == '\\') _ = path.pop(); | ||
| 449 | break :path try path.toOwnedSlice(); | ||
| 450 | }; | ||
| 451 | errdefer allocator.free(path); | ||
| 452 | |||
| 453 | const version = version: { | ||
| 454 | var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; | ||
| 455 | const sdk_lib_dir_path = std.fmt.bufPrint(buf[0..], "{s}\\Lib\\", .{path}) catch |err| switch (err) { | ||
| 456 | error.NoSpaceLeft => return error.PathTooLong, | ||
| 457 | }; | ||
| 458 | if (!std.fs.path.isAbsolute(sdk_lib_dir_path)) return error.InstallationNotFound; | ||
| 459 | |||
| 460 | // enumerate files in sdk path looking for latest version | ||
| 461 | var sdk_lib_dir = std.fs.openDirAbsolute(sdk_lib_dir_path, .{ | ||
| 462 | .iterate = true, | ||
| 463 | }) catch |err| switch (err) { | ||
| 464 | error.NameTooLong => return error.PathTooLong, | ||
| 465 | else => return error.InstallationNotFound, | ||
| 466 | }; | ||
| 467 | defer sdk_lib_dir.close(); | ||
| 468 | |||
| 469 | var iterator = sdk_lib_dir.iterate(); | ||
| 470 | const versions = try iterateAndFilterByVersion(&iterator, allocator, prefix); | ||
| 471 | defer { | ||
| 472 | for (versions[1..]) |version| allocator.free(version); | ||
| 473 | allocator.free(versions); | ||
| 474 | } | ||
| 475 | break :version versions[0]; | ||
| 422 | }; | 476 | }; |
| 423 | defer v10_key.closeKey(); | 477 | errdefer allocator.free(version); |
| 424 | 478 | ||
| 425 | const path: []const u8 = path10: { | 479 | return .{ .path = path, .version = version }; |
| 426 | const path_maybe_with_trailing_slash = v10_key.getString(allocator, "", "InstallationFolder") catch |err| switch (err) { | 480 | } |
| 427 | error.NotAString => return error.Windows10SdkNotFound, | 481 | |
| 428 | error.ValueNameNotFound => return error.Windows10SdkNotFound, | 482 | fn findFromInstallationFolder( |
| 429 | error.StringNotFound => return error.Windows10SdkNotFound, | 483 | allocator: std.mem.Allocator, |
| 484 | version_key_name: []const u8, | ||
| 485 | ) error{ OutOfMemory, InstallationNotFound, PathTooLong, VersionTooLong }!Installation { | ||
| 486 | var key_name_buf: [RegistryWtf16Le.key_name_max_len]u8 = undefined; | ||
| 487 | const key = key: for ([_][]const u8{ "\\Wow6432Node", "" }) |wow6432node| { | ||
| 488 | for ([_]windows.HKEY{ windows.HKEY_LOCAL_MACHINE, windows.HKEY_CURRENT_USER }) |hkey| { | ||
| 489 | break :key RegistryWtf8.openKey(hkey, std.fmt.bufPrint( | ||
| 490 | &key_name_buf, | ||
| 491 | "SOFTWARE{s}\\Microsoft\\Microsoft SDKs\\Windows\\{s}", | ||
| 492 | .{ wow6432node, version_key_name }, | ||
| 493 | ) catch unreachable) catch |err| switch (err) { | ||
| 494 | error.KeyNotFound => return error.InstallationNotFound, | ||
| 495 | }; | ||
| 496 | } | ||
| 497 | } else return error.InstallationNotFound; | ||
| 498 | defer key.closeKey(); | ||
| 499 | |||
| 500 | const path: []const u8 = path: { | ||
| 501 | const path_maybe_with_trailing_slash = key.getString(allocator, "", "InstallationFolder") catch |err| switch (err) { | ||
| 502 | error.NotAString => return error.InstallationNotFound, | ||
| 503 | error.ValueNameNotFound => return error.InstallationNotFound, | ||
| 504 | error.StringNotFound => return error.InstallationNotFound, | ||
| 430 | 505 | ||
| 431 | error.OutOfMemory => return error.OutOfMemory, | 506 | error.OutOfMemory => return error.OutOfMemory, |
| 432 | }; | 507 | }; |
| ... | @@ -443,17 +518,17 @@ pub const Windows10Sdk = struct { | ... | @@ -443,17 +518,17 @@ pub const Windows10Sdk = struct { |
| 443 | if (path.items.len > "C:\\".len and path.getLast() == '\\') _ = path.pop(); | 518 | if (path.items.len > "C:\\".len and path.getLast() == '\\') _ = path.pop(); |
| 444 | 519 | ||
| 445 | const path_without_trailing_slash = try path.toOwnedSlice(); | 520 | const path_without_trailing_slash = try path.toOwnedSlice(); |
| 446 | break :path10 path_without_trailing_slash; | 521 | break :path path_without_trailing_slash; |
| 447 | }; | 522 | }; |
| 448 | errdefer allocator.free(path); | 523 | errdefer allocator.free(path); |
| 449 | 524 | ||
| 450 | const version: []const u8 = version10: { | 525 | const version: []const u8 = version: { |
| 451 | 526 | ||
| 452 | // note(dimenus): Microsoft doesn't include the .0 in the ProductVersion key.... | 527 | // note(dimenus): Microsoft doesn't include the .0 in the ProductVersion key.... |
| 453 | const version_without_0 = v10_key.getString(allocator, "", "ProductVersion") catch |err| switch (err) { | 528 | const version_without_0 = key.getString(allocator, "", "ProductVersion") catch |err| switch (err) { |
| 454 | error.NotAString => return error.Windows10SdkNotFound, | 529 | error.NotAString => return error.InstallationNotFound, |
| 455 | error.ValueNameNotFound => return error.Windows10SdkNotFound, | 530 | error.ValueNameNotFound => return error.InstallationNotFound, |
| 456 | error.StringNotFound => return error.Windows10SdkNotFound, | 531 | error.StringNotFound => return error.InstallationNotFound, |
| 457 | 532 | ||
| 458 | error.OutOfMemory => return error.OutOfMemory, | 533 | error.OutOfMemory => return error.OutOfMemory, |
| 459 | }; | 534 | }; |
| ... | @@ -468,21 +543,27 @@ pub const Windows10Sdk = struct { | ... | @@ -468,21 +543,27 @@ pub const Windows10Sdk = struct { |
| 468 | try version.appendSlice(".0"); | 543 | try version.appendSlice(".0"); |
| 469 | 544 | ||
| 470 | const version_with_0 = try version.toOwnedSlice(); | 545 | const version_with_0 = try version.toOwnedSlice(); |
| 471 | break :version10 version_with_0; | 546 | break :version version_with_0; |
| 472 | }; | 547 | }; |
| 473 | errdefer allocator.free(version); | 548 | errdefer allocator.free(version); |
| 474 | 549 | ||
| 475 | return Windows10Sdk{ .path = path, .version = version }; | 550 | return .{ .path = path, .version = version }; |
| 476 | } | 551 | } |
| 477 | 552 | ||
| 478 | /// Check whether this version is enumerated in registry. | 553 | /// Check whether this version is enumerated in registry. |
| 479 | fn isValidVersion(windows10sdk: *const Windows10Sdk) bool { | 554 | fn isValidVersion(installation: Installation) bool { |
| 480 | var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; | 555 | var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; |
| 481 | const reg_query_as_wtf8 = std.fmt.bufPrint(buf[0..], "{s}\\{s}\\Installed Options", .{ WINDOWS_KIT_REG_KEY, windows10sdk.version }) catch |err| switch (err) { | 556 | const reg_query_as_wtf8 = std.fmt.bufPrint(buf[0..], "{s}\\{s}\\Installed Options", .{ |
| 557 | windows_kits_reg_key, | ||
| 558 | installation.version, | ||
| 559 | }) catch |err| switch (err) { | ||
| 482 | error.NoSpaceLeft => return false, | 560 | error.NoSpaceLeft => return false, |
| 483 | }; | 561 | }; |
| 484 | 562 | ||
| 485 | const options_key = RegistryWtf8.openKey(windows.HKEY_LOCAL_MACHINE, reg_query_as_wtf8) catch |err| switch (err) { | 563 | const options_key = RegistryWtf8.openKey( |
| 564 | windows.HKEY_LOCAL_MACHINE, | ||
| 565 | reg_query_as_wtf8, | ||
| 566 | ) catch |err| switch (err) { | ||
| 486 | error.KeyNotFound => return false, | 567 | error.KeyNotFound => return false, |
| 487 | }; | 568 | }; |
| 488 | defer options_key.closeKey(); | 569 | defer options_key.closeKey(); |
| ... | @@ -492,87 +573,16 @@ pub const Windows10Sdk = struct { | ... | @@ -492,87 +573,16 @@ pub const Windows10Sdk = struct { |
| 492 | .aarch64 => "OptionId.DesktopCPParm64", | 573 | .aarch64 => "OptionId.DesktopCPParm64", |
| 493 | .x86_64 => "OptionId.DesktopCPPx64", | 574 | .x86_64 => "OptionId.DesktopCPPx64", |
| 494 | .x86 => "OptionId.DesktopCPPx86", | 575 | .x86 => "OptionId.DesktopCPPx86", |
| 495 | else => |tag| @compileError("Windows 10 SDK cannot be detected on architecture " ++ tag), | 576 | else => |tag| @compileError("Windows SDK cannot be detected on architecture " ++ tag), |
| 496 | }; | 577 | }; |
| 497 | 578 | ||
| 498 | const reg_value = options_key.getDword("", option_name) catch return false; | 579 | const reg_value = options_key.getDword("", option_name) catch return false; |
| 499 | return (reg_value == 1); | 580 | return (reg_value == 1); |
| 500 | } | 581 | } |
| 501 | 582 | ||
| 502 | fn free(self: *const Windows10Sdk, allocator: std.mem.Allocator) void { | 583 | fn free(install: Installation, allocator: std.mem.Allocator) void { |
| 503 | allocator.free(self.path); | 584 | allocator.free(install.path); |
| 504 | allocator.free(self.version); | 585 | allocator.free(install.version); |
| 505 | } | ||
| 506 | }; | ||
| 507 | |||
| 508 | pub const Windows81Sdk = struct { | ||
| 509 | path: []const u8, | ||
| 510 | version: []const u8, | ||
| 511 | |||
| 512 | /// Find path and version of Windows 8.1 SDK. | ||
| 513 | /// Caller owns the result's fields. | ||
| 514 | /// After finishing work, call `free(allocator)`. | ||
| 515 | fn find(allocator: std.mem.Allocator, roots_key: *const RegistryWtf8) error{ OutOfMemory, Windows81SdkNotFound, PathTooLong, VersionTooLong }!Windows81Sdk { | ||
| 516 | const path: []const u8 = path81: { | ||
| 517 | const path_maybe_with_trailing_slash = roots_key.getString(allocator, "", "KitsRoot81") catch |err| switch (err) { | ||
| 518 | error.NotAString => return error.Windows81SdkNotFound, | ||
| 519 | error.ValueNameNotFound => return error.Windows81SdkNotFound, | ||
| 520 | error.StringNotFound => return error.Windows81SdkNotFound, | ||
| 521 | |||
| 522 | error.OutOfMemory => return error.OutOfMemory, | ||
| 523 | }; | ||
| 524 | if (path_maybe_with_trailing_slash.len > std.fs.MAX_PATH_BYTES or !std.fs.path.isAbsolute(path_maybe_with_trailing_slash)) { | ||
| 525 | allocator.free(path_maybe_with_trailing_slash); | ||
| 526 | return error.PathTooLong; | ||
| 527 | } | ||
| 528 | |||
| 529 | var path = std.ArrayList(u8).fromOwnedSlice(allocator, path_maybe_with_trailing_slash); | ||
| 530 | errdefer path.deinit(); | ||
| 531 | |||
| 532 | // String might contain trailing slash, so trim it here | ||
| 533 | if (path.items.len > "C:\\".len and path.getLast() == '\\') _ = path.pop(); | ||
| 534 | |||
| 535 | const path_without_trailing_slash = try path.toOwnedSlice(); | ||
| 536 | break :path81 path_without_trailing_slash; | ||
| 537 | }; | ||
| 538 | errdefer allocator.free(path); | ||
| 539 | |||
| 540 | const version: []const u8 = version81: { | ||
| 541 | var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; | ||
| 542 | const sdk_lib_dir_path = std.fmt.bufPrint(buf[0..], "{s}\\Lib\\", .{path}) catch |err| switch (err) { | ||
| 543 | error.NoSpaceLeft => return error.PathTooLong, | ||
| 544 | }; | ||
| 545 | if (!std.fs.path.isAbsolute(sdk_lib_dir_path)) return error.Windows81SdkNotFound; | ||
| 546 | |||
| 547 | // enumerate files in sdk path looking for latest version | ||
| 548 | var sdk_lib_dir = std.fs.openDirAbsolute(sdk_lib_dir_path, .{ | ||
| 549 | .iterate = true, | ||
| 550 | }) catch |err| switch (err) { | ||
| 551 | error.NameTooLong => return error.PathTooLong, | ||
| 552 | else => return error.Windows81SdkNotFound, | ||
| 553 | }; | ||
| 554 | defer sdk_lib_dir.close(); | ||
| 555 | |||
| 556 | var iterator = sdk_lib_dir.iterate(); | ||
| 557 | const versions = iterateAndFilterBySemVer(&iterator, allocator, "winv") catch |err| switch (err) { | ||
| 558 | error.OutOfMemory => return error.OutOfMemory, | ||
| 559 | error.VersionNotFound => return error.Windows81SdkNotFound, | ||
| 560 | }; | ||
| 561 | defer { | ||
| 562 | for (versions) |version| allocator.free(version); | ||
| 563 | allocator.free(versions); | ||
| 564 | } | ||
| 565 | const latest_version = try allocator.dupe(u8, versions[0]); | ||
| 566 | break :version81 latest_version; | ||
| 567 | }; | ||
| 568 | errdefer allocator.free(version); | ||
| 569 | |||
| 570 | return Windows81Sdk{ .path = path, .version = version }; | ||
| 571 | } | ||
| 572 | |||
| 573 | fn free(self: *const Windows81Sdk, allocator: std.mem.Allocator) void { | ||
| 574 | allocator.free(self.path); | ||
| 575 | allocator.free(self.version); | ||
| 576 | } | 586 | } |
| 577 | }; | 587 | }; |
| 578 | 588 | ||
| ... | @@ -634,7 +644,7 @@ const MsvcLibDir = struct { | ... | @@ -634,7 +644,7 @@ const MsvcLibDir = struct { |
| 634 | /// Example: 17.4.33205.214 -> 0x0011000481b500d6 | 644 | /// Example: 17.4.33205.214 -> 0x0011000481b500d6 |
| 635 | fn parseVersionQuad(version: []const u8) error{InvalidVersion}!u64 { | 645 | fn parseVersionQuad(version: []const u8) error{InvalidVersion}!u64 { |
| 636 | var it = std.mem.splitScalar(u8, version, '.'); | 646 | var it = std.mem.splitScalar(u8, version, '.'); |
| 637 | const a = it.next() orelse return error.InvalidVersion; | 647 | const a = it.first(); |
| 638 | const b = it.next() orelse return error.InvalidVersion; | 648 | const b = it.next() orelse return error.InvalidVersion; |
| 639 | const c = it.next() orelse return error.InvalidVersion; | 649 | const c = it.next() orelse return error.InvalidVersion; |
| 640 | const d = it.next() orelse return error.InvalidVersion; | 650 | const d = it.next() orelse return error.InvalidVersion; |
| ... | @@ -791,11 +801,7 @@ const MsvcLibDir = struct { | ... | @@ -791,11 +801,7 @@ const MsvcLibDir = struct { |
| 791 | defer visualstudio_folder.close(); | 801 | defer visualstudio_folder.close(); |
| 792 | 802 | ||
| 793 | var iterator = visualstudio_folder.iterate(); | 803 | var iterator = visualstudio_folder.iterate(); |
| 794 | const versions = iterateAndFilterBySemVer(&iterator, allocator, null) catch |err| switch (err) { | 804 | break :vs_versions try iterateAndFilterByVersion(&iterator, allocator, ""); |
| 795 | error.OutOfMemory => return error.OutOfMemory, | ||
| 796 | error.VersionNotFound => return error.PathNotFound, | ||
| 797 | }; | ||
| 798 | break :vs_versions versions; | ||
| 799 | }; | 805 | }; |
| 800 | defer { | 806 | defer { |
| 801 | for (vs_versions) |vs_version| allocator.free(vs_version); | 807 | for (vs_versions) |vs_version| allocator.free(vs_version); |