From 34ca27bc95261256846ee8d0ebcdf4aeafef907a Mon Sep 17 00:00:00 2001 From: sternenseemann Date: Thu, 7 Oct 2021 21:04:39 +0200 Subject: [PATCH 1/2] grpc: don't set LD_LIBRARY_PATH when cross compiling LD_LIBRARY_PATH is only necessary in the native compilation case when we need to execute grpc_cpp_plugin from the build directory. Disabling this for cross is not only cleaner, but eliminates linker failures when cross compiling to a compatible configuration, since LD_LIBRARY_PATH takes precedence over the rpath set in buildPackages.grpc's grpc_cpp_plugin. --- pkgs/development/libraries/grpc/default.nix | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkgs/development/libraries/grpc/default.nix b/pkgs/development/libraries/grpc/default.nix index 2000bdccb008..0787ffea41fa 100644 --- a/pkgs/development/libraries/grpc/default.nix +++ b/pkgs/development/libraries/grpc/default.nix @@ -68,7 +68,12 @@ stdenv.mkDerivation rec { rm -vf BUILD ''; - preBuild = '' + # When natively compiling, grpc_cpp_plugin is executed from the build directory, + # needing to load dynamic libraries from the build directory, so we set + # LD_LIBRARY_PATH to enable this. When cross compiling we need to avoid this, + # since it can cause the grpc_cpp_plugin executable from buildPackages to + # crash if build and host architecture are compatible (e. g. pkgsLLVM). + preBuild = lib.optionalString (stdenv.hostPlatform == stdenv.buildPlatform) '' export LD_LIBRARY_PATH=$(pwd)''${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH ''; From 8e57c33ab6b284be5053717daba75a18c285cd5b Mon Sep 17 00:00:00 2001 From: sternenseemann Date: Thu, 7 Oct 2021 21:06:56 +0200 Subject: [PATCH 2/2] pkgsLLVM.grpc: fix build with clang < 11 Apparently there's an issue where compiling grpc with -std=c++17 fails unless the clang version is at least 11. Hopefully our default clang version will be increased to that soon, but until then we need to work around this problem by setting an older C++ standard. It's unclear if using C++11 causes further issues, but compiling is better than not compiling, I suppose. Contrary to the linked bug report, the darwin stdenv doesn't exhibit this problem for some reason. --- pkgs/development/libraries/grpc/default.nix | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkgs/development/libraries/grpc/default.nix b/pkgs/development/libraries/grpc/default.nix index 0787ffea41fa..5d2b58aa3dba 100644 --- a/pkgs/development/libraries/grpc/default.nix +++ b/pkgs/development/libraries/grpc/default.nix @@ -57,7 +57,12 @@ stdenv.mkDerivation rec { "-DgRPC_ABSL_PROVIDER=package" "-DBUILD_SHARED_LIBS=ON" "-DCMAKE_SKIP_BUILD_RPATH=OFF" - "-DCMAKE_CXX_STANDARD=17" + # 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 + (if (stdenv.hostPlatform.useLLVM or false) && lib.versionOlder stdenv.cc.cc.version "11.0" + then "-DCMAKE_CXX_STANDARD=11" + else "-DCMAKE_CXX_STANDARD=17") ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ "-D_gRPC_PROTOBUF_PROTOC_EXECUTABLE=${buildPackages.protobuf}/bin/protoc" ];