From bb69f630bf6ce3bff4b2433e9b635c698e87e343 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8C=97=E9=9B=81=20Cryolitia?= Date: Tue, 26 Mar 2024 03:12:20 +0800 Subject: [PATCH] maa-assistant-arknights: init at 5.2.0 --- .../fastdeploy-ppocr.nix | 74 ++++++++++++++ .../ma/maa-assistant-arknights/package.nix | 99 +++++++++++++++++++ .../ma/maa-assistant-arknights/pin.json | 10 ++ .../ma/maa-assistant-arknights/update.sh | 28 ++++++ 4 files changed, 211 insertions(+) create mode 100644 pkgs/by-name/ma/maa-assistant-arknights/fastdeploy-ppocr.nix create mode 100644 pkgs/by-name/ma/maa-assistant-arknights/package.nix create mode 100644 pkgs/by-name/ma/maa-assistant-arknights/pin.json create mode 100755 pkgs/by-name/ma/maa-assistant-arknights/update.sh diff --git a/pkgs/by-name/ma/maa-assistant-arknights/fastdeploy-ppocr.nix b/pkgs/by-name/ma/maa-assistant-arknights/fastdeploy-ppocr.nix new file mode 100644 index 000000000000..c4ccfc7566b9 --- /dev/null +++ b/pkgs/by-name/ma/maa-assistant-arknights/fastdeploy-ppocr.nix @@ -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"; + }; +}) diff --git a/pkgs/by-name/ma/maa-assistant-arknights/package.nix b/pkgs/by-name/ma/maa-assistant-arknights/package.nix new file mode 100644 index 000000000000..c53c52562db8 --- /dev/null +++ b/pkgs/by-name/ma/maa-assistant-arknights/package.nix @@ -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; + }; +}) diff --git a/pkgs/by-name/ma/maa-assistant-arknights/pin.json b/pkgs/by-name/ma/maa-assistant-arknights/pin.json new file mode 100644 index 000000000000..36f8fcf42070 --- /dev/null +++ b/pkgs/by-name/ma/maa-assistant-arknights/pin.json @@ -0,0 +1,10 @@ +{ + "stable": { + "version": "5.2.0", + "hash": "sha256-vxGJHm1StQNN+0IVlGMqKVKW56LH6KUC94utDn7FcNo=" + }, + "beta": { + "version": "5.2.0", + "hash": "sha256-vxGJHm1StQNN+0IVlGMqKVKW56LH6KUC94utDn7FcNo=" + } +} diff --git a/pkgs/by-name/ma/maa-assistant-arknights/update.sh b/pkgs/by-name/ma/maa-assistant-arknights/update.sh new file mode 100755 index 000000000000..50cff9d38d78 --- /dev/null +++ b/pkgs/by-name/ma/maa-assistant-arknights/update.sh @@ -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