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

113 lines
4.1 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.3.tar.gz"
sha256 "f74607eebffce8391b5355ed7d12d46f6627f2882687cd0f5574c90b275f77fd"
license "BSD-3-Clause"
revision 1
bottle do
sha256 cellar: :any, arm64_monterey: "912ed22203f9e40473210c603a0c697dfdca8746300982268eb6aceeb9487d53"
sha256 cellar: :any, arm64_big_sur: "96565558e1e7f0a1d0842ec0d9aa7799339ac3f565f8a3369d40af20d6b9dbf9"
sha256 cellar: :any, monterey: "39ab054664f7b1422c5ef247d0dc8a853eee5341748cc0f22475ea528e7a9eb0"
sha256 cellar: :any, big_sur: "612e1254ac4adbebe0c18078161a2643d3e8be934cb08ccd0f34b91df671d796"
sha256 cellar: :any, catalina: "ec8257fd0e9cb81a3bbe109001a06abf438788a1e0b5f4f3078295bdff8e6d56"
sha256 cellar: :any_skip_relocation, x86_64_linux: "d228f518262ecf2ea070da3933049a9857f0302979fd8eedbaa28cf35769562f"
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"
# grpc requrires high version of gcc and are built with high version of gcc,
# thus gcc 5 won't work
on_linux do
depends_on "gcc"
end
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
on_macos do
if 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
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