lol
1{ callPackage
2, cmake
3, fetchFromGitHub
4, lib
5, protobuf
6, python3
7, stdenv
8, buildPackages
9, mallocBuild ? false
10}:
11
12stdenv.mkDerivation rec {
13 pname = "nanopb";
14 version = "0.4.6";
15
16 src = fetchFromGitHub {
17 owner = pname;
18 repo = pname;
19 rev = version;
20 sha256 = "sha256-B9J+GkgOBR4iZaP6/2ykcjbkifoyhkuukkjK/CLBZj0=";
21 };
22
23 nativeBuildInputs = [ cmake python3 python3.pkgs.wrapPython ];
24
25 pythonPath = with python3.pkgs; [ python3.pkgs.protobuf six ];
26
27 cmakeFlags = [
28 "-DBUILD_SHARED_LIBS=ON" # generate $out/lib/libprotobuf-nanopb.so{.0,}
29 "-DBUILD_STATIC_LIBS=ON" # generate $out/lib/libprotobuf-nanopb.a
30 "-Dnanopb_PROTOC_PATH=${buildPackages.protobuf}/bin/protoc"
31 ] ++ lib.optional mallocBuild "-DCMAKE_C_FLAGS=-DPB_ENABLE_MALLOC 1";
32
33 postInstall = ''
34 mkdir -p $out/share/nanopb/generator/proto
35 cp ../generator/proto/nanopb.proto $out/share/nanopb/generator/proto/nanopb.proto
36 cp ../pb_common.c ../pb_decode.c ../pb_encode.c $out/include/
37 '';
38
39 postFixup = ''
40 wrapPythonPrograms
41 '';
42
43 passthru.tests = {
44 simple-proto2 = callPackage ./test-simple-proto2 {};
45 simple-proto3 = callPackage ./test-simple-proto3 {};
46 message-with-annotations = callPackage ./test-message-with-annotations {};
47 message-with-options = callPackage ./test-message-with-options {};
48 };
49
50 meta = with lib; {
51 inherit (protobuf.meta) platforms;
52
53 description = "Protocol Buffers with small code size";
54 homepage = "https://jpa.kapsi.fi/nanopb/";
55 license = licenses.zlib;
56 maintainers = with maintainers; [ kalbasit ];
57
58 longDescription = ''
59 Nanopb is a small code-size Protocol Buffers implementation in ansi C. It
60 is especially suitable for use in microcontrollers, but fits any memory
61 restricted system.
62
63 - Homepage: jpa.kapsi.fi/nanopb
64 - Documentation: jpa.kapsi.fi/nanopb/docs
65 - Downloads: jpa.kapsi.fi/nanopb/download
66 - Forum: groups.google.com/forum/#!forum/nanopb
67
68 In order to use the nanopb options in your proto files, you'll need to
69 tell protoc where to find the nanopb.proto file.
70 You can do so with the --proto_path (-I) option to add the directory
71 ''${nanopb}/share/nanopb/generator/proto like so:
72
73 protoc --proto_path=. --proto_path=''${nanopb}/share/nanopb/generator/proto --plugin=protoc-gen-nanopb=''${nanopb}/bin/protoc-gen-nanopb --nanopb_out=out file.proto
74 '';
75 };
76}