grpc: refactor cxxStandard selection

GRPC is less aggressive in overriding `CMAKE_CXX_STANDARD` nowadays.
This allows us to take a less invasive approach to ensure that the
provided abseil package is configured with the same implementation
for the provided c++17 compatibility shims.
Instead of always setting `CMAKE_CXX_STANDARD`, we only do it to
override hard-coded downgrade on darwin. With that, we can use the
default configuration for abseil-cpp, reducing the number of instances
of that library in the build closure to one.
This commit is contained in:
Tobias Mayer 2023-08-14 08:57:36 +02:00
parent 69ea1516ca
commit 54e9994a6b
No known key found for this signature in database
GPG Key ID: F8657E90819A1298
4 changed files with 17 additions and 25 deletions

View File

@ -39,11 +39,8 @@
, enableShared ? !stdenv.hostPlatform.isStatic
, enableFlight ? true
, enableJemalloc ? !stdenv.isDarwin
# boost/process is broken in 1.69 on darwin, but fixed in 1.70 and
# non-existent in older versions
# see https://github.com/boostorg/process/issues/55
, enableS3 ? (!stdenv.isDarwin) || (lib.versionOlder boost.version "1.69" || lib.versionAtLeast boost.version "1.70")
, enableGcs ? (!stdenv.isDarwin) && (lib.versionAtLeast grpc.cxxStandard "17") # google-cloud-cpp is not supported on darwin, needs to support C++17
, enableS3 ? true
, enableGcs ? !stdenv.isDarwin
}:
assert lib.asserts.assertMsg

View File

@ -120,7 +120,6 @@ stdenv.mkDerivation rec {
# this adds a good chunk of time to the build
"-DBUILD_TESTING:BOOL=ON"
"-DGOOGLE_CLOUD_CPP_ENABLE_EXAMPLES:BOOL=OFF"
"-DCMAKE_CXX_STANDARD=${grpc.cxxStandard}"
] ++ lib.optionals (apis != [ "*" ]) [
"-DGOOGLE_CLOUD_CPP_ENABLE=${lib.concatStringsSep ";" apis}"
];

View File

@ -56,10 +56,22 @@ stdenv.mkDerivation rec {
"-DgRPC_PROTOBUF_PROVIDER=package"
"-DgRPC_ABSL_PROVIDER=package"
"-DBUILD_SHARED_LIBS=ON"
"-DCMAKE_CXX_STANDARD=${passthru.cxxStandard}"
] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
"-D_gRPC_PROTOBUF_PROTOC_EXECUTABLE=${buildPackages.protobuf}/bin/protoc"
];
]
# The build scaffold defaults to c++14 on darwin, even when the compiler uses
# a more recent c++ version by default [1]. However, downgrades are
# problematic, because the compatibility types in abseil will have different
# interface definitions than the ones used for building abseil itself.
# [1] https://github.com/grpc/grpc/blob/v1.57.0/CMakeLists.txt#L239-L243
++ (let
defaultCxxIsOlderThan17 =
(stdenv.cc.isClang && lib.versionAtLeast stdenv.cc.cc.version "16.0")
|| (stdenv.cc.isGNU && lib.versionAtLeast stdenv.cc.cc.version "11.0");
in lib.optionals (stdenv.hostPlatform.isDarwin && defaultCxxIsOlderThan17)
[
"-DCMAKE_CXX_STANDARD=17"
]);
# CMake creates a build directory by default, this conflicts with the
# basel BUILD file on case-insensitive filesystems.
@ -81,17 +93,6 @@ stdenv.mkDerivation rec {
enableParallelBuilds = true;
passthru.cxxStandard =
let
# Needs to be compiled with -std=c++11 for clang < 11. Interestingly this is
# only an issue with the useLLVM stdenv, not the darwin stdenv…
# https://github.com/grpc/grpc/issues/26473#issuecomment-860885484
useLLVMAndOldCC = (stdenv.hostPlatform.useLLVM or false) && lib.versionOlder stdenv.cc.cc.version "11.0";
# With GCC 9 (current aarch64-linux) it fails with c++17 but OK with c++14.
useOldGCC = !(stdenv.hostPlatform.useLLVM or false) && lib.versionOlder stdenv.cc.cc.version "10";
in
(if useLLVMAndOldCC then "11" else if useOldGCC then "14" else "17");
passthru.tests = {
inherit (python3.pkgs) grpcio-status grpcio-tools;
inherit arrow-cpp;

View File

@ -21597,12 +21597,7 @@ with pkgs;
grilo-plugins = callPackage ../development/libraries/grilo-plugins { };
grpc = callPackage ../development/libraries/grpc {
# grpc builds with c++17 so abseil must also be built that way
abseil-cpp = abseil-cpp_202206.override {
cxxStandard = grpc.cxxStandard;
};
};
grpc = callPackage ../development/libraries/grpc { };
gsettings-qt = libsForQt5.callPackage ../development/libraries/gsettings-qt { };