mstorsjo / llvm-mingw

An LLVM/Clang/LLD based mingw-w64 toolchain
Other
1.84k stars 179 forks source link

Making a wish for i686 MacOS wincrt builds? #445

Closed vonj closed 1 month ago

vonj commented 1 month ago

Could one make a wish for builds targetting wincrt (not ucrt) 32 bit Win32 from MacOS host?

longnguyen2004 commented 1 month ago

You can fork this repo, edit the GitHub Actions and build it yourself perhaps?

mstorsjo commented 1 month ago

You can fork this repo, edit the GitHub Actions and build it yourself perhaps?

Yes, this is quite easy if you want to go this way, a change like this should achieve that:

diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index d785c7a..dfaaafe 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -206,17 +206,17 @@ jobs:
           # form. Therefore, autodetection will pick them up, but linking
           # universal binaries fails as those libraries are unavailable in the
           # other (arm64) architecture form.
-          MACOS_REDIST=1 LLVM_CMAKEFLAGS="-DLLVM_ENABLE_ZSTD=OFF -DLLDB_ENABLE_PYTHON=OFF" ./build-all.sh $(pwd)/install/llvm-mingw
+          MACOS_REDIST=1 LLVM_CMAKEFLAGS="-DLLVM_ENABLE_ZSTD=OFF -DLLDB_ENABLE_PYTHON=OFF" ./build-all.sh $(pwd)/install/llvm-mingw --with-default-msvcrt=msvcrt
           .github/workflows/store-version.sh install/llvm-mingw/versions.txt
           ./test-libcxx-module.sh $(pwd)/install/llvm-mingw
           RUN_I686=false RUN_X86_64=false ./run-tests.sh $(pwd)/install/llvm-mingw
           cd install
-          NAME=llvm-mingw-$TAG-ucrt-macos-universal
+          NAME=llvm-mingw-$TAG-msvcrt-macos-universal
           mv llvm-mingw $NAME
           gtar -Jcf ../$NAME.tar.xz --format=ustar --numeric-owner --owner=0 --group=0 --sort=name --mtime="$BUILD_DATE" $NAME
       - uses: actions/upload-artifact@v4
         with:
-          name: macos-ucrt-toolchain
+          name: macos-msvcrt-toolchain
           path: |
             llvm-mingw-*.tar.xz
           retention-days: 7

However it should also be possible to just assemble the same from the existing files. If you download the msvcrt-ubuntu-... package, and the ucrt-macos package, it's enough to just replace the target mingw libraries and headers in the macos package with the ones from the msvcrt package.

It's possible to do that with the script prepare-cross-toolchain-unix.sh in the repo as well - but you may want to do this small tweak to it:

diff --git a/prepare-cross-toolchain-unix.sh b/prepare-cross-toolchain-unix.sh
index 75846a0..ce00361 100755
--- a/prepare-cross-toolchain-unix.sh
+++ b/prepare-cross-toolchain-unix.sh
@@ -46,6 +46,7 @@ cp -a $CLANG_RESOURCE_DIR $DEST/lib/clang/$CLANG_VERSION

 # Copy all arch-specific subdirectories plus the "generic" one, as is.
 for arch in generic $ARCHS; do
+    rm -rf $DEST/$arch-w64-mingw32
     cp -a $SRC/$arch-w64-mingw32 $DEST/$arch-w64-mingw32
 done

(I'll probably do that modification in the script soon anyway.)

With that modification, if you unpack those two packages, you can do this:

$ ./prepare-cross-toolchain-unix.sh /path/to/unpacked/msvcrt-ubuntu-toolchain /path/to/unpacked/ucrt-macos-toolchain

That should replace the runtime target files in the macos toolchain package with the ones from the msvcrt targeting toolchain.

vonj commented 1 month ago

Thank you so much, you make it look easy!

vonj commented 1 month ago

It worked. (But I later had other issues related to my code depending on GCC specific behaviour.)