homebrew-core/Formula/etcd-cpp-apiv3.rb

106 lines
4.0 KiB
Ruby

class EtcdCppApiv3 < Formula
desc "C++ implementation for etcd's v3 client API, i.e., ETCDCTL_API=3"
homepage "https://github.com/etcd-cpp-apiv3/etcd-cpp-apiv3"
url "https://github.com/etcd-cpp-apiv3/etcd-cpp-apiv3/archive/refs/tags/v0.2.9.tar.gz"
sha256 "6874643b511a01656b4e4bc9805f911630963718f05807cbebc4b1c8bfb0fdc6"
license "BSD-3-Clause"
revision 2
bottle do
sha256 cellar: :any, arm64_ventura: "dba0bca072f1ba311ff407a0ea31360e1d20d3d7b8816429eabb65630347fb09"
sha256 cellar: :any, arm64_monterey: "79d67acef46cec73cd944b0dd0a61ef221039d3dd43b28b1a8cb1576683a796e"
sha256 cellar: :any, arm64_big_sur: "0ed07b8475a2e7f90e8461538428d374c627babed503ae91815e9576f4282844"
sha256 cellar: :any, ventura: "2a9a45c914536f48b65de3a638c1c1af42137abccc4853009d48bff53f72a9b6"
sha256 cellar: :any, monterey: "5222a9b9a0164462a0477778134556ccc8229deb0981b04672c51095b29d9d79"
sha256 cellar: :any, big_sur: "0333e1eb8999e77037f06ea0d18d0d2b4a36d23140c307d6a0516582fd916c76"
sha256 cellar: :any_skip_relocation, x86_64_linux: "537d2784d8fa29b8f7673086214c75d2392443acbdffe83669cd6b79cad382d3"
end
depends_on "cmake" => :build
depends_on "etcd" => :test
depends_on "boost"
depends_on "cpprestsdk"
depends_on "grpc"
depends_on "openssl@1.1"
depends_on "protobuf"
fails_with gcc: "5"
def install
system "cmake", "-S", ".", "-B", "build",
"-DCMAKE_CXX_STANDARD=17",
"-DCMAKE_CXX_STANDARD_REQUIRED=TRUE",
"-DBUILD_ETCD_TESTS=OFF",
"-DOPENSSL_ROOT_DIR=#{Formula["openssl@1.1"].opt_prefix}",
*std_cmake_args
system "cmake", "--build", "build"
system "cmake", "--install", "build"
end
test do
port = free_port
(testpath/"test.cc").write <<~EOS
#include <iostream>
#include <etcd/Client.hpp>
int main() {
etcd::Client etcd("http://127.0.0.1:#{port}");
etcd.set("foo", "bar").wait();
auto response = etcd.get("foo").get();
std::cout << response.value().as_string() << std::endl;
}
EOS
system ENV.cxx, "test.cc", "-std=c++17",
"-I#{Formula["boost"].include}",
"-I#{Formula["cpprestsdk"].include}",
"-I#{Formula["grpc"].include}",
"-I#{Formula["openssl@1.1"].include}",
"-I#{Formula["protobuf"].include}",
"-I#{include}",
"-L#{Formula["boost"].lib}",
"-L#{Formula["cpprestsdk"].lib}",
"-L#{Formula["grpc"].lib}",
"-L#{Formula["openssl@1.1"].lib}",
"-L#{Formula["protobuf"].lib}",
"-L#{lib}",
"-lboost_random-mt",
"-lboost_chrono-mt",
"-lboost_thread-mt",
"-lboost_system-mt",
"-lboost_filesystem-mt",
"-lcpprest",
"-letcd-cpp-api",
"-lgpr", "-lgrpc", "-lgrpc++",
"-lssl", "-lcrypto",
"-lprotobuf",
"-o", "test_etcd_cpp_apiv3"
# prepare etcd
etcd_pid = fork do
if OS.mac? && Hardware::CPU.arm?
# etcd isn't officially supported on arm64
# https://github.com/etcd-io/etcd/issues/10318
# https://github.com/etcd-io/etcd/issues/10677
ENV["ETCD_UNSUPPORTED_ARCH"]="arm64"
end
exec "#{Formula["etcd"].opt_prefix}/bin/etcd",
"--force-new-cluster",
"--data-dir=#{testpath}",
"--listen-client-urls=http://127.0.0.1:#{port}",
"--advertise-client-urls=http://127.0.0.1:#{port}"
end
# sleep to let etcd get its wits about it
sleep 10
assert_equal("bar\n", shell_output("./test_etcd_cpp_apiv3"))
ensure
# clean up the etcd process before we leave
Process.kill("HUP", etcd_pid)
end
end