maa-assistant-arknights: init at 5.2.0

This commit is contained in:
北雁 Cryolitia 2024-03-26 03:12:20 +08:00
parent edeff1bd7d
commit bb69f630bf
No known key found for this signature in database
GPG Key ID: 3E5D1772FC8A8EDD
4 changed files with 211 additions and 0 deletions

View File

@ -0,0 +1,74 @@
{ stdenv
, config
, pkgs
, lib
, fetchFromGitHub
, cmake
, eigen
, onnxruntime
, opencv
, cudaSupport ? config.cudaSupport
, cudaPackages ? { }
}@inputs:
let
effectiveStdenv = if cudaSupport then cudaPackages.backendStdenv else inputs.stdenv;
cudaCapabilities = cudaPackages.cudaFlags.cudaCapabilities;
# E.g. [ "80" "86" "90" ]
cudaArchitectures = (builtins.map cudaPackages.cudaFlags.dropDot cudaCapabilities);
cudaArchitecturesString = lib.strings.concatStringsSep ";" cudaArchitectures;
in
effectiveStdenv.mkDerivation (finalAttrs: {
pname = "fastdeploy-ppocr";
version = "0-unstable-2023-10-09";
src = fetchFromGitHub {
owner = "Cryolitia";
repo = "FastDeploy";
# follows https://github.com/MaaAssistantArknights/MaaDeps/blob/master/vcpkg-overlay/ports/maa-fastdeploy/portfile.cmake#L4
rev = "2e68908141f6950bc5d22ba84f514e893cc238ea";
hash = "sha256-BWO4lKZhwNG6mbkC70hPgMNjabTnEV5XMo0bLV/gvQs=";
};
outputs = [ "out" "cmake" ];
nativeBuildInputs = [
cmake
eigen
] ++ lib.optionals cudaSupport [
cudaPackages.cuda_nvcc
];
buildInputs = [
onnxruntime
opencv
] ++ lib.optionals cudaSupport (with cudaPackages; [
cuda_cccl # cub/cub.cuh
libcublas # cublas_v2.h
libcurand # curand.h
libcusparse # cusparse.h
libcufft # cufft.h
cudnn # cudnn.h
cuda_cudart
]);
cmakeFlags = [
(lib.cmakeFeature "CMAKE_BUILD_TYPE" "None")
(lib.cmakeBool "BUILD_SHARED_LIBS" true)
] ++ lib.optionals cudaSupport [
(lib.cmakeFeature "CMAKE_CUDA_ARCHITECTURES" cudaArchitecturesString)
];
postInstall = ''
mkdir $cmake
install -Dm644 ${finalAttrs.src}/cmake/Findonnxruntime.cmake $cmake/
'';
meta = with lib; {
description = "MaaAssistantArknights stripped-down version of FastDeploy";
homepage = "https://github.com/MaaAssistantArknights/FastDeploy";
platforms = platforms.linux;
license = licenses.apsl20;
broken = cudaSupport && stdenv.hostPlatform.system != "x86_64-linux";
};
})

View File

