1{ lib
2, stdenv
3, fetchFromGitHub
4, cmake
5, vulkan-headers
6, vulkan-loader
7, glslang
8, opencv
9, protobuf
10}:
11
12stdenv.mkDerivation rec {
13 pname = "ncnn";
14 version = "20240410";
15
16 src = fetchFromGitHub {
17 owner = "Tencent";
18 repo = pname;
19 rev = version;
20 hash = "sha256-UiaU+LCevrWBxZg5LAimGIJB0CElWBnO6qoadUc3VVM=";
21 };
22
23 patches = [
24 ./cmakelists.patch
25 ];
26
27 cmakeFlags = [
28 "-DNCNN_CMAKE_VERBOSE=1" # Only for debugging the build
29 "-DNCNN_SHARED_LIB=1"
30 "-DNCNN_ENABLE_LTO=1"
31 "-DNCNN_VULKAN=1"
32 "-DNCNN_BUILD_EXAMPLES=0"
33 "-DNCNN_BUILD_TOOLS=0"
34 "-DNCNN_SYSTEM_GLSLANG=1"
35 "-DNCNN_PYTHON=0" # Should be an attribute
36 ]
37 # Requires setting `Vulkan_LIBRARY` on Darwin. Otherwise the build fails due to missing symbols.
38 ++ lib.optionals stdenv.isDarwin [ "-DVulkan_LIBRARY=-lvulkan" ];
39
40 nativeBuildInputs = [ cmake ];
41 buildInputs = [ vulkan-headers vulkan-loader glslang opencv protobuf ];
42
43 meta = with lib; {
44 description = "ncnn is a high-performance neural network inference framework optimized for the mobile platform";
45 homepage = "https://github.com/Tencent/ncnn";
46 license = licenses.bsd3;
47 maintainers = with maintainers; [ tilcreator ];
48 platforms = platforms.all;
49 };
50}