nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{ lib, stdenv, llvm_meta
2, buildLlvmTools
3, monorepoSrc, runCommand
4, cmake
5, libxml2
6, libllvm
7, version
8}:
9
10stdenv.mkDerivation rec {
11 pname = "lld";
12 inherit version;
13
14 # Blank llvm dir just so relative path works
15 src = runCommand "${pname}-src-${version}" {} ''
16 mkdir -p "$out"
17 cp -r ${monorepoSrc}/cmake "$out"
18 cp -r ${monorepoSrc}/${pname} "$out"
19 mkdir -p "$out/libunwind"
20 cp -r ${monorepoSrc}/libunwind/include "$out/libunwind"
21 mkdir -p "$out/llvm"
22 '';
23
24 sourceRoot = "${src.name}/${pname}";
25
26 patches = [
27 ./gnu-install-dirs.patch
28 # On Darwin the llvm-config is perhaps not working fine as the
29 # LLVM_MAIN_SRC_DIR is not getting set correctly, and the build fails as
30 # the include path is not correct.
31 ./fix-root-src-dir.patch
32 ];
33
34 nativeBuildInputs = [ cmake ];
35 buildInputs = [ libllvm libxml2 ];
36
37 cmakeFlags = lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
38 "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen"
39 ];
40
41 # Musl's default stack size is too small for lld to be able to link Firefox.
42 LDFLAGS = lib.optionalString stdenv.hostPlatform.isMusl "-Wl,-z,stack-size=2097152";
43
44 outputs = [ "out" "lib" "dev" ];
45
46 meta = llvm_meta // {
47 homepage = "https://lld.llvm.org/";
48 description = "The LLVM linker (unwrapped)";
49 longDescription = ''
50 LLD is a linker from the LLVM project that is a drop-in replacement for
51 system linkers and runs much faster than them. It also provides features
52 that are useful for toolchain developers.
53 The linker supports ELF (Unix), PE/COFF (Windows), Mach-O (macOS), and
54 WebAssembly in descending order of completeness. Internally, LLD consists
55 of several different linkers.
56 '';
57 };
58}