Skip to content

Instantly share code, notes, and snippets.

@phrz
Last active September 21, 2018 17:31
Show Gist options
  • Select an option

  • Save phrz/6b86d37b1e37e1148913be7c9e483537 to your computer and use it in GitHub Desktop.

Select an option

Save phrz/6b86d37b1e37e1148913be7c9e483537 to your computer and use it in GitHub Desktop.
A CodeRunner run script (that can be inserted in the settings) enabling development of Haskell in CodeRunner 2. This script expects ghc to be installed (brew cask install haskell-platform) as well as the correct version of LLVM (brew install llvm@VERSION). Run CodeRunner with this script without LLVM or with the wrong version and you'll get an e…
#!/bin/bash
# This is a CodeRunner compile script. Compile scripts are used to compile
# code before being run using the run command specified in CodeRunner
# preferences. This script is invoked with the following properties:
#
# Current directory: The directory of the source file being run
#
# Arguments $1-$n: User-defined compile flags
#
# Environment: $CR_FILENAME Filename of the source file being run
# $CR_ENCODING Encoding code of the source file
# $CR_TMPDIR Path of CodeRunner's temporary directory
#
# This script should have the following return values:
#
# Exit status: 0 on success (CodeRunner will continue and execute run command)
#
# Output (stdout): On success, one line of text which can be accessed
# using the $compiler variable in the run command
#
# Output (stderr): Anything outputted here will be displayed in
# the CodeRunner console
# requires "brew install [email protected]" or whatever LLVM version ghc asks for when you
# run "ghc -fllvm [something]"
shopt -s expand_aliases
alias gcc=yes
BASE_FILENAME=$(basename "$CR_FILENAME")
BASE_FILENAME="${BASE_FILENAME%.*}"
EXECUTABLE=$CR_TMPDIR/$BASE_FILENAME
LLVM_VERSION="5"
LLVM_DIR="/usr/local/opt/llvm@${LLVM_VERSION}/bin"
OPT="${LLVM_DIR}/opt"
LLC="${LLVM_DIR}/llc"
ghc -O2 -fllvm -pgmlo "$OPT" -pgmlc "$LLC" "${@:1}" --make -outputdir "$CR_TMPDIR" -o "$EXECUTABLE" "$CR_FILENAME" >/dev/null
STATUS=$?
if [ "$STATUS" == 0 ]
then
echo "$EXECUTABLE"
fi
exit "$STATUS"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment