In case you don't have Stack installed in your system, you should visit Stack's website and follow the appropriate installation method for your OS. If you are on Linux or macOS, you will be provided with a shell command, while if you are on Windows a regular installer is available.
git clone https://github.com/fjvallarino/monomer-starter.git <your-app-name>In case you don't have Homebrew installed, visit Homebrew
brew install sdl2
brew install glewThe standard build process currently fails on M1 Macs. This issue should be
fixed when support for GHC 9.2 is added to stack, since that version of GHC
includes a native code generator for M1 processors.
It has been reported that:
- Building for x86 and running the application in the Rosetta shell works well.
- Applying some workarounds, mentioned in the same issue, the build can work on M1.
sudo apt-get install libsdl2-dev
sudo apt-get install libglew-devIt seems there are issues when installing libsdl2-dev on some Ubuntu versions.
These issues can usually be solved by running sudo aptitude install libsdl2-dev
and choosing one of the suggested actions, although doing this is a bit more
dangerous than a regular package install.
Aptitude can be installed with sudo apt-get install aptitude.
pacman -S sdl2
pacman -S glewsudo dnf install SDL2-devel glew-develInside your project's directory:
stack setup
stack exec -- pacman -S mingw-w64-x86_64-pkg-config
stack exec -- pacman -S mingw-w64-x86_64-SDL2
stack exec -- pacman -S mingw-w64-x86_64-freeglut
stack exec -- pacman -S mingw-w64-x86_64-glewIf these steps fail with a message similar to "invalid or corrupted database"
or "signature from ... is unknown trust", you may have an old MinGW installed
by a previous version of Stack. At some point the MinGW project changed their
certificates and, even if it should be possible to upgrade them manually, it is
not an easy process (and I have not had luck with it).
Stack installs its files in two locations:
%STACK_ROOT%(usuallyC:\sr, unless modified)%LOCALAPPDATA%\Programs\stack
The second location is the directory that contains MinGW. Removing
%LOCALAPPDATA%\Programs\stack and running the above steps again is usually
enough to get a working environment. If this does not work, removing
%STACK_ROOT% and reinstalling Stack may be required.
If the previous steps did not fix the issue, updating the keyring with the following commands and building again may help:
stack exec -- pacman -S msys2-keyring
stack exec -- pacman -SyuInside your project's directory:
stack buildOne case has been reported where an "Unable to make GL context current" error ocurred on application startup. This seems to be a driver issue, and it's not something that can be fixed from the library.
As a workaround, an application configuration option called
appRenderOnMainThread is available. It can be added to the config list of
the starter application or to the corresponding section of any of the examples.
In case you want to test the examples the library provides, you need to clone the library itself with:
git clone https://github.com/fjvallarino/monomer.gitThen, inside the cloned directory, build the project with:
stack buildIn case you have not followed the instructions for the starter project, you still need to install the dependencies.
Inside the cloned directory, you can run each of the examples with stack run:
stack run todo
stack run books
stack run ticker
stack run generativeSince compilation times can be annoying, I personally prefer to rely on ghcid for a nicer development experience. First, you need to install it:
stack install ghcidThen, inside your project's directory:
ghcidIf you use Visual Studio Code, you can also use this very nice extension.
Once installed, pressing Ctrl-Shift-P will allow you to invoke the
Start Ghcid command. You can also run ghcid on the command line directly.
With this you will be running your application in interpreted mode (ghcid
under the hood uses ghci), allowing you to make changes and test them almost
immediately.
Note: when a file is saved, a new instance of the application will be in a new window. The previous window needs to be closed manually.
If you have a discrete GPU, and you'd rather have your application use the
integrated GPU, you may want to copy Info.plist into the bin directory the
build command shows. It will be something like (replacing 8.10.7 with the
corresponding GHC version):
$HOME/.../monomer-starter/.stack-work/install/x86_64-osx/......../8.10.7/binBy doing this, macOS will default to using the integrated GPU instead of the discrete one. This provides slightly faster startup, better battery life and it will work fine for most UIs, although you may notice a bit of lag when resizing windows.
Further, you may want to do this for your local stack install directory, since you'll be using ghcid and Info.plist needs to be in the directory where the executable is located. The path is usually:
$HOME/.local/binYou will also need to add it to the directory where ghc/ghci are installed:
$HOME/.stack/programs/x86_64-osx/ghc-8.10.7/lib/ghc-8.10.7/bin/Reference: http://supermegaultragroovy.com/2016/12/10/auto-graphics-switching
The sample project includes custom .ghci and .ghcid files. The most important
change in .ghci is for Mac users, since macOS does not allow graphics setup to
happen outside the main thread (by default ghci spawns a thread for user
code). If you create your custom GHCi config and run into issues, check if you
are providing the necessary flags.