summary refs log tree commit diff
path: root/pkgs/development/libraries/nanopb
diff options
context:
space:
mode:
authorWael Nasreddine <wael.nasreddine@gmail.com>2020-06-05 13:29:26 -0700
committerWael Nasreddine <wael@keeptruckin.com>2020-06-05 13:33:21 -0700
commit47361447f89a1abd36365ea8da7822eeb8b58d3c (patch)
tree4b9efb2b494684e2c353bfd80837fb32955dcecc /pkgs/development/libraries/nanopb
parentd952565ab6cd5e8133fd92566eb66a5d79294d33 (diff)
downloadnixpkgs-47361447f89a1abd36365ea8da7822eeb8b58d3c.tar
nixpkgs-47361447f89a1abd36365ea8da7822eeb8b58d3c.tar.gz
nixpkgs-47361447f89a1abd36365ea8da7822eeb8b58d3c.tar.bz2
nixpkgs-47361447f89a1abd36365ea8da7822eeb8b58d3c.tar.lz
nixpkgs-47361447f89a1abd36365ea8da7822eeb8b58d3c.tar.xz
nixpkgs-47361447f89a1abd36365ea8da7822eeb8b58d3c.tar.zst
nixpkgs-47361447f89a1abd36365ea8da7822eeb8b58d3c.zip
nanopb: init at 0.4.1
Diffstat (limited to 'pkgs/development/libraries/nanopb')
-rw-r--r--pkgs/development/libraries/nanopb/default.nix81
-rw-r--r--pkgs/development/libraries/nanopb/protoc-gen-nanopb3
2 files changed, 84 insertions, 0 deletions
diff --git a/pkgs/development/libraries/nanopb/default.nix b/pkgs/development/libraries/nanopb/default.nix
new file mode 100644
index 00000000000..92d56386f0f
--- /dev/null
+++ b/pkgs/development/libraries/nanopb/default.nix
@@ -0,0 +1,81 @@
+{ callPackage
+, cmake
+, fetchFromGitHub
+, lib
+, protobuf
+, python3
+, stdenv
+}:
+
+let
+  pythonRuntime = python3.withPackages(ps: [ ps.protobuf ]);
+in stdenv.mkDerivation rec {
+  pname = "nanopb";
+  version = "0.4.1";
+
+  src = fetchFromGitHub {
+    owner = pname;
+    repo = pname;
+    rev = version;
+    sha256 = "16zxk42wzn519bpxf4578qn97k0h1cnbkvqqkqvka9sl0n3lz2dp";
+  };
+
+  nativeBuildInputs = [ cmake python3 ];
+
+  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"
+  ];
+
+  # On a case-insensitive filesystem (such as on Darwin), CMake fails to create
+  # the build directory because of the existence of the BUILD file.
+  # TODO: This can be removed once https://github.com/nanopb/nanopb/pull/537 is merged.
+  preConfigure = "rm BUILD";
+
+  # install the generator which requires Python3 with the protobuf package. It
+  # also requires the nanopb module that's generated by CMake to be in a
+  # relative location to the generator itself so we move it out of the
+  # python.sitePackages into the shared generator folder.
+  postInstall = ''
+    mkdir -p $out/share/nanopb/generator/proto
+    cp ../generator/nanopb_generator.py $out/share/nanopb/generator/nanopb_generator.py
+    cp ../generator/proto/_utils.py $out/share/nanopb/generator/proto/_utils.py
+    cp ../generator/proto/nanopb.proto $out/share/nanopb/generator/proto/nanopb.proto
+    mv $out/${python3.sitePackages}/nanopb_pb2.py $out/share/nanopb/generator/proto
+    rm -rf $out/${python3.sitePackages}
+
+    mkdir $out/bin
+    substitute ${./protoc-gen-nanopb} $out/bin/protoc-gen-nanopb \
+      --subst-var-by python ${pythonRuntime}/bin/python \
+      --subst-var-by out $out
+    chmod +x $out/bin/protoc-gen-nanopb
+  '';
+
+  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/pkgs/development/libraries/nanopb/protoc-gen-nanopb b/pkgs/development/libraries/nanopb/protoc-gen-nanopb
new file mode 100644
index 00000000000..764e6614b18
--- /dev/null
+++ b/pkgs/development/libraries/nanopb/protoc-gen-nanopb
@@ -0,0 +1,3 @@
+#!/usr/bin/env bash
+
+exec @python@ @out@/share/nanopb/generator/nanopb_generator.py --protoc-plugin