LLVM compiler for Granule. This is a prototype which compiles on the functional core of Granule and does not yet support custom ADTs and GADTs.
Installation requires Stack and LLVM 12.
Build and install using Stack. The following will install the grc
binary:
stack install :grc
LLVM 12 is available on some macOS versions via Homebrew and some Linux distributions via their default apt repositories or the LLVM apt repository.
# mac
brew install llvm@12
# linux
sudo apt install llvm-12
If you are not able to install through a package manager, or if you encounter any unexpected issues during building this project (especially llvm-config
errors on macOS), which you are not able to resolve, you might need to build LLVM from source.
These are the steps I took to build LLVM 12 on an M1 MacBook running Sequoia 15.1. The process is very similar on Linux, minus the macOS specifics.
- Install build dependencies:
brew install cmake ninja
- Get the source, create a build directory:
git clone https://github.com/llvm/llvm-project -b release/12.x --single-branch --depth 1
cd llvm-project/llvm
mkdir build && cd build
- Build. Choose a sensible installation path. The dylib flags are necessary, the rest are for build speed:
# setup
cmake -Wno-dev -G "Ninja" .. \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr/local/llvm-12 \
-DLLVM_TARGETS_TO_BUILD="AArch64" \
-DLLVM_INCLUDE_TOOLS=ON \
-DLLVM_INCLUDE_EXAMPLES=OFF \
-DLLVM_INCLUDE_TESTS=OFF \
-DLLVM_INCLUDE_BENCHMARKS=OFF \
-DLLVM_ENABLE_BINDINGS=OFF \
-DLLVM_BUILD_LLVM_DYLIB=ON \
-DLLVM_LINK_LLVM_DYLIB=ON
# build (take a break!)
ninja
# install
sudo ninja install
- Clean up and permissions. The
-12
suffix is sometimes expected on the dylib. Theinstall_name_tool
usage is for SIP:
cd /usr/local/llvm-12/lib
sudo ln -s libLLVM.dylib libLLVM-12.dylib
sudo install_name_tool -id $PWD/libLTO.dylib libLTO.dylib
sudo install_name_tool -id $PWD/libLLVM.dylib libLLVM.dylib
sudo install_name_tool -change '@rpath/libLLVM.dylib' $PWD/libLLVM.dylib libLTO.dylib
- Add the following to your .zshrc or equivalent:
export PATH="/usr/local/llvm-12/bin:$PATH"
export LD_LIBRARY_PATH="/usr/local/llvm-12/lib:$LD_LIBRARY_PATH"