koboldcpp: drop unused args, refactor darwin sdks (#349052)

This commit is contained in:
Masum Reza 2024-11-21 23:35:09 +05:30 committed by GitHub
commit b4928123e8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -5,11 +5,10 @@
makeWrapper, makeWrapper,
gitUpdater, gitUpdater,
python3Packages, python3Packages,
python311Packages ? null, # Ignored. Kept for compatibility with the release
tk, tk,
addDriverRunpath, addDriverRunpath,
darwin, apple-sdk_12,
koboldLiteSupport ? true, koboldLiteSupport ? true,
@ -30,10 +29,8 @@
vulkanSupport ? true, vulkanSupport ? true,
vulkan-loader, vulkan-loader,
metalSupport ? stdenv.hostPlatform.isDarwin,
metalSupport ? stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64, nix-update-script,
march ? "",
mtune ? "",
}: }:
let let
@ -43,12 +40,6 @@ let
--prefix LD_LIBRARY_PATH : "${lib.makeLibraryPath [ addDriverRunpath.driverLink ]}" --prefix LD_LIBRARY_PATH : "${lib.makeLibraryPath [ addDriverRunpath.driverLink ]}"
''; '';
darwinFrameworks =
if (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isx86_64) then
darwin.apple_sdk.frameworks
else
darwin.apple_sdk_11_0.frameworks;
effectiveStdenv = if cublasSupport then cudaPackages.backendStdenv else stdenv; effectiveStdenv = if cublasSupport then cudaPackages.backendStdenv else stdenv;
in in
effectiveStdenv.mkDerivation (finalAttrs: { effectiveStdenv.mkDerivation (finalAttrs: {
@ -74,17 +65,7 @@ effectiveStdenv.mkDerivation (finalAttrs: {
buildInputs = buildInputs =
[ tk ] [ tk ]
++ finalAttrs.pythonInputs ++ finalAttrs.pythonInputs
++ lib.optionals effectiveStdenv.hostPlatform.isDarwin [ ++ lib.optionals stdenv.hostPlatform.isDarwin [ apple-sdk_12 ]
darwinFrameworks.Accelerate
darwinFrameworks.CoreVideo
darwinFrameworks.CoreGraphics
darwinFrameworks.CoreServices
]
++ lib.optionals metalSupport [
darwinFrameworks.MetalKit
darwinFrameworks.Foundation
darwinFrameworks.MetalPerformanceShaders
]
++ lib.optionals openblasSupport [ openblas ] ++ lib.optionals openblasSupport [ openblas ]
++ lib.optionals cublasSupport [ ++ lib.optionals cublasSupport [
cudaPackages.libcublas cudaPackages.libcublas
@ -100,29 +81,6 @@ effectiveStdenv.mkDerivation (finalAttrs: {
pythonPath = finalAttrs.pythonInputs; pythonPath = finalAttrs.pythonInputs;
darwinLdFlags = lib.optionals stdenv.hostPlatform.isDarwin [
"-F${darwinFrameworks.CoreServices}/Library/Frameworks"
"-F${darwinFrameworks.Accelerate}/Library/Frameworks"
"-framework CoreServices"
"-framework Accelerate"
];
metalLdFlags = lib.optionals metalSupport [
"-F${darwinFrameworks.Foundation}/Library/Frameworks"
"-F${darwinFrameworks.Metal}/Library/Frameworks"
"-framework Foundation"
"-framework Metal"
];
env.NIX_LDFLAGS = lib.concatStringsSep " " (finalAttrs.darwinLdFlags ++ finalAttrs.metalLdFlags);
env.NIX_CFLAGS_COMPILE =
lib.optionalString (march != "") (
lib.warn "koboldcpp: the march argument is only kept for compatibility; use overrideAttrs intead" "-march=${march}"
)
+ lib.optionalString (mtune != "") (
lib.warn "koboldcpp: the mtune argument is only kept for compatibility; use overrideAttrs intead" "-mtune=${mtune}"
);
makeFlags = [ makeFlags = [
(makeBool "LLAMA_OPENBLAS" openblasSupport) (makeBool "LLAMA_OPENBLAS" openblasSupport)
(makeBool "LLAMA_CUBLAS" cublasSupport) (makeBool "LLAMA_CUBLAS" cublasSupport)
@ -153,19 +111,13 @@ effectiveStdenv.mkDerivation (finalAttrs: {
runHook postInstall runHook postInstall
''; '';
# Remove an unused argument, mainly intended for Darwin to reduce warnings
postPatch = ''
substituteInPlace Makefile \
--replace-warn " -s " " "
'';
postFixup = '' postFixup = ''
wrapPythonProgramsIn "$out/bin" "$pythonPath" wrapPythonProgramsIn "$out/bin" "$pythonPath"
makeWrapper "$out/bin/koboldcpp.unwrapped" "$out/bin/koboldcpp" \ makeWrapper "$out/bin/koboldcpp.unwrapped" "$out/bin/koboldcpp" \
--prefix PATH : ${lib.makeBinPath [ tk ]} ${libraryPathWrapperArgs} --prefix PATH : ${lib.makeBinPath [ tk ]} ${libraryPathWrapperArgs}
''; '';
passthru.updateScript = gitUpdater { rev-prefix = "v"; }; passthru.updateScript = nix-update-script { };
meta = { meta = {
changelog = "https://github.com/LostRuins/koboldcpp/releases/tag/v${finalAttrs.version}"; changelog = "https://github.com/LostRuins/koboldcpp/releases/tag/v${finalAttrs.version}";