@ -0,0 +1,99 @@
{ lib
, config
, callPackage
, stdenv
, fetchFromGitHub
, asio
, cmake
, eigen
, libcpr
, onnxruntime
, opencv
, isBeta ? false
, cudaSupport ? config.cudaSupport
, cudaPackages ? { }
}:
let
fastdeploy = callPackage ./fastdeploy-ppocr.nix { };
sources = lib.importJSON ./pin.json;
in
stdenv.mkDerivation (finalAttr: {
pname = "maa-assistant-arknights" + lib.optionalString isBeta "-beta";
version = if isBeta then sources.beta.version else sources.stable.version;
src = fetchFromGitHub {
owner = "MaaAssistantArknights";
repo = "MaaAssistantArknights";
rev = "v${finalAttr.version}";
hash = if isBeta then sources.beta.hash else sources.stable.hash;
};
# https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=maa-assistant-arknights
postPatch = ''
substituteInPlace CMakeLists.txt \
--replace-fail 'RUNTIME DESTINATION .' ' ' \
--replace-fail 'LIBRARY DESTINATION .' ' ' \
--replace-fail 'PUBLIC_HEADER DESTINATION .' ' '
substituteInPlace CMakeLists.txt \
--replace-fail 'find_package(asio ' '# find_package(asio ' \
--replace-fail 'asio::asio' ' '
shopt -s globstar nullglob
substituteInPlace src/MaaCore/**/{*.h,*.cpp,*.hpp,*.cc} \
--replace 'onnxruntime/core/session/' ""
substituteInPlace CMakeLists.txt \
--replace-fail 'ONNXRuntime' 'onnxruntime'
cp -v ${fastdeploy.cmake}/Findonnxruntime.cmake cmake/
'';
nativeBuildInputs = [
asio
cmake
fastdeploy.cmake
] ++ lib.optionals cudaSupport [
cudaPackages.cuda_nvcc
];
buildInputs = [
fastdeploy
libcpr
onnxruntime
opencv
] ++ lib.optionals cudaSupport (with cudaPackages; [
cuda_cccl # cub/cub.cuh
libcublas # cublas_v2.h
libcurand # curand.h
libcusparse # cusparse.h
libcufft # cufft.h
cudnn # cudnn.h
cuda_cudart
]);
cmakeFlags = [
(lib.cmakeFeature "CMAKE_BUILD_TYPE" "None")
(lib.cmakeBool "USE_MAADEPS" false)
(lib.cmakeBool "BUILD_SHARED_LIBS" true)
(lib.cmakeBool "INSTALL_RESOURCE" true)
(lib.cmakeBool "INSTALL_PYTHON" true)
(lib.cmakeFeature "MAA_VERSION" "v${finalAttr.version}")
];
passthru.updateScript = ./update.sh;
postInstall = ''
mkdir -p $out/share/${finalAttr.pname}
mv $out/{Python,resource} $out/share/${finalAttr.pname}
'';
meta = with lib; {
description = "An Arknights assistant";
homepage = "https://github.com/MaaAssistantArknights/MaaAssistantArknights";
license = licenses.agpl3Only;
maintainers = with maintainers; [ Cryolitia ];
platforms = platforms.linux;
};
})

View File

@ -0,0 +1,10 @@
{
"stable": {
"version": "5.2.0",
"hash": "sha256-vxGJHm1StQNN+0IVlGMqKVKW56LH6KUC94utDn7FcNo="
},
"beta": {
"version": "5.2.0",
"hash": "sha256-vxGJHm1StQNN+0IVlGMqKVKW56LH6KUC94utDn7FcNo="
}
}

View File

@ -0,0 +1,28 @@
#!/usr/bin/env -S nix shell nixpkgs#nix nixpkgs#curl nixpkgs#jq nixpkgs#nix-prefetch-github --command bash
set -euo pipefail
directory="$(dirname $0 | xargs realpath)"
version_stable="$(curl "https://api.github.com/repos/MaaAssistantArknights/MaaAssistantArknights/releases/latest" | jq -r '.tag_name')"
hash_stable=$(nix-prefetch-github MaaAssistantArknights MaaAssistantArknights --rev ${version_stable} -v | jq -r .hash)
version_beta="$(curl "https://api.github.com/repos/MaaAssistantArknights/MaaAssistantArknights/releases?per_page=1" | jq -r '.[0].tag_name')"
hash_beta=$(nix-prefetch-github MaaAssistantArknights MaaAssistantArknights --rev ${version_beta} -v | jq -r .hash)
cat > $directory/pin.json << EOF
{
"stable": {
"version": "${version_stable#*v}",
"hash": "$hash_stable"
},
"beta": {
"version": "${version_beta#*v}",
"hash": "$hash_beta"
}
}
EOF
cat $directory/pin.json