mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-01-31 09:14:28 +00:00
Merge pull request #288422 from liarokapisv/nanopb_update_and_cross_support
nanopb: 0.4.6 -> 0.4.8, cross-compilation support
This commit is contained in:
commit
c61a59aa2b
@ -11348,6 +11348,12 @@
|
||||
githubId = 1769386;
|
||||
name = "Liam Diprose";
|
||||
};
|
||||
liarokapisv = {
|
||||
email = "liarokapis.v@gmail.com";
|
||||
github = "liarokapisv";
|
||||
githubId = 19633626;
|
||||
name = "Alexandros Liarokapis";
|
||||
};
|
||||
liassica = {
|
||||
email = "git-commit.jingle869@aleeas.com";
|
||||
github = "Liassica";
|
||||
|
59
pkgs/by-name/na/nanopb/generator-out.nix
Normal file
59
pkgs/by-name/na/nanopb/generator-out.nix
Normal file
@ -0,0 +1,59 @@
|
||||
{ stdenv
|
||||
, cmake
|
||||
, python3
|
||||
, writeTextFile
|
||||
, protobuf
|
||||
, src
|
||||
, version
|
||||
}:
|
||||
let
|
||||
pyproject_toml = writeTextFile {
|
||||
name = "pyproject.toml";
|
||||
text = ''
|
||||
[build-system]
|
||||
requires = ["setuptools"]
|
||||
build-backend = "setuptools.build_meta"
|
||||
|
||||
[tool.setuptools]
|
||||
include-package-data = true
|
||||
|
||||
[tool.setuptools.packages.find]
|
||||
where = ["src"]
|
||||
|
||||
[tool.setuptools.package-data]
|
||||
"*" = ["nanopb.proto"]
|
||||
|
||||
[project]
|
||||
name = "nanopb"
|
||||
version = "${version}"
|
||||
dependencies = [
|
||||
"setuptools",
|
||||
"protobuf",
|
||||
"six"
|
||||
]
|
||||
'';
|
||||
};
|
||||
in
|
||||
stdenv.mkDerivation {
|
||||
pname = "nanopb-generator-out";
|
||||
inherit src version;
|
||||
|
||||
nativeBuildInputs = [ cmake protobuf python3 ];
|
||||
|
||||
cmakeFlags = [
|
||||
"-Dnanopb_BUILD_RUNTIME=OFF"
|
||||
"-Dnanopb_BUILD_GENERATOR=ON"
|
||||
"-Dnanopb_PYTHON_INSTDIR_OVERRIDE=$out/lib/python/site-packages"
|
||||
];
|
||||
|
||||
preConfigure = ''
|
||||
cmakeFlags+=" -Dnanopb_PYTHON_INSTDIR_OVERRIDE=$out/lib/python/site-packages"
|
||||
'';
|
||||
|
||||
postInstall = ''
|
||||
rm -rf $out/include
|
||||
rm -rf $out/lib/cmake
|
||||
ln -s $out/lib/python/site-packages $out/src
|
||||
ln -s ${pyproject_toml} $out/pyproject.toml
|
||||
'';
|
||||
}
|
27
pkgs/by-name/na/nanopb/generator.nix
Normal file
27
pkgs/by-name/na/nanopb/generator.nix
Normal file
@ -0,0 +1,27 @@
|
||||
{ python3
|
||||
, stdenvNoCC
|
||||
, protobuf
|
||||
, version
|
||||
, generator-out
|
||||
}:
|
||||
stdenvNoCC.mkDerivation {
|
||||
pname = "nanopb-generator";
|
||||
inherit version;
|
||||
|
||||
dontUnpack = true;
|
||||
|
||||
nativeBuildInputs = [ python3.pkgs.wrapPython ];
|
||||
|
||||
propagatedBuildInputs = [
|
||||
protobuf
|
||||
python3.pkgs.nanopb-proto
|
||||
];
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp ${generator-out}/bin/protoc-gen-nanopb $out/bin/
|
||||
cp ${generator-out}/bin/nanopb_generator $out/bin/
|
||||
wrapPythonPrograms
|
||||
cp ${generator-out}/bin/nanopb_generator.py $out/bin/
|
||||
'';
|
||||
}
|
122
pkgs/by-name/na/nanopb/package.nix
Normal file
122
pkgs/by-name/na/nanopb/package.nix
Normal file
@ -0,0 +1,122 @@
|
||||
{ stdenvNoCC
|
||||
, callPackage
|
||||
, fetchFromGitHub
|
||||
, buildPackages
|
||||
, lib
|
||||
, enableMalloc ? false
|
||||
, noPackedStructs ? false
|
||||
, maxRequiredFields ? null
|
||||
, field32bit ? false
|
||||
, noErrmsg ? false
|
||||
, bufferOnly ? false
|
||||
, systemHeader ? null
|
||||
, without64bit ? false
|
||||
, encodeArraysUnpacked ? false
|
||||
, convertDoubleFloat ? false
|
||||
, validateUtf8 ? false
|
||||
, littleEndian8bit ? false
|
||||
, c99StaticAssert ? false
|
||||
, noStaticAssert ? false
|
||||
}:
|
||||
stdenvNoCC.mkDerivation (self:
|
||||
let
|
||||
generator-out = buildPackages.callPackage ./generator-out.nix { inherit (self) src version; };
|
||||
python-module = buildPackages.callPackage ./python-module.nix {
|
||||
inherit (self) version;
|
||||
inherit (self.passthru) generator-out;
|
||||
};
|
||||
python3 = buildPackages.python3.override {
|
||||
packageOverrides = _: _: {
|
||||
nanopb-proto = self.passthru.python-module;
|
||||
};
|
||||
};
|
||||
generator = buildPackages.callPackage ./generator.nix {
|
||||
inherit python3;
|
||||
inherit (self) version;
|
||||
inherit (self.passthru) generator-out;
|
||||
};
|
||||
runtime = callPackage ./runtime.nix {
|
||||
inherit python3;
|
||||
inherit (self) src version;
|
||||
inherit
|
||||
enableMalloc
|
||||
noPackedStructs
|
||||
maxRequiredFields
|
||||
field32bit
|
||||
noErrmsg
|
||||
bufferOnly
|
||||
systemHeader
|
||||
without64bit
|
||||
encodeArraysUnpacked
|
||||
convertDoubleFloat
|
||||
validateUtf8
|
||||
littleEndian8bit
|
||||
c99StaticAssert
|
||||
noStaticAssert;
|
||||
};
|
||||
in
|
||||
{
|
||||
pname = "nanopb";
|
||||
version = "0.4.8";
|
||||
|
||||
src = fetchFromGitHub {
|
||||
owner = "nanopb";
|
||||
repo = "nanopb";
|
||||
rev = self.version;
|
||||
hash = "sha256-LfARVItT+7dczg2u08RlXZLrLR7ScvC44tgmcy/Zv48=";
|
||||
};
|
||||
|
||||
dontPatch = true;
|
||||
dontUnpack = true;
|
||||
|
||||
propagatedNativeBuildInputs = [ generator ];
|
||||
|
||||
propagatedBuildInputs = [ runtime ];
|
||||
|
||||
postInstall = ''
|
||||
mkdir $out
|
||||
ln -s ${generator}/bin $out/bin
|
||||
ln -s ${runtime}/include $out/include
|
||||
ln -s ${runtime}/lib $out/lib
|
||||
mkdir -p $out/share/nanopb/generator/proto
|
||||
ln -s ${self.src}/generator/proto/nanopb.proto $out/share/nanopb/generator/proto/nanopb.proto
|
||||
'';
|
||||
|
||||
passthru = {
|
||||
inherit runtime generator-out python-module generator;
|
||||
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; {
|
||||
platforms = platforms.all;
|
||||
|
||||
description = "Protocol Buffers with small code size";
|
||||
homepage = "https://jpa.kapsi.fi/nanopb/";
|
||||
license = licenses.zlib;
|
||||
maintainers = with maintainers; [ kalbasit liarokapisv ];
|
||||
|
||||
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
|
||||
'';
|
||||
};
|
||||
})
|
||||
|
16
pkgs/by-name/na/nanopb/python-module.nix
Normal file
16
pkgs/by-name/na/nanopb/python-module.nix
Normal file
@ -0,0 +1,16 @@
|
||||
{ python3
|
||||
, version
|
||||
, generator-out
|
||||
}:
|
||||
python3.pkgs.buildPythonPackage {
|
||||
pname = "nanopb-python-module";
|
||||
inherit version;
|
||||
src = generator-out;
|
||||
pyproject = true;
|
||||
pythonImportsCheck = [ "nanopb" ];
|
||||
propagatedBuildInputs = with python3.pkgs; [
|
||||
setuptools
|
||||
protobuf
|
||||
six
|
||||
];
|
||||
}
|
69
pkgs/by-name/na/nanopb/runtime.nix
Normal file
69
pkgs/by-name/na/nanopb/runtime.nix
Normal file
@ -0,0 +1,69 @@
|
||||
{ cmake
|
||||
, lib
|
||||
, stdenv
|
||||
, protobuf
|
||||
, python3
|
||||
, src
|
||||
, version
|
||||
, enableMalloc
|
||||
, noPackedStructs
|
||||
, maxRequiredFields
|
||||
, field32bit
|
||||
, noErrmsg
|
||||
, bufferOnly
|
||||
, systemHeader
|
||||
, without64bit
|
||||
, encodeArraysUnpacked
|
||||
, convertDoubleFloat
|
||||
, validateUtf8
|
||||
, littleEndian8bit
|
||||
, c99StaticAssert
|
||||
, noStaticAssert
|
||||
}:
|
||||
|
||||
stdenv.mkDerivation
|
||||
({
|
||||
pname = "nanopb-runtime";
|
||||
inherit src version;
|
||||
|
||||
nativeBuildInputs = [ cmake protobuf python3 ];
|
||||
|
||||
patchPhase =
|
||||
let
|
||||
compile_definitions = target: ''
|
||||
target_compile_definitions(${target}
|
||||
PUBLIC
|
||||
${lib.concatStringsSep "\n\t" (map (x: "PB_${x.flag}")
|
||||
(builtins.filter (x: x.cond) [
|
||||
{ cond = enableMalloc; flag = "ENABLE_MALLOC=1"; }
|
||||
{ cond = noPackedStructs; flag = "NO_PACKED_STRUCTS=1"; }
|
||||
{ cond = maxRequiredFields != null; flag = "MAX_REQUIRED_FIELDS=${maxRequiredFields}"; }
|
||||
{ cond = field32bit; flag = "FIELD_32BIT=1"; }
|
||||
{ cond = noErrmsg; flag = "NO_ERRMSG=1"; }
|
||||
{ cond = bufferOnly; flag = "BUFFER_ONLY=1"; }
|
||||
{ cond = systemHeader != null; flag = "SYSTEM_HEADER=${systemHeader}"; }
|
||||
{ cond = without64bit; flag = "WITHOUT_64BIT=1"; }
|
||||
{ cond = encodeArraysUnpacked; flag = "ENCODE_ARRAYS_UNPACKED=1"; }
|
||||
{ cond = convertDoubleFloat; flag = "CONVERT_DOUBLE_FLOAT=1"; }
|
||||
{ cond = validateUtf8; flag = "VALIDATE_UTF8=1"; }
|
||||
{ cond = littleEndian8bit; flag = "LITTLE_ENDIAN_8BIT=1"; }
|
||||
{ cond = c99StaticAssert; flag = "C99_STATIC_ASSERT=1"; }
|
||||
{ cond = noStaticAssert; flag = "NO_STATIC_ASSERT=1"; }
|
||||
]))}
|
||||
)
|
||||
'';
|
||||
in
|
||||
''
|
||||
cat << EOF >> CMakeLists.txt
|
||||
${compile_definitions "protobuf-nanopb"}
|
||||
${compile_definitions "protobuf-nanopb-static"}
|
||||
EOF
|
||||
'';
|
||||
|
||||
cmakeFlags = [
|
||||
"-DBUILD_SHARED_LIBS=ON"
|
||||
"-DBUILD_STATIC_LIBS=ON"
|
||||
"-Dnanopb_BUILD_GENERATOR=OFF"
|
||||
"-Dnanopb_BUILD_RUNTIME=ON"
|
||||
];
|
||||
})
|
@ -1,4 +1,4 @@
|
||||
{ lib, stdenv, protobuf, nanopb }:
|
||||
{ lib, stdenv, nanopb }:
|
||||
|
||||
stdenv.mkDerivation {
|
||||
name = "nanopb-test-message-with-annotations";
|
||||
@ -8,6 +8,8 @@ stdenv.mkDerivation {
|
||||
fileset = lib.fileset.unions [ ./withannotations.proto ];
|
||||
};
|
||||
|
||||
buildInputs = [ nanopb ];
|
||||
|
||||
# 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
|
||||
@ -16,7 +18,7 @@ stdenv.mkDerivation {
|
||||
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
|
||||
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;
|
@ -1,4 +1,4 @@
|
||||
{ lib, stdenv, protobuf, nanopb }:
|
||||
{ lib, stdenv, nanopb }:
|
||||
|
||||
stdenv.mkDerivation {
|
||||
name = "nanopb-test-message-with-options";
|
||||
@ -11,6 +11,8 @@ stdenv.mkDerivation {
|
||||
];
|
||||
};
|
||||
|
||||
buildInputs = [ nanopb ];
|
||||
|
||||
# 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
|
||||
@ -19,7 +21,7 @@ stdenv.mkDerivation {
|
||||
buildPhase = ''
|
||||
mkdir $out
|
||||
|
||||
${protobuf}/bin/protoc --plugin=protoc-gen-nanopb=${nanopb}/bin/protoc-gen-nanopb --nanopb_out=$out withoptions.proto
|
||||
protoc --plugin=protoc-gen-nanopb=${nanopb}/bin/protoc-gen-nanopb --nanopb_out=$out withoptions.proto
|
||||
'';
|
||||
|
||||
doCheck = true;
|
@ -1,4 +1,4 @@
|
||||
{ lib, stdenv, protobuf, nanopb }:
|
||||
{ lib, stdenv, nanopb }:
|
||||
|
||||
stdenv.mkDerivation {
|
||||
name = "nanopb-test-simple-proto2";
|
||||
@ -8,6 +8,8 @@ stdenv.mkDerivation {
|
||||
fileset = lib.fileset.unions [ ./simple.proto ];
|
||||
};
|
||||
|
||||
buildInputs = [ nanopb ];
|
||||
|
||||
# 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
|
||||
@ -16,7 +18,7 @@ stdenv.mkDerivation {
|
||||
buildPhase = ''
|
||||
mkdir $out
|
||||
|
||||
${protobuf}/bin/protoc --plugin=protoc-gen-nanopb=${nanopb}/bin/protoc-gen-nanopb --nanopb_out=$out simple.proto
|
||||
protoc --plugin=protoc-gen-nanopb=${nanopb}/bin/protoc-gen-nanopb --nanopb_out=$out simple.proto
|
||||
'';
|
||||
|
||||
doCheck = true;
|
@ -1,4 +1,4 @@
|
||||
{ lib, stdenv, protobuf, nanopb }:
|
||||
{ lib, stdenv, nanopb }:
|
||||
|
||||
stdenv.mkDerivation {
|
||||
name = "nanopb-test-simple-proto3";
|
||||
@ -7,6 +7,9 @@ stdenv.mkDerivation {
|
||||
root = ./.;
|
||||
fileset = lib.fileset.unions [ ./simple.proto ];
|
||||
};
|
||||
|
||||
buildInputs = [ nanopb ];
|
||||
|
||||
# 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
|
||||
@ -15,7 +18,7 @@ stdenv.mkDerivation {
|
||||
buildPhase = ''
|
||||
mkdir $out
|
||||
|
||||
${protobuf}/bin/protoc --plugin=protoc-gen-nanopb=${nanopb}/bin/protoc-gen-nanopb --nanopb_out=$out simple.proto
|
||||
protoc --plugin=protoc-gen-nanopb=${nanopb}/bin/protoc-gen-nanopb --nanopb_out=$out simple.proto
|
||||
'';
|
||||
|
||||
doCheck = true;
|
@ -1,76 +0,0 @@
|
||||
{ callPackage
|
||||
, cmake
|
||||
, fetchFromGitHub
|
||||
, lib
|
||||
, protobuf
|
||||
, python3
|
||||
, stdenv
|
||||
, buildPackages
|
||||
, mallocBuild ? false
|
||||
}:
|
||||
|
||||
stdenv.mkDerivation rec {
|
||||
pname = "nanopb";
|
||||
version = "0.4.6";
|
||||
|
||||
src = fetchFromGitHub {
|
||||
owner = pname;
|
||||
repo = pname;
|
||||
rev = version;
|
||||
sha256 = "sha256-B9J+GkgOBR4iZaP6/2ykcjbkifoyhkuukkjK/CLBZj0=";
|
||||
};
|
||||
|
||||
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=${buildPackages.protobuf}/bin/protoc"
|
||||
] ++ lib.optional mallocBuild "-DCMAKE_C_FLAGS=-DPB_ENABLE_MALLOC 1";
|
||||
|
||||
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
|
||||
'';
|
||||
};
|
||||
}
|
@ -23754,8 +23754,7 @@ with pkgs;
|
||||
|
||||
flatbuffers = callPackage ../development/libraries/flatbuffers { };
|
||||
|
||||
nanopb = callPackage ../development/libraries/nanopb { };
|
||||
nanopbMalloc = callPackage ../development/libraries/nanopb { mallocBuild = true; };
|
||||
nanopbMalloc = callPackage ../by-name/na/nanopb/package.nix { enableMalloc = true; };
|
||||
|
||||
gnupth = callPackage ../development/libraries/pth { };
|
||||
pth = if stdenv.hostPlatform.isMusl then npth else gnupth;
|
||||
|
Loading…
Reference in New Issue
Block a user