Skip to content

Instantly share code, notes, and snippets.

@bigos
Last active November 29, 2022 03:34
Show Gist options
  • Save bigos/62defeec09a06f18ee38daf644af5340 to your computer and use it in GitHub Desktop.
Save bigos/62defeec09a06f18ee38daf644af5340 to your computer and use it in GitHub Desktop.
My way of installing Haskell on Windows so that I can build gi-gtk based stack projects

Simplified installation

already I have

choco msys2 emacs

Install GHC

open cmd as administrator

Press Windows button, in ‘Type to search’ type cmd, right-click on Command Promp Desktop app and select Run as administrator.

lines to paste in cmd

Paste each following line separately

SET PATH=%APPDATA%\cabal\bin;C:\msys64\mingw64\bin;C:\msys64\usr\bin;C:\ProgramData\chocolatey\lib\ghc\tools\ghc-8.0.2\bin;C:\ProgramData\chocolatey\lib\cabal\tools;%PATH%
SET PKG_CONFIG_PATH=C:\msys64\mingw64\lib\pkgconfig
SET XDG_DATA_DIRS=C:\msys64\mingw64\share
choco install ghc --version 8.0.2

I will take a while so in the meantimme let’s do something else. Keep the cmd open.

Install MSYS2 packages

In Msys2 terminal

pacman -S -q --noconfirm mingw64/mingw-w64-x86_64-pkg-config mingw64/mingw-w64-x86_64-gobject-introspection mingw64/mingw-w64-x86_64-gtksourceview3 mingw64/mingw-w64-x86_64-webkitgtk3

test ghc

In cmd ghc and cabal version.

ghc --version
cabal --version

optional - create Emacs launcher

In C:\Users\IEUser folder create emacslauncher.cmd with the following content

set PATH=C:\msys64\mingw64\bin;C:\msys64\usr\bin;%PATH%
set XDG_DATA_DIRS=c:/msys64/mingw64/share
set PKG_CONFIG_PATH=c:/msys64/mingw64/lib/pkgconfig
set HASKELL_GI_GIR_SEARCH_PATH=c:/msys64/mingw64/share/gir-1.0

C:\msys64\mingw64\bin\runemacs

Close Emacs if open, run the emaclauncher.cmd thus starting Emacs, open eshell by pressing Alt+x and test ghc and cabal version in Emacs. If you get the same result as in cmd you are good to go.

Subsequent examples should work both in cmd and Emacs eshell.

cabal config

The command cabal user-config init gave me the location of cabal file. So I modified the extra-*-dirs to point to msys libraries.

-- flags:
extra-include-dirs: c:/msys64/mingw64/include
-- deterministic:
-- cid:
extra-lib-dirs: c:/msys64/mingw64/lib
-- extra-framework-dirs:
extra-prog-path: C:\Users\IEUser\AppData\Roaming\cabal\bin
-- instantiate-with:

cabal installation

cabal update
cabal install alex happy
cabal install gi-gtk

stack

donwload

I used 64 bit installer from https://docs.haskellstack.org/en/stable/install_and_upgrade/

optional

Restart Emacs, if you want to use Emacs for shell operations.

test

Test if the installation went well.

stack --version
Version 1.5.1, Git revision 600c1f01435a10d127938709556c1682ecfd694e x86_64 hpack-0.17.1

running in a stack based project

stack --system-ghc install --dependencies-only
stack --system-ghc build

Running stack exec <programName> does not work on eshell, but in cmd you will get a dialog about a missing dlls.

To solve it use cmd and do to the c:\msys64\mingw64\bin directory that contains your dlls and execute

..\..\..\Users\your\project\.stack-work\install\345123444\bin\yourexec.exe

You have to do it because the current folder is not in the system PATH. https://msdn.microsoft.com/en-us/library/windows/desktop/ms682586(v=vs.85).aspx

Possible solution

Create a file cmdlauncher.cmd and put the following code in it. This will start cmd shell with modified PATH so it doesn’t have to interfere with your Windows system. If you do it this way you do not need the long command as in the previous section.

set PATH=C:\msys64\mingw64\bin;C:\msys64\usr\bin;%PATH%

set XDG_DATA_DIRS=c:/msys64/mingw64/share
set PKG_CONFIG_PATH=c:/msys64/mingw64/lib/pkgconfig
set HASKELL_GI_GIR_SEARCH_PATH=c:/msys64/mingw64/share/gir-1.0

cmd

global config

File

C:\sr\config.yaml

contains following additional options(s)

skip-msys: true
system-ghc: true

https://github.com/commercialhaskell/stack/blob/master/doc/yaml_configuration.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment