|
| 1 | +{ |
| 2 | + callPackage, |
| 3 | + newScope, |
| 4 | + wrapCCWith, |
| 5 | + symlinkJoin, |
| 6 | + overrideCC, |
| 7 | + lib, |
| 8 | + fetchFromGitHub, |
| 9 | +}: |
| 10 | +let |
| 11 | + # This derivation uses makeScope to help with overriding. |
| 12 | + # |
| 13 | + # To override the source and other basics: |
| 14 | + # pkgs.intel-llvm.overrideScope (final: prev: { |
| 15 | + # version = ..; |
| 16 | + # src = ..; |
| 17 | + # # If setting src, you'll probably also want to set this. |
| 18 | + # commitDate = ..; |
| 19 | + # }) |
| 20 | + # |
| 21 | + # To override something inside unified-runtime: |
| 22 | + # pkgs.intel-llvm.overrideScope (final: prev: { |
| 23 | + # make-unified-runtime = args: (prev.make-unified-runtime args) |
| 24 | + # .override { .. } |
| 25 | + # .overrideAttrs { .. } |
| 26 | + # }) |
| 27 | + scope = lib.makeScope newScope (self: { |
| 28 | + # == Parameters for overriding == |
| 29 | + |
| 30 | + llvmMajorVersion = "22"; |
| 31 | + |
| 32 | + version = "unstable-2025-11-14"; |
| 33 | + |
| 34 | + src = fetchFromGitHub { |
| 35 | + owner = "intel"; |
| 36 | + repo = "llvm"; |
| 37 | + # Latest commit which doesn't require dependency versions newer than |
| 38 | + # what's available in nixpkgs as of 2026-01-13. |
| 39 | + # Commits after require newer level-zero and pre-release unified memory framework. |
| 40 | + rev = "ab3dc98de0fd1ada9df12b138de1e1f8b715cc27"; |
| 41 | + hash = "sha256-oHk8kQVNsyC9vrOsDqVoFLYl2yMMaTgpQnAW9iHZLfE="; |
| 42 | + }; |
| 43 | + |
| 44 | + # If you override src, you'll probably also want to override this, |
| 45 | + # as some packages check for this date to decide what features the compiler supports |
| 46 | + commitDate = "20251114"; |
| 47 | + |
| 48 | + vc-intrinsics-src = fetchFromGitHub { |
| 49 | + owner = "intel"; |
| 50 | + repo = "vc-intrinsics"; |
| 51 | + # See llvm/lib/SYCLLowerIR/CMakeLists.txt:17 |
| 52 | + rev = "60cea7590bd022d95f5cf336ee765033bd114d69"; |
| 53 | + sha256 = "sha256-1K16UEa6DHoP2ukSx58OXJdtDWyUyHkq5Gd2DUj1644="; |
| 54 | + }; |
| 55 | + |
| 56 | + # =============================== |
| 57 | + |
| 58 | + make-unified-runtime = |
| 59 | + { |
| 60 | + levelZeroSupport, |
| 61 | + cudaSupport, |
| 62 | + rocmSupport, |
| 63 | + rocmGpuTargets, |
| 64 | + nativeCpuSupport, |
| 65 | + }: |
| 66 | + callPackage ./unified-runtime.nix { |
| 67 | + intel-llvm-src = self.src; |
| 68 | + inherit |
| 69 | + levelZeroSupport |
| 70 | + cudaSupport |
| 71 | + rocmSupport |
| 72 | + rocmGpuTargets |
| 73 | + nativeCpuSupport |
| 74 | + ; |
| 75 | + # This could theoretically be disabled if you for some reason |
| 76 | + # didn't want to build the backend, however OpenCL will get |
| 77 | + # pulled in as a dependency either way so there is little point. |
| 78 | + openclSupport = true; |
| 79 | + }; |
| 80 | + |
| 81 | + unwrapped = callPackage ./unwrapped.nix { |
| 82 | + inherit (self) |
| 83 | + llvmMajorVersion |
| 84 | + src |
| 85 | + version |
| 86 | + commitDate |
| 87 | + vc-intrinsics-src |
| 88 | + make-unified-runtime |
| 89 | + ; |
| 90 | + }; |
| 91 | + |
| 92 | + wrapper = |
| 93 | + (wrapCCWith { |
| 94 | + cc = self.unwrapped; |
| 95 | + # This is needed for tools like clang-scan-deps to find headers. |
| 96 | + # The build commands here are the same as the vanilla LLVM derivation. |
| 97 | + extraBuildCommands = '' |
| 98 | + rsrc="$out/resource-root" |
| 99 | + mkdir "$rsrc" |
| 100 | + echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags |
| 101 | + ln -s "${lib.getLib self.unwrapped}/lib/clang/${self.llvmMajorVersion}/include" "$rsrc" |
| 102 | + ''; |
| 103 | + }).overrideAttrs |
| 104 | + (old: { |
| 105 | + # OpenCL needs to be passed through |
| 106 | + propagatedBuildInputs = old.propagatedBuildInputs ++ self.unwrapped.propagatedBuildInputs; |
| 107 | + }); |
| 108 | + |
| 109 | + clang-tools-wrapper = callPackage ./clang-tools.nix { |
| 110 | + inherit (self) unwrapped wrapper; |
| 111 | + }; |
| 112 | + |
| 113 | + # We merge everything into one by default to avoid issues with path-lookup. |
| 114 | + # intel-llvm provides the SYCL library, so unlike regular LLVM libraries, |
| 115 | + # its libraries are equally important as the compiler itself. |
| 116 | + # Splitting is nonetheless important, as otherwise the binaries go over the Hydra limit. |
| 117 | + merged = symlinkJoin { |
| 118 | + inherit (self.unwrapped) pname version meta; |
| 119 | + |
| 120 | + strictDeps = true; |
| 121 | + __structuredAttrs = true; |
| 122 | + |
| 123 | + paths = with self; [ |
| 124 | + # Order is important, we want files from the wrappers to take precedence |
| 125 | + wrapper |
| 126 | + clang-tools-wrapper |
| 127 | + |
| 128 | + unwrapped.out |
| 129 | + unwrapped.dev |
| 130 | + unwrapped.lib |
| 131 | + ]; |
| 132 | + |
| 133 | + passthru = self.unwrapped.passthru // { |
| 134 | + inherit (self) stdenv; |
| 135 | + unwrapped = self.unwrapped; |
| 136 | + tests = callPackage ./tests.nix { inherit (self) stdenv; }; |
| 137 | + |
| 138 | + overrideScope = newF: (self.overrideScope newF).merged; |
| 139 | + }; |
| 140 | + }; |
| 141 | + stdenv = overrideCC self.unwrapped.baseLlvm.stdenv self.merged; |
| 142 | + }); |
| 143 | +in |
| 144 | +scope.merged |
0 commit comments