Can someone please help me with the following problems:
This triggers a full build of LLVM from source (unlike clangStdenv from regular, non-cross nixpkgs). Why? How can I use a regular, cached LLVM for cross-compilation?
It uses clang 18. I’d rather have clang 17. How can I specify another version?
Darwin to wasm simply isn’t a combination of platforms that hydra builds. I’m half surprised that even works tbh.
Darwin to Darwin or Linux to Linux using clang OTOH is quite common and happens within regular Nixpkgs.
We provide multiple versions of LLVM in Nixpkgs following the pattern of llvmPackages_xy where xy is the major version. In your case simply use llvmPackages_17.stdenv.
Darwin to wasm simply isn’t a combination of platforms that hydra builds.
But isn’t clang (unlike gcc) is a universal cross-compiler by itself, so same clang binary can be used for any target, so there is just no need to rebuild it regardless of the target?
We provide multiple versions of LLVM in Nixpkgs following the pattern of llvmPackages_xy where xy is the major version. In your case simply use llvmPackages_17.stdenv .
I tried to change stdenvCross = pkgsCross.clangStdenv; to stdenvCross = pkgsCross.llvmPackages_17.stdenv;. Now when I run nix develop, it starts building both llvm-17 and llvm-18. That really confuses me
In theory yes, in practice because of how Nixpkgs cross is structured we can’t share those binaries. That’s an unfortunate limitation that hopefully we will one day fix.
LLVM 18 is the default for all platforms except Darwin, including WASM. (In Nixpkgs 25.05 it’ll be LLVM 19 on all platforms.)
FWIW your config is not quite right. I would suggest trying pkgsCross.wasi32 instead.
That’s an unfortunate limitation that hopefully we will one day fix.
Got it. Is there anything that can be done about it now? Maybe there’s some workaround I could apply? Maybe is makes sense to ask somewhere for adding pkgsCross.wasi32 to public cache, at least stdenv, since it’s quite a popular platform nowadays?
FWIW your config is not quite right. I would suggest trying pkgsCross.wasi32 instead.
You can maybe try some rewrapping stuff, but it’s kind of a pain and will be problematic with library dependencies. I think your best option at present is just to deal with the LLVM build.
This is correct and clang-unwrapped as well as llvm would be shard if they were the same. However we currently have some minor differences depending on the platform we are targeting which should eventually be eliminated. You can inspect differences yourself using nix-diff, e.g. nix-shell -p nix-diff --run "nix-instantiate -A llvmPackages_18.clang-unwrapped -A pkgsCross.wasi32.stdenv.cc.cc | xargs nix-diff.
Current things preventing clang-unwrapped from being shared:
On e.g. Linux we build the LLVM plugin for ld.gold (necessary for e.g. LTO) if the target platform supports it.
Clang receives a different patch depending on darwin or not. This patch will probably be removed altogether eventually.