about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/libraries/nanopb
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/development/libraries/nanopb')
-rw-r--r--nixpkgs/pkgs/development/libraries/nanopb/default.nix74
-rw-r--r--nixpkgs/pkgs/development/libraries/nanopb/test-message-with-annotations/default.nix27
-rw-r--r--nixpkgs/pkgs/development/libraries/nanopb/test-message-with-annotations/withannotations.proto7
-rw-r--r--nixpkgs/pkgs/development/libraries/nanopb/test-message-with-options/default.nix27
-rw-r--r--nixpkgs/pkgs/development/libraries/nanopb/test-message-with-options/withoptions.options1
-rw-r--r--nixpkgs/pkgs/development/libraries/nanopb/test-message-with-options/withoptions.proto5
-rw-r--r--nixpkgs/pkgs/development/libraries/nanopb/test-simple-proto2/default.nix24
-rw-r--r--nixpkgs/pkgs/development/libraries/nanopb/test-simple-proto2/simple.proto5
-rw-r--r--nixpkgs/pkgs/development/libraries/nanopb/test-simple-proto3/default.nix24
-rw-r--r--nixpkgs/pkgs/development/libraries/nanopb/test-simple-proto3/simple.proto5
10 files changed, 199 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/development/libraries/nanopb/default.nix b/nixpkgs/pkgs/development/libraries/nanopb/default.nix
new file mode 100644
index 000000000000..e71d1c6a54c9
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/nanopb/default.nix
@@ -0,0 +1,74 @@
+{ callPackage
+, cmake
+, fetchFromGitHub
+, lib
+, protobuf
+, python3
+, stdenv
+}:
+
+stdenv.mkDerivation rec {
+  pname = "nanopb";
+  version = "0.4.4";
+
+  src = fetchFromGitHub {
+    owner = pname;
+    repo = pname;
+    rev = version;
+    sha256 = "0nqfi1b0szjmm1z8wd3ks64h10jblv9ip01kfggxgz6qjjfwgvq7";
+  };
+
+  nativeBuildInputs = [ cmake python3 python3.pkgs.wrapPython ];
+
+  pythonPath = with python3.pkgs; [ python3.pkgs.protobuf six ];
+
+  cmakeFlags = [
+    "-DBUILD_SHARED_LIBS=ON" # generate $out/lib/libprotobuf-nanopb.so{.0,}
+    "-DBUILD_STATIC_LIBS=ON" # generate $out/lib/libprotobuf-nanopb.a
+    "-Dnanopb_PROTOC_PATH=${protobuf}/bin/protoc"
+  ];
+
+  postInstall = ''
+    mkdir -p $out/share/nanopb/generator/proto
+    cp ../generator/proto/nanopb.proto $out/share/nanopb/generator/proto/nanopb.proto
+    cp ../pb_common.c ../pb_decode.c ../pb_encode.c $out/include/
+  '';
+
+  postFixup = ''
+    wrapPythonPrograms
+  '';
+
+  passthru.tests = {
+    simple-proto2 = callPackage ./test-simple-proto2 {};
+    simple-proto3 = callPackage ./test-simple-proto3 {};
+    message-with-annotations = callPackage ./test-message-with-annotations {};
+    message-with-options = callPackage ./test-message-with-options {};
+  };
+
+  meta = with lib; {
+    inherit (protobuf.meta) platforms;
+
+    description = "Protocol Buffers with small code size";
+    homepage = "https://jpa.kapsi.fi/nanopb/";
+    license = licenses.zlib;
+    maintainers = with maintainers; [ kalbasit ];
+
+    longDescription = ''
+      Nanopb is a small code-size Protocol Buffers implementation in ansi C. It
+      is especially suitable for use in microcontrollers, but fits any memory
+      restricted system.
+
+      - Homepage: jpa.kapsi.fi/nanopb
+      - Documentation: jpa.kapsi.fi/nanopb/docs
+      - Downloads: jpa.kapsi.fi/nanopb/download
+      - Forum: groups.google.com/forum/#!forum/nanopb
+
+      In order to use the nanopb options in your proto files, you'll need to
+      tell protoc where to find the nanopb.proto file.
+      You can do so with the --proto_path (-I) option to add the directory
+      ''${nanopb}/share/nanopb/generator/proto like so:
+
+      protoc --proto_path=. --proto_path=''${nanopb}/share/nanopb/generator/proto --plugin=protoc-gen-nanopb=''${nanopb}/bin/protoc-gen-nanopb --nanopb_out=out file.proto
+    '';
+  };
+}
diff --git a/nixpkgs/pkgs/development/libraries/nanopb/test-message-with-annotations/default.nix b/nixpkgs/pkgs/development/libraries/nanopb/test-message-with-annotations/default.nix
new file mode 100644
index 000000000000..618d7c521ce0
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/nanopb/test-message-with-annotations/default.nix
@@ -0,0 +1,27 @@
+{ stdenv, protobuf, nanopb }:
+
+stdenv.mkDerivation {
+  name = "nanopb-test-message-with-annotations";
+  meta.timeout = 60;
+  src = ./.;
+
+  # protoc requires any .proto file to be compiled to reside within it's
+  # proto_path. By default the current directory is automatically added to the
+  # proto_path. I tried using --proto_path ${./.} ${./simple.proto} and it did
+  # not work because they end up in the store at different locations.
+  installPhase = ":";
+  buildPhase = ''
+    mkdir $out
+
+    ${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
+  '';
+
+  docheck = true;
+  checkphase = ''
+    grep -q WithAnnotations $out/withannotations.pb.c || (echo "error: WithAnnotations not found in $out/withannotations.pb.c"; exit 1)
+    grep -q WithAnnotations $out/withannotations.pb.h || (echo "error: WithAnnotations not found in $out/withannotations.pb.h"; exit 1)
+    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)
+    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)
+    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)
+  '';
+}
diff --git a/nixpkgs/pkgs/development/libraries/nanopb/test-message-with-annotations/withannotations.proto b/nixpkgs/pkgs/development/libraries/nanopb/test-message-with-annotations/withannotations.proto
new file mode 100644
index 000000000000..d8109e877d68
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/nanopb/test-message-with-annotations/withannotations.proto
@@ -0,0 +1,7 @@
+syntax = "proto3";
+
+import "nanopb.proto";
+
+message WithAnnotations {
+  bytes uuid = 1 [(nanopb).max_size = 16, (nanopb).fixed_length = true];
+}
diff --git a/nixpkgs/pkgs/development/libraries/nanopb/test-message-with-options/default.nix b/nixpkgs/pkgs/development/libraries/nanopb/test-message-with-options/default.nix
new file mode 100644
index 000000000000..c15b51f71977
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/nanopb/test-message-with-options/default.nix
@@ -0,0 +1,27 @@
+{ stdenv, protobuf, nanopb }:
+
+stdenv.mkDerivation {
+  name = "nanopb-test-message-with-options";
+  meta.timeout = 60;
+  src = ./.;
+
+  # protoc requires any .proto file to be compiled to reside within it's
+  # proto_path. By default the current directory is automatically added to the
+  # proto_path. I tried using --proto_path ${./.} ${./simple.proto} and it did
+  # not work because they end up in the store at different locations.
+  installPhase = ":";
+  buildPhase = ''
+    mkdir $out
+
+    ${protobuf}/bin/protoc --plugin=protoc-gen-nanopb=${nanopb}/bin/protoc-gen-nanopb --nanopb_out=$out withoptions.proto
+  '';
+
+  docheck = true;
+  checkphase = ''
+    grep -q WithOptions $out/withoptions.pb.c || (echo "error: WithOptions not found in $out/withoptions.pb.c"; exit 1)
+    grep -q WithOptions $out/withoptions.pb.h || (echo "error: WithOptions not found in $out/withoptions.pb.h"; exit 1)
+    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)
+    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)
+    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)
+  '';
+}
diff --git a/nixpkgs/pkgs/development/libraries/nanopb/test-message-with-options/withoptions.options b/nixpkgs/pkgs/development/libraries/nanopb/test-message-with-options/withoptions.options
new file mode 100644
index 000000000000..ecf98a217367
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/nanopb/test-message-with-options/withoptions.options
@@ -0,0 +1 @@
+ WithOptions.uuid max_size:16 fixed_length:true
diff --git a/nixpkgs/pkgs/development/libraries/nanopb/test-message-with-options/withoptions.proto b/nixpkgs/pkgs/development/libraries/nanopb/test-message-with-options/withoptions.proto
new file mode 100644
index 000000000000..5a5da3a1c973
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/nanopb/test-message-with-options/withoptions.proto
@@ -0,0 +1,5 @@
+syntax = "proto3";
+
+message WithOptions {
+  bytes uuid = 1;
+}
diff --git a/nixpkgs/pkgs/development/libraries/nanopb/test-simple-proto2/default.nix b/nixpkgs/pkgs/development/libraries/nanopb/test-simple-proto2/default.nix
new file mode 100644
index 000000000000..a915e7785370
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/nanopb/test-simple-proto2/default.nix
@@ -0,0 +1,24 @@
+{ stdenv, protobuf, nanopb }:
+
+stdenv.mkDerivation {
+  name = "nanopb-test-simple-proto2";
+  meta.timeout = 60;
+  src = ./.;
+
+  # protoc requires any .proto file to be compiled to reside within it's
+  # proto_path. By default the current directory is automatically added to the
+  # proto_path. I tried using --proto_path ${./.} ${./simple.proto} and it did
+  # not work because they end up in the store at different locations.
+  installPhase = ":";
+  buildPhase = ''
+    mkdir $out
+
+    ${protobuf}/bin/protoc --plugin=protoc-gen-nanopb=${nanopb}/bin/protoc-gen-nanopb --nanopb_out=$out simple.proto
+  '';
+
+  doCheck = true;
+  checkPhase = ''
+    grep -q SimpleMessage $out/simple.pb.c || (echo "ERROR: SimpleMessage not found in $out/simple.pb.c"; exit 1)
+    grep -q SimpleMessage $out/simple.pb.h || (echo "ERROR: SimpleMessage not found in $out/simple.pb.h"; exit 1)
+  '';
+}
diff --git a/nixpkgs/pkgs/development/libraries/nanopb/test-simple-proto2/simple.proto b/nixpkgs/pkgs/development/libraries/nanopb/test-simple-proto2/simple.proto
new file mode 100644
index 000000000000..b02936b1ae26
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/nanopb/test-simple-proto2/simple.proto
@@ -0,0 +1,5 @@
+syntax = "proto2";
+
+message SimpleMessage {
+  required int32 lucky_number = 1;
+}
diff --git a/nixpkgs/pkgs/development/libraries/nanopb/test-simple-proto3/default.nix b/nixpkgs/pkgs/development/libraries/nanopb/test-simple-proto3/default.nix
new file mode 100644
index 000000000000..3e2bba731b9f
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/nanopb/test-simple-proto3/default.nix
@@ -0,0 +1,24 @@
+{ stdenv, protobuf, nanopb }:
+
+stdenv.mkDerivation {
+  name = "nanopb-test-simple-proto3";
+  meta.timeout = 60;
+  src = ./.;
+
+  # protoc requires any .proto file to be compiled to reside within it's
+  # proto_path. By default the current directory is automatically added to the
+  # proto_path. I tried using --proto_path ${./.} ${./simple.proto} and it did
+  # not work because they end up in the store at different locations.
+  installPhase = ":";
+  buildPhase = ''
+    mkdir $out
+
+    ${protobuf}/bin/protoc --plugin=protoc-gen-nanopb=${nanopb}/bin/protoc-gen-nanopb --nanopb_out=$out simple.proto
+  '';
+
+  doCheck = true;
+  checkPhase = ''
+    grep -q SimpleMessage $out/simple.pb.c || (echo "ERROR: SimpleMessage not found in $out/simple.pb.c"; exit 1)
+    grep -q SimpleMessage $out/simple.pb.h || (echo "ERROR: SimpleMessage not found in $out/simple.pb.h"; exit 1)
+  '';
+}
diff --git a/nixpkgs/pkgs/development/libraries/nanopb/test-simple-proto3/simple.proto b/nixpkgs/pkgs/development/libraries/nanopb/test-simple-proto3/simple.proto
new file mode 100644
index 000000000000..6b99cdb5daa7
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/nanopb/test-simple-proto3/simple.proto
@@ -0,0 +1,5 @@
+syntax = "proto3";
+
+message SimpleMessage {
+  int32 lucky_number = 1;
+}