Last active
October 28, 2020 17:52
-
-
Save Mic92/30996bf5d49d783c4743c3ea9e0c0a6f to your computer and use it in GitHub Desktop.
Development environment to hack on llvm/clang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with import <nixpkgs> {}; | |
let | |
gccForLibs = stdenv.cc.cc; | |
libc_lib = getLib stdenv.cc.libc; | |
in stdenv.mkDerivation { | |
name = "env"; | |
buildInputs = [ | |
bashInteractive | |
ninja | |
cmake | |
llvmPackages_latest.llvm | |
]; | |
# where to find libgcc | |
NIX_LDFLAGS="-L${gccForLibs}/lib/gcc/${targetPlatform.config}/${gccForLibs.version}"; | |
# teach clang about C startup file locations | |
CFLAGS="-B${gccForLibs}/lib/gcc/${targetPlatform.config}/${gccForLibs.version} -B ${stdenv.cc.libc}/lib"; | |
cmakeFlags = [ | |
"-DGCC_INSTALL_PREFIX=${gcc}" | |
"-DC_INCLUDE_DIRS=${stdenv.cc.libc.dev}/include" | |
"-GNinja" | |
"-DCMAKE_BUILD_TYPE=Release" | |
"-DCMAKE_INSTALL_PREFIX=../inst" | |
"-DLLVM_INSTALL_TOOLCHAIN_ONLY=ON" | |
"-DLLVM_ENABLE_PROJECTS=clang;libcxx;libcxxabi" | |
"-DLLVM_TARGETS_TO_BUILD=host" | |
]; | |
## How to use with clang | |
# $ git clone https://github.com/llvm/llvm-project/ | |
# $ mkdir build && cd build | |
# $ cmake $cmakeFlags ../llvm-project/llvm | |
# $ ninja && ninja install | |
# $ cd .. | |
## assuming main.c is a test program. | |
# ./inst/bin/clang $CFLAGS -o main main.c | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment