git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #89070 from kalbasit/nixpkgs_add-nanopb

nanopb: init at 0.4.1

commit15a059bba215b2a6f2b3a1cc0aba92c1501dca36 authorWael Nasreddine <wael.nasreddine@gmail.com> dateTue 16 Jun 2020, 07:22 (6 years ago) parent138c2dcc081005
12 files changed+218
pkgs/development/libraries/nanopb/default.nix+88 pkgs/development/libraries/nanopb/protoc-gen-nanopb+3 pkgs/development/libraries/nanopb/test-message-with-annotations/default.nix+27 pkgs/development/libraries/nanopb/test-message-with-annotations/withannotations.proto+7 pkgs/development/libraries/nanopb/test-message-with-options/default.nix+27 pkgs/development/libraries/nanopb/test-message-with-options/withoptions.options+1 pkgs/development/libraries/nanopb/test-message-with-options/withoptions.proto+5 pkgs/development/libraries/nanopb/test-simple-proto2/default.nix+24 pkgs/development/libraries/nanopb/test-simple-proto2/simple.proto+5 pkgs/development/libraries/nanopb/test-simple-proto3/default.nix+24 pkgs/development/libraries/nanopb/test-simple-proto3/simple.proto+5 pkgs/top-level/all-packages.nix+2
pkgs/development/libraries/nanopb/default.nixnew file+88
@@ -0,0 +1,88 @@
1+{ callPackage
2+, cmake
3+, fetchFromGitHub
4+, lib
5+, protobuf
6+, python3
7+, stdenv
8+}:
9+
10+let
11+ pythonRuntime = python3.withPackages(ps: [ ps.protobuf ]);
12+in stdenv.mkDerivation rec {
13+ pname = "nanopb";
14+ version = "0.4.1";
15+
16+ src = fetchFromGitHub {
17+ owner = pname;
18+ repo = pname;
19+ rev = version;
20+ sha256 = "16zxk42wzn519bpxf4578qn97k0h1cnbkvqqkqvka9sl0n3lz2dp";
21+ };
22+
23+ nativeBuildInputs = [ cmake python3 ];
24+
25+ cmakeFlags = [
26+ "-DBUILD_SHARED_LIBS=ON" # generate $out/lib/libprotobuf-nanopb.so{.0,}
27+ "-DBUILD_STATIC_LIBS=ON" # generate $out/lib/libprotobuf-nanopb.a
28+ "-Dnanopb_PROTOC_PATH=${protobuf}/bin/protoc"
29+ ];
30+
31+ # On a case-insensitive filesystem (such as on Darwin), CMake fails to create
32+ # the build directory because of the existence of the BUILD file.
33+ # TODO: This can be removed once https://github.com/nanopb/nanopb/pull/537 is merged.
34+ preConfigure = "rm BUILD";
35+
36+ # install the generator which requires Python3 with the protobuf package. It
37+ # also requires the nanopb module that's generated by CMake to be in a
38+ # relative location to the generator itself so we move it out of the
39+ # python.sitePackages into the shared generator folder.
40+ postInstall = ''
41+ mkdir -p $out/share/nanopb/generator/proto
42+ cp ../generator/nanopb_generator.py $out/share/nanopb/generator/nanopb_generator.py
43+ cp ../generator/proto/_utils.py $out/share/nanopb/generator/proto/_utils.py
44+ cp ../generator/proto/nanopb.proto $out/share/nanopb/generator/proto/nanopb.proto
45+ mv $out/${python3.sitePackages}/nanopb_pb2.py $out/share/nanopb/generator/proto
46+ rm -rf $out/${python3.sitePackages}
47+
48+ mkdir $out/bin
49+ substitute ${./protoc-gen-nanopb} $out/bin/protoc-gen-nanopb \
50+ --subst-var-by python ${pythonRuntime}/bin/python \
51+ --subst-var-by out $out
52+ chmod +x $out/bin/protoc-gen-nanopb
53+ '';
54+
55+ passthru.tests = {
56+ simple-proto2 = callPackage ./test-simple-proto2 {};
57+ simple-proto3 = callPackage ./test-simple-proto3 {};
58+ message-with-annotations = callPackage ./test-message-with-annotations {};
59+ message-with-options = callPackage ./test-message-with-options {};
60+ };
61+
62+ meta = with lib; {
63+ inherit (protobuf.meta) platforms;
64+
65+ description = "Protocol Buffers with small code size";
66+ homepage = "https://jpa.kapsi.fi/nanopb/";
67+ license = licenses.zlib;
68+ maintainers = with maintainers; [ kalbasit ];
69+
70+ longDescription = ''
71+ Nanopb is a small code-size Protocol Buffers implementation in ansi C. It
72+ is especially suitable for use in microcontrollers, but fits any memory
73+ restricted system.
74+
75+ - Homepage: jpa.kapsi.fi/nanopb
76+ - Documentation: jpa.kapsi.fi/nanopb/docs
77+ - Downloads: jpa.kapsi.fi/nanopb/download
78+ - Forum: groups.google.com/forum/#!forum/nanopb
79+
80+ In order to use the nanopb options in your proto files, you'll need to
81+ tell protoc where to find the nanopb.proto file.
82+ You can do so with the --proto_path (-I) option to add the directory
83+ ''${nanopb}/share/nanopb/generator/proto like so:
84+
85+ protoc --proto_path=. --proto_path=''${nanopb}/share/nanopb/generator/proto --plugin=protoc-gen-nanopb=''${nanopb}/bin/protoc-gen-nanopb --nanopb_out=out file.proto
86+ '';
87+ };
88+}
pkgs/development/libraries/nanopb/protoc-gen-nanopbnew file+3
@@ -0,0 +1,3 @@
1+#!/usr/bin/env bash
2+
3+exec @python@ @out@/share/nanopb/generator/nanopb_generator.py --protoc-plugin
pkgs/development/libraries/nanopb/test-message-with-annotations/default.nixnew file+27
@@ -0,0 +1,27 @@
1+{ stdenv, protobuf, nanopb }:
2+
3+stdenv.mkDerivation {
4+ name = "nanopb-test-message-with-annotations";
5+ meta.timeout = 60;
6+ src = ./.;
7+
8+ # protoc requires any .proto file to be compiled to reside within it's
9+ # proto_path. By default the current directory is automatically added to the
10+ # proto_path. I tried using --proto_path ${./.} ${./simple.proto} and it did
11+ # not work because they end up in the store at different locations.
12+ installPhase = ":";
13+ buildPhase = ''
14+ mkdir $out
15+
16+ ${protobuf}/bin/protoc --proto_path=. --proto_path=${nanopb}/share/nanopb/generator/proto --plugin=protoc-gen-nanopb=${nanopb}/bin/protoc-gen-nanopb --nanopb_out=$out withannotations.proto
17+ '';
18+
19+ docheck = true;
20+ checkphase = ''
21+ grep -q WithAnnotations $out/withannotations.pb.c || (echo "error: WithAnnotations not found in $out/withannotations.pb.c"; exit 1)
22+ grep -q WithAnnotations $out/withannotations.pb.h || (echo "error: WithAnnotations not found in $out/withannotations.pb.h"; exit 1)
23+ grep -q "pb_byte_t uuid\[16\]" $out/withannotations.pb.h || (echo "error: uuid is not of type pb_byte_t and of size 16 in $out/withannotations.pb.h"; exit 1)
24+ grep -q "FIXED_LENGTH_BYTES, uuid" $out/withannotations.pb.h || (echo "error: uuid is not of fixed lenght bytes in $out/withannotations.pb.h"; exit 1)
25+ grep -q "#define WithAnnotations_size" $out/withannotations.pb.h || (echo "error: the size of WithAnnotations is not known in $out/withannotations.pb.h"; exit 1)
26+ '';
27+}
pkgs/development/libraries/nanopb/test-message-with-annotations/withannotations.protonew file+7
@@ -0,0 +1,7 @@
1+syntax = "proto3";
2+
3+import "nanopb.proto";
4+
5+message WithAnnotations {
6+ bytes uuid = 1 [(nanopb).max_size = 16, (nanopb).fixed_length = true];
7+}
pkgs/development/libraries/nanopb/test-message-with-options/default.nixnew file+27
@@ -0,0 +1,27 @@
1+{ stdenv, protobuf, nanopb }:
2+
3+stdenv.mkDerivation {
4+ name = "nanopb-test-message-with-options";
5+ meta.timeout = 60;
6+ src = ./.;
7+
8+ # protoc requires any .proto file to be compiled to reside within it's
9+ # proto_path. By default the current directory is automatically added to the
10+ # proto_path. I tried using --proto_path ${./.} ${./simple.proto} and it did
11+ # not work because they end up in the store at different locations.
12+ installPhase = ":";
13+ buildPhase = ''
14+ mkdir $out
15+
16+ ${protobuf}/bin/protoc --plugin=protoc-gen-nanopb=${nanopb}/bin/protoc-gen-nanopb --nanopb_out=$out withoptions.proto
17+ '';
18+
19+ docheck = true;
20+ checkphase = ''
21+ grep -q WithOptions $out/withoptions.pb.c || (echo "error: WithOptions not found in $out/withoptions.pb.c"; exit 1)
22+ grep -q WithOptions $out/withoptions.pb.h || (echo "error: WithOptions not found in $out/withoptions.pb.h"; exit 1)
23+ grep -q "pb_byte_t uuid\[16\]" $out/withoptions.pb.h || (echo "error: uuid is not of type pb_byte_t and of size 16 in $out/withoptions.pb.h"; exit 1)
24+ grep -q "FIXED_LENGTH_BYTES, uuid" $out/withoptions.pb.h || (echo "error: uuid is not of fixed lenght bytes in $out/withoptions.pb.h"; exit 1)
25+ grep -q "#define WithOptions_size" $out/withoptions.pb.h || (echo "error: the size of WithOptions is not known in $out/withoptions.pb.h"; exit 1)
26+ '';
27+}
pkgs/development/libraries/nanopb/test-message-with-options/withoptions.optionsnew file+1
@@ -0,0 +1 @@
1+ WithOptions.uuid max_size:16 fixed_length:true
pkgs/development/libraries/nanopb/test-message-with-options/withoptions.protonew file+5
@@ -0,0 +1,5 @@
1+syntax = "proto3";
2+
3+message WithOptions {
4+ bytes uuid = 1;
5+}
pkgs/development/libraries/nanopb/test-simple-proto2/default.nixnew file+24
@@ -0,0 +1,24 @@
1+{ stdenv, protobuf, nanopb }:
2+
3+stdenv.mkDerivation {
4+ name = "nanopb-test-simple-proto2";
5+ meta.timeout = 60;
6+ src = ./.;
7+
8+ # protoc requires any .proto file to be compiled to reside within it's
9+ # proto_path. By default the current directory is automatically added to the
10+ # proto_path. I tried using --proto_path ${./.} ${./simple.proto} and it did
11+ # not work because they end up in the store at different locations.
12+ installPhase = ":";
13+ buildPhase = ''
14+ mkdir $out
15+
16+ ${protobuf}/bin/protoc --plugin=protoc-gen-nanopb=${nanopb}/bin/protoc-gen-nanopb --nanopb_out=$out simple.proto
17+ '';
18+
19+ doCheck = true;
20+ checkPhase = ''
21+ grep -q SimpleMessage $out/simple.pb.c || (echo "ERROR: SimpleMessage not found in $out/simple.pb.c"; exit 1)
22+ grep -q SimpleMessage $out/simple.pb.h || (echo "ERROR: SimpleMessage not found in $out/simple.pb.h"; exit 1)
23+ '';
24+}
pkgs/development/libraries/nanopb/test-simple-proto2/simple.protonew file+5
@@ -0,0 +1,5 @@
1+syntax = "proto2";
2+
3+message SimpleMessage {
4+ required int32 lucky_number = 1;
5+}
pkgs/development/libraries/nanopb/test-simple-proto3/default.nixnew file+24
@@ -0,0 +1,24 @@
1+{ stdenv, protobuf, nanopb }:
2+
3+stdenv.mkDerivation {
4+ name = "nanopb-test-simple-proto3";
5+ meta.timeout = 60;
6+ src = ./.;
7+
8+ # protoc requires any .proto file to be compiled to reside within it's
9+ # proto_path. By default the current directory is automatically added to the
10+ # proto_path. I tried using --proto_path ${./.} ${./simple.proto} and it did
11+ # not work because they end up in the store at different locations.
12+ installPhase = ":";
13+ buildPhase = ''
14+ mkdir $out
15+
16+ ${protobuf}/bin/protoc --plugin=protoc-gen-nanopb=${nanopb}/bin/protoc-gen-nanopb --nanopb_out=$out simple.proto
17+ '';
18+
19+ doCheck = true;
20+ checkPhase = ''
21+ grep -q SimpleMessage $out/simple.pb.c || (echo "ERROR: SimpleMessage not found in $out/simple.pb.c"; exit 1)
22+ grep -q SimpleMessage $out/simple.pb.h || (echo "ERROR: SimpleMessage not found in $out/simple.pb.h"; exit 1)
23+ '';
24+}
pkgs/development/libraries/nanopb/test-simple-proto3/simple.protonew file+5
@@ -0,0 +1,5 @@
1+syntax = "proto3";
2+
3+message SimpleMessage {
4+ int32 lucky_number = 1;
5+}
pkgs/top-level/all-packages.nix+2
@@ -14213,6 +14213,8 @@ in
1421314213
1421414214 flatbuffers = callPackage ../development/libraries/flatbuffers { };
1421514215
14216+ nanopb = callPackage ../development/libraries/nanopb { };
14217+
1421614218 gnupth = callPackage ../development/libraries/pth { };
1421714219 pth = if stdenv.hostPlatform.isMusl then npth else gnupth;
1421814220