| 1 | #!/bin/sh |
| 2 | # Fetches llvm-mingw into target/windows/llvm-mingw: clang, lld and the MinGW-w64 sysroots |
| 3 | # for x86_64 and aarch64, built for msvcrt.dll, which Windows 7 has without updates, where |
| 4 | # the UCRT needs KB2999226. llvm-mingw publishes msvcrt builds only for Linux and Windows |
| 5 | # hosts, so on macOS its UCRT toolchain takes the msvcrt build's target files. |
| 6 | set -eu |
| 7 | here=$(cd "$(dirname "$0")" && pwd) |
| 8 | root=$(cd "$here/../.." && pwd) |
| 9 | release=20260922 |
| 10 | out=$root/target/windows/llvm-mingw |
| 11 | stage=$root/target/windows/llvm-mingw.partial |
| 12 | base=https://github.com/mstorsjo/llvm-mingw/releases/download/$release |
| 13 | msvcrt=llvm-mingw-$release-msvcrt-ubuntu-22.04-x86_64 |
| 14 | [ ! -e "$out" ] || { echo "$out exists" >&2; exit 1; } |
| 15 | rm -rf "${stage:?}" |
| 16 | mkdir -p "$stage" |
| 17 | curl -fsSL "$base/$msvcrt.tar.xz" | tar -xJ -C "$stage" |
| 18 | if [ "$(uname -s)" = Darwin ]; then |
| 19 | host=llvm-mingw-$release-ucrt-macos-universal |
| 20 | curl -fsSL "$base/$host.tar.xz" | tar -xJ -C "$stage" |
| 21 | clang=$(ls "$stage/$host/lib/clang") |
| 22 | for part in x86_64-w64-mingw32 aarch64-w64-mingw32 generic-w64-mingw32 \ |
| 23 | "lib/clang/$clang/lib/windows"; do |
| 24 | rm -rf "${stage:?}/$host/$part" |
| 25 | mv "$stage/$msvcrt/$part" "$stage/$host/$part" |
| 26 | done |
| 27 | else |
| 28 | host=$msvcrt |
| 29 | fi |
| 30 | # Only x86_64 and aarch64 are built. |
| 31 | rm -rf "${stage:?}/$host/i686-w64-mingw32" "${stage:?}/$host/armv7-w64-mingw32" |
| 32 | find "$stage/$host/bin" \( -name 'i686-*' -o -name 'armv7-*' -o -name '*uwp*' \) -delete |
| 33 | mv "$stage/$host" "$out" |
| 34 | rm -rf "${stage:?}" |
| 35 | echo "$out" |