homebrew-core/Formula/grpc.rb

96 lines
2.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.36.0",
revision: "736e3758351ced3cd842bad3ba4e2540f01bbc48",
shallow: false
license "Apache-2.0"
revision 1
head "https://github.com/grpc/grpc.git"
livecheck do
url :stable
strategy :github_latest
end
bottle do
sha256 arm64_big_sur: "97f7e92fb5f93f9bad3492e9ce45d6352474299101f10cbcf7e29e1c9579c4ef"
sha256 big_sur: "c7436a8932ffa15452044626efe70cedd7d5767757085db52697319e88f26620"
sha256 catalina: "54b03077201bc405839da0988076df6c5537fe6ae67c342b52c705a9e1f88588"
sha256 mojave: "957a614406efdfb26a91f37204bc5d9385648e0308f09e5578b43a29e000f4bd"
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"
def install
mkdir "cmake/build" do
args = %W[
../..
-DCMAKE_CXX_STANDARD=17
-DCMAKE_CXX_STANDARD_REQUIRED=TRUE
-DCMAKE_INSTALL_RPATH=#{lib}
-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"
# grpc_cli does not build correctly with a non-/usr/local prefix.
# Reported upstream at https://github.com/grpc/grpc/issues/25176
# When removing the `unless` block, make sure to do the same for
# the test block.
unless Hardware::CPU.arm?
args = %W[
../..
-DCMAKE_INSTALL_RPATH=#{lib}
-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", "*")]
end
end
end
test do
(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"
unless Hardware::CPU.arm?
output = shell_output("grpc_cli ls localhost:#{free_port} 2>&1", 1)
assert_match "Received an error when querying services endpoint.", output
end
end
end