LLVM: Difference between revisions

imported>Nix
m add applications and languages categories
DHCP (talk | contribs)
m Build LLVM/clang from source: prefix shell comment with $ just so syntaxhighlight works properly
 
(4 intermediate revisions by 4 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;libcxx;libcxxabi"
     "-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/
$ git clone https://github.com/llvm/llvm-project/
$ mkdir build && cd build
$ mkdir build && cd build
$ cmake $cmakeFlags ../llvm-project/llvm
$ cmake $cmakeFlags ../llvm-project/llvm
$ ninja
$ ninja
# installs everything to ../inst
$ # installs everything to ../inst
$ ninja install
$ ninja install
$ cd ..
$ cd ..
</syntaxHighlight>
</syntaxHighlight>


Line 56: Line 59:


<syntaxHighlight lang=console>
<syntaxHighlight lang=console>
$ ./inst/bin/clang $CFLAGS -o main main.c  
$ ./inst/bin/clang $CFLAGS -o main main.c  
</syntaxHighlight>
</syntaxHighlight>


[[Category:Applications]]
== Building Nixpkgs/NixOS with LLVM ==
[[Category:Languages]]
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]]