at master 2.9 kB view raw
1{ 2 cmake, 3 devExtraCmakeFlags ? [ ], 4 lib, 5 llvm_meta, 6 monorepoSrc ? null, 7 ninja, 8 patches ? [ ], 9 python3, 10 updateAutotoolsGnuConfigScriptsHook, 11 release_version, 12 runCommand, 13 src ? null, 14 stdenv, 15 version, 16 clangPatches, 17}: 18 19let 20 # This is a synthetic package which is not an official part of the llvm-project. 21 # See https://github.com/NixOS/nixpkgs/pull/362384 for discussion. 22 # 23 # LLVM has tools that run at build time. In native builds, these are 24 # built as a part of the usual build, but in cross builds they need to 25 # come from buildPackages. 26 # 27 # In many scenarios this is a small problem because LLVM from 28 # buildPackages is already available as a build; but if cross building a 29 # version of LLVM which is not available (e.g. a new git commit of LLVM) 30 # this results in two builds of LLVM and clang, one native and one for the 31 # cross. 32 # 33 # Full builds of LLVM are expensive; and unnecessary in this scenario. We 34 # don't need a native LLVM, only a native copy of the tools which run at 35 # build time. This is only tablegen and related tooling, which are cheap 36 # to build. 37 pname = "llvm-tblgen"; 38 39 src' = 40 if monorepoSrc != null then 41 runCommand "${pname}-src-${version}" { } ('' 42 mkdir -p "$out" 43 cp -r ${monorepoSrc}/cmake "$out" 44 cp -r ${monorepoSrc}/third-party "$out" 45 cp -r ${monorepoSrc}/llvm "$out" 46 cp -r ${monorepoSrc}/clang "$out" 47 cp -r ${monorepoSrc}/clang-tools-extra "$out" 48 cp -r ${monorepoSrc}/mlir "$out" 49 '') 50 else 51 src; 52 53 # List of tablegen targets. 54 targets = [ 55 "clang-tblgen" 56 "llvm-tblgen" 57 "clang-tidy-confusable-chars-gen" 58 "mlir-tblgen" 59 ] 60 ++ lib.optionals (lib.versionOlder release_version "20") [ 61 "clang-pseudo-gen" # Removed in LLVM 20 @ ed8f78827895050442f544edef2933a60d4a7935. 62 ]; 63 64 self = stdenv.mkDerivation (finalAttrs: { 65 inherit pname version patches; 66 67 src = src'; 68 sourceRoot = "${finalAttrs.src.name}/llvm"; 69 70 __structuredAttrs = true; 71 72 postPatch = '' 73 ( 74 cd ../clang 75 chmod u+rwX -R . 76 for p in ${toString clangPatches} 77 do 78 patch -p1 < $p 79 done 80 ) 81 ''; 82 83 nativeBuildInputs = [ 84 cmake 85 ninja 86 python3 87 88 # while this is not an autotools build, it still includes a config.guess 89 # this is needed until scripts are updated to not use /usr/bin/uname on FreeBSD native 90 updateAutotoolsGnuConfigScriptsHook 91 ]; 92 93 cmakeFlags = [ 94 # Projects with tablegen-like tools. 95 "-DLLVM_ENABLE_PROJECTS=${ 96 lib.concatStringsSep ";" [ 97 "llvm" 98 "clang" 99 "clang-tools-extra" 100 "mlir" 101 ] 102 }" 103 ] 104 ++ devExtraCmakeFlags; 105 106 ninjaFlags = targets; 107 108 inherit targets; 109 110 installPhase = '' 111 mkdir -p $out/bin 112 cp "''${targets[@]/#/bin/}" $out/bin 113 ''; 114 }); 115in 116self