summary refs log tree commit diff
path: root/pkgs/development/libraries/protobuf
diff options
context:
space:
mode:
authorJonathan Ringer <jonringer117@gmail.com>2022-04-20 16:04:10 -0700
committerJonathan Ringer <jonringer@users.noreply.github.com>2022-07-17 23:25:30 -0700
commit5c38e6b3d27fa613087a2245e82f07ccd1f8c8a3 (patch)
tree42ad4532d64f5dd8ceaf8aeb53214312b837d90b /pkgs/development/libraries/protobuf
parent2c184fc2002a9765e4f4e6e86402b8cb550156c0 (diff)
downloadnixpkgs-5c38e6b3d27fa613087a2245e82f07ccd1f8c8a3.tar
nixpkgs-5c38e6b3d27fa613087a2245e82f07ccd1f8c8a3.tar.gz
nixpkgs-5c38e6b3d27fa613087a2245e82f07ccd1f8c8a3.tar.bz2
nixpkgs-5c38e6b3d27fa613087a2245e82f07ccd1f8c8a3.tar.lz
nixpkgs-5c38e6b3d27fa613087a2245e82f07ccd1f8c8a3.tar.xz
nixpkgs-5c38e6b3d27fa613087a2245e82f07ccd1f8c8a3.tar.zst
nixpkgs-5c38e6b3d27fa613087a2245e82f07ccd1f8c8a3.zip
protobuf: add cmake generic builder
Diffstat (limited to 'pkgs/development/libraries/protobuf')
-rw-r--r--pkgs/development/libraries/protobuf/generic-v3-cmake.nix107
1 files changed, 107 insertions, 0 deletions
diff --git a/pkgs/development/libraries/protobuf/generic-v3-cmake.nix b/pkgs/development/libraries/protobuf/generic-v3-cmake.nix
new file mode 100644
index 00000000000..0b6967a6738
--- /dev/null
+++ b/pkgs/development/libraries/protobuf/generic-v3-cmake.nix
@@ -0,0 +1,107 @@
+# The cmake version of this build is meant to enable both cmake and .pc being exported
+# this is important because grpc exports a .cmake file which also expects for protobuf
+# to have been exported through cmake as well.
+{ lib
+, stdenv
+, abseil-cpp
+, buildPackages
+, cmake
+, fetchFromGitHub
+, fetchpatch
+, gtest
+, zlib
+, version
+, sha256
+
+# downstream dependencies
+, python3
+
+, ...
+}:
+
+let
+  self = stdenv.mkDerivation {
+    pname = "protobuf";
+    inherit version;
+
+    src = fetchFromGitHub {
+      owner = "protocolbuffers";
+      repo = "protobuf";
+      rev = "v${version}";
+      inherit sha256;
+    };
+
+    # re-create submodule logic
+    postPatch = ''
+      rm -rf gmock
+      cp -r ${gtest.src}/googlemock third_party/gmock
+      cp -r ${gtest.src}/googletest third_party/
+      chmod -R a+w third_party/
+
+      ln -s ../googletest third_party/gmock/gtest
+      ln -s ../gmock third_party/googletest/googlemock
+      ln -s $(pwd)/third_party/googletest third_party/googletest/googletest
+    '' + lib.optionalString stdenv.isDarwin ''
+      substituteInPlace src/google/protobuf/testing/googletest.cc \
+        --replace 'tmpnam(b)' '"'$TMPDIR'/foo"'
+    '';
+
+    patches = lib.optionals (lib.versionOlder version "3.22") [
+      # fix protobuf-targets.cmake installation paths, and allow for CMAKE_INSTALL_LIBDIR to be absolute
+      # https://github.com/protocolbuffers/protobuf/pull/10090
+      (fetchpatch {
+        url = "https://github.com/protocolbuffers/protobuf/commit/a7324f88e92bc16b57f3683403b6c993bf68070b.patch";
+        sha256 = "sha256-SmwaUjOjjZulg/wgNmR/F5b8rhYA2wkKAjHIOxjcQdQ=";
+      })
+    ];
+
+    nativeBuildInputs = let
+      protobufVersion = "${lib.versions.major version}_${lib.versions.minor version}";
+    in [
+      cmake
+    ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
+      # protoc of the same version must be available for build. For non-cross builds, it's able to
+      # re-use the executable generated as part of the build
+      buildPackages."protobuf${protobufVersion}"
+    ];
+
+    buildInputs = [
+      abseil-cpp
+      zlib
+    ];
+
+    # After 3.20, CMakeLists.txt can now be found at the top-level, however
+    # a stub cmake/CMakeLists.txt still exists for compatibility with previous build assumptions
+    cmakeDir = "../cmake";
+    cmakeFlags = [
+      "-Dprotobuf_ABSL_PROVIDER=package"
+      ] ++ lib.optionals (!stdenv.targetPlatform.isStatic) [
+      "-Dprotobuf_BUILD_SHARED_LIBS=ON"
+    ];
+
+    # unfortunately the shared libraries have yet to been patched by nix, thus tests will fail
+    doCheck = false;
+
+    passthru = {
+      tests = {
+        pythonProtobuf = python3.pkgs.protobuf.override(_: {
+          protobuf = self;
+        });
+      };
+    };
+
+    meta = {
+      description = "Google's data interchange format";
+      longDescription = ''
+        Protocol Buffers are a way of encoding structured data in an efficient
+        yet extensible format. Google uses Protocol Buffers for almost all of
+        its internal RPC protocols and file formats.
+      '';
+      license = lib.licenses.bsd3;
+      platforms = lib.platforms.unix;
+      homepage = "https://developers.google.com/protocol-buffers/";
+      maintainers = with lib.maintainers; [ jonringer ];
+    };
+  };
+in
+  self