Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Makefile work on MSYS2 #15102

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

HertzDevil
Copy link
Contributor

@HertzDevil HertzDevil commented Oct 20, 2024

Resolves part of #6170.

  • Uses llvm-config instead of llvm_VERSION for the x86_64-windows-gnu target. Also invokes the find-llvm-config script using sh explicitly and ensures the script returns a Windows path. (This pretty much means a MinGW-w64-based compiler will require the entire MSYS2 environment to work.)
  • Increases the stack size from the default 2 MiB to 8 MiB, consistent with builds using the MSVC toolchain.
  • Makefile and the bin/crystal script now recognize .build/crystal.exe as the local compiler under MSYS2.
  • If .build/crystal.exe already exists and we are on Windows, Makefile now builds a temporary executable first, just like in Makefile.win.
  • Ensures Makefile doesn't interpret backslashes in llvm-config.exe's path as escape sequences.
  • Adds a separate install_dlls target for installing the compiler's dependent DLLs to the given prefix's bin directory. This is only needed if the installation is to be distributed outside MSYS2.
  • Detects the presence of lld which can be installed using the mingw-w64-ucrt-x86_64-lld package.

With this patch, cross-compiling from MSVC-based Crystal will no longer work until #15091 is merged. Instead it can be done from Linux, including WSL, assuming the host and target LLVM versions are identical (right now MSYS2 has 18.1.8):

# on Linux
make clean crystal && make -B target=x86_64-windows-gnu

# on MSYS2's UCRT64 environment
pacman -Sy \
  mingw-w64-ucrt-x86_64-gcc mingw-w64-ucrt-x86_64-pkgconf \
  mingw-w64-ucrt-x86_64-gc mingw-w64-ucrt-x86_64-pcre2 mingw-w64-ucrt-x86_64-libiconv \
  mingw-w64-ucrt-x86_64-zlib mingw-w64-ucrt-x86_64-llvm
cc .build/crystal.obj -o .build/crystal.exe \
  $(pkg-config bdw-gc libpcre2-8 iconv zlib --libs) \
  $(llvm-config --libs --system-libs --ldflags) \
  -lDbgHelp -lole32 -lWS2_32 -Wl,--stack,0x800000

@HertzDevil HertzDevil added kind:feature topic:infrastructure platform:windows Windows support based on the MSVC toolchain labels Oct 20, 2024
@straight-shoota straight-shoota added this to the 1.15.0 milestone Oct 20, 2024
@HertzDevil HertzDevil added platform:windows-gnu Windows support based on the MinGW-w64 toolchain + MSYS2 and removed platform:windows Windows support based on the MSVC toolchain labels Oct 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:feature platform:windows-gnu Windows support based on the MinGW-w64 toolchain + MSYS2 topic:infrastructure
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants