Cross-compiling with clang for RISC-V

I’m trying to create a cross-compilation environment using clang for RISC-V. After reading, 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 for this usecase.

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

1 Like

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. i just now fixed.

I would like the pkgs/build-support/alternatives from 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 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