Cross-compiling with clang for RISC-V

I’m trying to create a cross-compilation environment using clang for RISC-V. After reading Clang can't be used to cross-build packages. · Issue #40934 · NixOS/nixpkgs · GitHub, I managed to get this to evaluate:

{ nixpkgs ? <nixpkgs>
, pkgs ? import nixpkgs { }}:

  lib = pkgs.lib;
in rec {

  # gccRiscvPkgs = pkgs.pkgsCross.riscv64;
  clangRiscvPkgs = import nixpkgs { crossSystem = // { useLLVM = true; }; };

  hello = clangRiscvPkgs.hello;

The problem is that this tries to build a toolchain with LLVM 8, which doesn’t yet have full RISC-V support. This was introduced in LLVM 9. I can see that LLVM 8 is hardcoded in nixpkgs/default.nix at a5661135f29f4b2603c41690a01c3168bc8760ae · NixOS/nixpkgs · GitHub for this usecase.

Is there a way to override the version of LLVM without patching nixpkgs?


There isn’t a way to do this currently. I think adding an option like llvmVersion or something to crossSystem would make sense though. We might also be able to just use LLVM 9 or 10 always for cross-compilation.

Updating to LLVM 9 seems like a sensible idea, but I’m not sure what the implications are for other architectures.

Clang can't be used to cross-build packages. · Issue #40934 · NixOS/nixpkgs · GitHub i just now fixed.

I would like the pkgs/build-support/alternatives from Add BLAS/LAPACK switching mechanism by matthewbauer · Pull Request #83888 · NixOS/nixpkgs · GitHub to handle the LLVM version.

1 Like

The problem with using something like alternatives here is that you can’t just override the “clang” due to bootstrapping dependencies. You need it to be some kind of configuration option.

I was thinking more choosing Also I’d love all the choices outlined in Assembling a Complete Toolchain — Clang 13 documentation to be made independently all sorts of LLVM vs GNU mashups. Once GCC is broken up both should be bootstrapped the same way.

1 Like


1 Like