LLVM: Difference between revisions
imported>Mic92 add llvm tutorial |
m →Build LLVM/clang from source: prefix shell comment with $ just so syntaxhighlight works properly |
||
| (5 intermediate revisions by 5 users not shown) | |||
| Line 14: | Line 14: | ||
buildInputs = [ | buildInputs = [ | ||
bashInteractive | bashInteractive | ||
python3 | |||
ninja | ninja | ||
cmake | cmake | ||
| Line 34: | Line 35: | ||
"-DLLVM_INSTALL_TOOLCHAIN_ONLY=ON" | "-DLLVM_INSTALL_TOOLCHAIN_ONLY=ON" | ||
# change this to enable the projects you need | # change this to enable the projects you need | ||
"-DLLVM_ENABLE_PROJECTS=clang | "-DLLVM_ENABLE_PROJECTS=clang" | ||
# enable libcxx* to come into play at runtimes | |||
"-DLLVM_ENABLE_RUNTIMES=libcxx;libcxxabi" | |||
# this makes llvm only to produce code for the current platform, this saves CPU time, change it to what you need | # this makes llvm only to produce code for the current platform, this saves CPU time, change it to what you need | ||
"-DLLVM_TARGETS_TO_BUILD=host" | "-DLLVM_TARGETS_TO_BUILD=host" | ||
| Line 44: | Line 47: | ||
<syntaxHighlight lang=console> | <syntaxHighlight lang=console> | ||
$ git clone https://github.com/llvm/llvm-project/ | |||
$ mkdir build && cd build | |||
$ cmake $cmakeFlags ../llvm-project/llvm | |||
$ ninja | |||
$ # installs everything to ../inst | |||
$ ninja install | |||
$ cd .. | |||
</syntaxHighlight> | </syntaxHighlight> | ||
| Line 56: | Line 59: | ||
<syntaxHighlight lang=console> | <syntaxHighlight lang=console> | ||
$ ./inst/bin/clang $CFLAGS -o main main.c | |||
</syntaxHighlight> | </syntaxHighlight> | ||
== Building Nixpkgs/NixOS with LLVM == | |||
It is technically possible to build Nixpkgs and NixOS with LLVM, however many packages are broken due to the differences between GCC and Clang. Tristan Ross, one of the maintainers of LLVM, started a project back in June of 2024 to improve the state of LLVM compiled packages. Currently, the project is located on GitHub at [https://github.com/RossComputerGuy/nixpkgs-llvm-ws RossComputerGuy/nixpkgs-llvm-ws]. Many packages have been fixed upstream but it is best to try the Flake as not all fixes are merged. | |||
=== Using LLVM in Nixpkgs without the Nixpkgs LLVM Workspace === | |||
To use LLVM to build packages in Nix, it can be done by either using the <code>pkgsLLVM</code> attribute or by overriding a derivation and changing out the <code>stdenv</code>. Changing out the <code>stdenv</code> is as simple as this:<syntaxhighlight lang="nix"> | |||
pkgs.hello.override { | |||
stdenv = pkgs.llvmPackages.stdenv; | |||
} | |||
</syntaxhighlight> | |||
[[Category:Development]] | |||