1{
2 lib,
3 stdenv,
4 llvm_meta,
5 release_version,
6 buildLlvmTools,
7 monorepoSrc ? null,
8 src ? null,
9 runCommand,
10 cmake,
11 ninja,
12 libxml2,
13 libllvm,
14 version,
15 devExtraCmakeFlags ? [ ],
16 getVersionFile,
17 fetchpatch,
18}:
19stdenv.mkDerivation (finalAttrs: {
20 pname = "lld";
21 inherit version;
22
23 src =
24 if monorepoSrc != null then
25 runCommand "lld-src-${version}" { inherit (monorepoSrc) passthru; } (''
26 mkdir -p "$out"
27 cp -r ${monorepoSrc}/cmake "$out"
28 cp -r ${monorepoSrc}/lld "$out"
29 mkdir -p "$out/libunwind"
30 cp -r ${monorepoSrc}/libunwind/include "$out/libunwind"
31 mkdir -p "$out/llvm"
32 '')
33 else
34 src;
35
36 sourceRoot = "${finalAttrs.src.name}/lld";
37
38 patches = [
39 (getVersionFile "lld/gnu-install-dirs.patch")
40 ]
41 ++ lib.optional (lib.versions.major release_version == "18") (
42 # https://github.com/llvm/llvm-project/pull/97122
43 fetchpatch {
44 name = "more-openbsd-program-headers.patch";
45 url = "https://github.com/llvm/llvm-project/commit/d7fd8b19e560fbb613159625acd8046d0df75115.patch";
46 stripLen = 1;
47 hash = "sha256-7wTy7XDTx0+fhWQpW1KEuz7xJvpl42qMTUfd20KGOfA=";
48 }
49 );
50
51 nativeBuildInputs = [
52 cmake
53 ninja
54 ];
55 buildInputs = [
56 libllvm
57 libxml2
58 ];
59
60 cmakeFlags = [
61 (lib.cmakeFeature "LLD_INSTALL_PACKAGE_DIR" "${placeholder "dev"}/lib/cmake/lld")
62 (lib.cmakeFeature "LLVM_TABLEGEN_EXE" "${buildLlvmTools.tblgen}/bin/llvm-tblgen")
63 ]
64 ++ devExtraCmakeFlags;
65
66 # TODO: Remove on `staging`.
67 postPatch = "";
68
69 # Musl's default stack size is too small for lld to be able to link Firefox.
70 LDFLAGS = lib.optionalString stdenv.hostPlatform.isMusl "-Wl,-z,stack-size=2097152";
71
72 outputs = [
73 "out"
74 "lib"
75 "dev"
76 ];
77
78 meta = llvm_meta // {
79 homepage = "https://lld.llvm.org/";
80 description = "LLVM linker (unwrapped)";
81 longDescription = ''
82 LLD is a linker from the LLVM project that is a drop-in replacement for
83 system linkers and runs much faster than them. It also provides features
84 that are useful for toolchain developers.
85 The linker supports ELF (Unix), PE/COFF (Windows), Mach-O (macOS), and
86 WebAssembly in descending order of completeness. Internally, LLD consists
87 of several different linkers.
88 '';
89 };
90})