3636 # It's necessary to consistently use backendStdenv when building with CUDA support,
3737 # otherwise we get libstdc++ errors downstream.
3838 effectiveStdenv ? if useCuda then cudaPackages . backendStdenv else stdenv ,
39- enableStatic ? effectiveStdenv . hostPlatform . isStatic
39+ enableStatic ? effectiveStdenv . hostPlatform . isStatic ,
40+ precompileMetalShaders ? false
4041} @inputs :
4142
4243let
@@ -166,12 +167,12 @@ effectiveStdenv.mkDerivation (
166167 '' ;
167168
168169 # With PR#6015 https://github.com/ggerganov/llama.cpp/pull/6015,
169- # `default.metallib` is compiled with Metal compiler from XCode
170+ # `default.metallib` may be compiled with Metal compiler from XCode
170171 # and we need to escape sandbox on MacOS to access Metal compiler.
171172 # `xcrun` is used find the path of the Metal compiler, which is varible
172173 # and not on $PATH
173174 # see https://github.com/ggerganov/llama.cpp/pull/6118 for discussion
174- __noChroot = effectiveStdenv . isDarwin && useMetalKit ;
175+ __noChroot = effectiveStdenv . isDarwin && useMetalKit && precompileMetalShaders ;
175176
176177 nativeBuildInputs =
177178 [
@@ -189,7 +190,7 @@ effectiveStdenv.mkDerivation (
189190 ]
190191 ++ optionals ( effectiveStdenv . hostPlatform . isGnu && enableStatic ) [
191192 glibc . static
192- ] ++ optionals ( effectiveStdenv . isDarwin && useMetalKit ) [
193+ ] ++ optionals ( effectiveStdenv . isDarwin && useMetalKit && precompileMetalShaders ) [
193194 xcrunHost
194195 ] ;
195196
@@ -234,7 +235,10 @@ effectiveStdenv.mkDerivation (
234235 # Should likely use `rocmPackages.clr.gpuTargets`.
235236 "-DAMDGPU_TARGETS=gfx803;gfx900;gfx906:xnack-;gfx908:xnack-;gfx90a:xnack+;gfx90a:xnack-;gfx940;gfx941;gfx942;gfx1010;gfx1012;gfx1030;gfx1100;gfx1101;gfx1102"
236237 ]
237- ++ optionals useMetalKit [ ( lib . cmakeFeature "CMAKE_C_FLAGS" "-D__ARM_FEATURE_DOTPROD=1" ) ]
238+ ++ optionals useMetalKit [
239+ ( lib . cmakeFeature "CMAKE_C_FLAGS" "-D__ARM_FEATURE_DOTPROD=1" )
240+ ( cmakeBool "LLAMA_METAL_EMBED_LIBRARY" ( ! precompileMetalShaders ) )
241+ ]
238242 ++ optionals useBlas [ ( lib . cmakeFeature "LLAMA_BLAS_VENDOR" "OpenBLAS" ) ] ;
239243
240244 # TODO(SomeoneSerge): It's better to add proper install targets at the CMake level,
0 commit comments