homebrew-core/Formula/grpc.rb

118 lines
3.9 KiB
Ruby

class Grpc < Formula
desc "Next generation open source RPC library and framework"
homepage "https://grpc.io/"
url "https://github.com/grpc/grpc.git",
tag: "v1.43.0",
revision: "b0f37a22bbae12a4b225a88be6d18d5e41dce881"
license "Apache-2.0"
revision 2
head "https://github.com/grpc/grpc.git", branch: "master"
livecheck do
url :stable
strategy :github_latest
end
bottle do
sha256 cellar: :any, arm64_monterey: "1fdc820ef00649291bfacb6a378f0ed47892a12d18d6246b29b2196b9cf366c9"
sha256 cellar: :any, arm64_big_sur: "3c7be53b01337009d0f08f4a641d7f5d9f58d33b95c6060137d397ef5592858b"
sha256 cellar: :any, monterey: "d357572a81c2f946141c96f9fe711ddaf7be0c04df0bdca14c6ca3bba7a0445e"
sha256 cellar: :any, big_sur: "491cae15482bb2efc6aa67476fbeb15dc427a256745613e1a9a455e204f73d91"
sha256 cellar: :any, catalina: "d09af57c107eb9468d56f65a6b6b073b2f2104f6a76ecef5bd352cc5083aa9a6"
sha256 cellar: :any_skip_relocation, x86_64_linux: "e07deba0c44980f2a762d6522f28f1ef84338ccf0ed5adaf6cf4b07facec1613"
end
depends_on "autoconf" => :build
depends_on "automake" => :build
depends_on "cmake" => :build
depends_on "libtool" => :build
depends_on "pkg-config" => :test
depends_on "abseil"
depends_on "c-ares"
depends_on "openssl@1.1"
depends_on "protobuf"
depends_on "re2"
uses_from_macos "zlib"
on_macos do
# This shouldn't be needed for `:test`, but there's a bug in `brew`:
# CompilerSelectionError: pdnsrec cannot be built with any available compilers.
depends_on "llvm" => [:build, :test] if DevelopmentTools.clang_build_version <= 1100
end
on_linux do
depends_on "gcc"
end
fails_with :clang do
build 1100
cause "Requires C++17 features not yet implemented"
end
fails_with gcc: "5" # C++17
def install
ENV.remove "HOMEBREW_LIBRARY_PATHS", Formula["llvm"].opt_lib
ENV.llvm_clang if OS.mac? && (DevelopmentTools.clang_build_version <= 1100)
mkdir "cmake/build" do
args = %W[
../..
-DCMAKE_CXX_STANDARD=17
-DCMAKE_CXX_STANDARD_REQUIRED=TRUE
-DCMAKE_INSTALL_RPATH=#{rpath}
-DBUILD_SHARED_LIBS=ON
-DgRPC_BUILD_TESTS=OFF
-DgRPC_INSTALL=ON
-DgRPC_ABSL_PROVIDER=package
-DgRPC_CARES_PROVIDER=package
-DgRPC_PROTOBUF_PROVIDER=package
-DgRPC_SSL_PROVIDER=package
-DgRPC_ZLIB_PROVIDER=package
-DgRPC_RE2_PROVIDER=package
] + std_cmake_args
system "cmake", *args
system "make", "install"
args = %W[
../..
-DCMAKE_INSTALL_RPATH=#{rpath}
-DBUILD_SHARED_LIBS=ON
-DgRPC_BUILD_TESTS=ON
] + std_cmake_args
system "cmake", *args
system "make", "grpc_cli"
bin.install "grpc_cli"
lib.install Dir[shared_library("libgrpc++_test_config", "*")]
if OS.mac?
# These are installed manually, so need to be relocated manually as well
MachO::Tools.add_rpath(bin/"grpc_cli", rpath)
MachO::Tools.add_rpath(lib/shared_library("libgrpc++_test_config"), rpath)
end
end
end
test do
# Force use of system clang on Mojave
ENV.clang if OS.mac? && (DevelopmentTools.clang_build_version <= 1100)
(testpath/"test.cpp").write <<~EOS
#include <grpc/grpc.h>
int main() {
grpc_init();
grpc_shutdown();
return GRPC_STATUS_OK;
}
EOS
ENV.prepend_path "PKG_CONFIG_PATH", Formula["openssl@1.1"].opt_lib/"pkgconfig"
pkg_config_flags = shell_output("pkg-config --cflags --libs libcares protobuf re2 grpc++").chomp.split
system ENV.cc, "test.cpp", "-L#{Formula["abseil"].opt_lib}", *pkg_config_flags, "-o", "test"
system "./test"
output = shell_output("grpc_cli ls localhost:#{free_port} 2>&1", 1)
assert_match "Received an error when querying services endpoint.", output
end
end