Skip to content

Instantly share code, notes, and snippets.

@Mic92
Last active October 28, 2020 17:52
Show Gist options
  • Save Mic92/30996bf5d49d783c4743c3ea9e0c0a6f to your computer and use it in GitHub Desktop.
Save Mic92/30996bf5d49d783c4743c3ea9e0c0a6f to your computer and use it in GitHub Desktop.
Development environment to hack on llvm/clang
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