1 # The cmake version of this build is meant to enable both cmake and .pc being exported
2 # this is important because grpc exports a .cmake file which also expects for protobuf
3 # to have been exported through cmake as well.
18 # downstream dependencies
21 enableShared ? !stdenv.hostPlatform.isStatic,
28 stdenv.mkDerivation (finalAttrs: {
32 src = fetchFromGitHub {
33 owner = "protocolbuffers";
39 postPatch = lib.optionalString stdenv.hostPlatform.isDarwin ''
40 substituteInPlace src/google/protobuf/testing/googletest.cc \
41 --replace 'tmpnam(b)' '"'$TMPDIR'/foo"'
44 patches = lib.optionals (lib.versionOlder version "22") [
45 # fix protobuf-targets.cmake installation paths, and allow for CMAKE_INSTALL_LIBDIR to be absolute
46 # https://github.com/protocolbuffers/protobuf/pull/10090
48 url = "https://github.com/protocolbuffers/protobuf/commit/a7324f88e92bc16b57f3683403b6c993bf68070b.patch";
49 hash = "sha256-SmwaUjOjjZulg/wgNmR/F5b8rhYA2wkKAjHIOxjcQdQ=";
57 ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
58 # protoc of the same version must be available for build. For non-cross builds, it's able to
59 # re-use the executable generated as part of the build
60 buildPackages."protobuf_${lib.versions.major version}"
68 propagatedBuildInputs = [
74 cmakeDir = if lib.versionOlder version "22" then "../cmake" else null;
77 "-Dprotobuf_USE_EXTERNAL_GTEST=ON"
78 "-Dprotobuf_ABSL_PROVIDER=package"
80 ++ lib.optionals enableShared [
81 "-Dprotobuf_BUILD_SHARED_LIBS=ON"
83 ++ lib.optionals (!finalAttrs.finalPackage.doCheck) [
84 "-Dprotobuf_BUILD_TESTS=OFF"
88 # Tests fail to build on 32-bit platforms; fixed in 22.x
89 # https://github.com/protocolbuffers/protobuf/issues/10418
90 # Also AnyTest.TestPackFromSerializationExceedsSizeLimit fails on 32-bit platforms
91 # https://github.com/protocolbuffers/protobuf/issues/8460
92 !stdenv.hostPlatform.is32bit;
94 nativeInstallCheckInputs = [
97 versionCheckProgram = [ "${placeholder "out"}/bin/protoc" ];
98 versionCheckProgramArg = [ "--version" ];
99 doInstallCheck = true;
103 pythonProtobuf = python3.pkgs.protobuf;
105 version = testers.testVersion { package = protobuf; };
112 description = "Google's data interchange format";
114 Protocol Buffers are a way of encoding structured data in an efficient
115 yet extensible format. Google uses Protocol Buffers for almost all of
116 its internal RPC protocols and file formats.
118 license = lib.licenses.bsd3;
119 platforms = lib.platforms.all;
120 homepage = "https://protobuf.dev/";
121 maintainers = with lib.maintainers; [ GaetanLepage ];
122 mainProgram = "protoc";