I'm trying to use cabal on windows (installed using chocolatey), and it is looking for "ar", which is a GNU utility, and I have no idea how to install that.

# In powershell or git bash
git clone https://github.com/haskell/text
cd text
cabal build --with-gcc=msys2

Error message excerpt (and yes I am intentionally using 8.2.2, -w ghc-8.2.2):

Failed to build call-stack-0.4.0.
Build log (
C:\cabal\logs\ghc-8.2.2\call-stack-0.4.0-99b0801375eba6b85bc1a82c10630c85f20debfa.log
):
Preprocessing library for call-stack-0.4.0..
Building library for call-stack-0.4.0..
[1 of 3] Compiling Data.SrcLoc      ( src\Data\SrcLoc.hs, dist\build\Data\SrcLoc.o )
[2 of 3] Compiling Data.CallStack   ( src\Data\CallStack.hs, dist\build\Data\CallStack.o )
[3 of 3] Compiling Paths_call_stack ( dist\build\autogen\Paths_call_stack.hs, dist\build\Paths_call_stack.o )
cabal.exe: The program 'ar' is required but it could not be found.



(and a whole lot more identical errors for other packages)

You might need to install GCC, which, as far as I can tell by looking at the MSYS2 setup on my machine, doesn't seem to come with the initial MSYS2 install. That would be done through pacman, on the MSYS shell (see the MSYS2 wiki for a primer on the MSYS2 shells and subsystems):

# Updates the package database and the currently installed packages.
# If the shell closes at the end of the update, reopen it and rerun.
pacman -Syu
# Installs gcc.
pacman -S mingw-w64-x86_64-gcc

In particular, ar is installed as part of mingw-w64-x86_64-binutils, which is a dependency of mingw-w64-x86_64-gcc.

Additional notes:

  • GCC will be installed to mingw64\bin under your MSYS2 root. You might want to add that location to your PATH.

  • As you found out, if you are managing the tools through Chocolatey, choco install mingw will set up the basic MinGW development toolchain, which includes GCC.