How to detect the current MSYS2 environment (ucrt64, mingw64, clang64) on Windows?

Hello,
I am using Crystal on Windows with MSYS2.
MSYS2 has different environments (ucrt64, clang64, mingw64).
Is there a simple way to check which one I am using?
This is important when I use Crystal with other libraries not included in MSYS2.

According to ChatGPT, you can tell by looking at the environment variable MSYSTEM.

{% if env("MSYSTEM") == "MINGW64" %}
  puts "Using mingw64 environment"
{% elsif env("MSYSTEM") == "UCRT64" %}
  puts "Using ucrt64 environment"
{% elsif env("MSYSTEM") == "CLANG64" %}
  puts "Using clang64 environment"
{% else %}
  puts "Unknown or unsupported MSYS2 environment"
{% end %}

The relevant MSYSTEM_ and MINGW_ variables are defined here.

If you want to set up custom third-library dependencies, here is a worked example using raylib-cr.

1 Like

Thanks. Programming is hard and Windows is hard.