mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-12-16 02:33:25 +00:00
e36b4564d2
This commit: - Bumps the nanopb version - Adds all runtime configuration options - Implements proper cross-compilation support which is the main use-case of the library. - Uses newer `finalAttrs` form of `mkDerivation` to allow for easier attribute overrides. The cross-compilation support is achieved by splitting the package into two sub-packages consisting of the build-time generator and the runtime library. Nanopb explicitely supports this by providing specialized `GENERATOR` and `RUNTIME` CMake configuration options. The top-level package uses `propagatedNativeBuildInputs` and `propagatedBuildInputs` to propagate the sub-packages and also adds convenient symlinks to make certain use cases easier. == GENERATOR == The generator is a mostly ready-to-be-packaged python module tree. We patch the library to also include the missing `__init__.py` and we also fix the `PYTHON_INSTDIR` variable to follow best practice and to prevent the library from attempting to install to a global directory. We package the python module using `buildPythonPackage` and internally override python in order to wrap the `nanopb_generator.py` executable. We do *not* wrap `nanob_generator.py` due to it also being imported directly from python when used through `protoc-gen-nanopb`. == RUNTIME == The runtime is a simple library that consists of the common functionality among generated headers/sources. It is configured through `preprocessor definitions` and consumer projects *must* be compiled with the same definitions. This is currently achieved by exposing all configuration options through the top-level overrides and patching the CMakeLists.txt so that the definitions are added to the to-be-installed CMake targets as PUBLIC properties.
60 lines
1.2 KiB
Nix
60 lines
1.2 KiB
Nix
{ 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
|
|
'';
|
|
}
|