class Protobuf < Formula desc "Protocol buffers (Google's data interchange format)" homepage "https://protobuf.dev/" url "https://github.com/protocolbuffers/protobuf/releases/download/v22.5/protobuf-22.5.tar.gz" sha256 "26859db86e2516bf447b5c73ad484c72016376dad179d96591d489911e09cdc2" license "BSD-3-Clause" livecheck do url :stable strategy :github_latest end bottle do sha256 cellar: :any, arm64_ventura: "f93b1ff92035a29f7440afb2fa544cf0d4e7f4bd2132666dbdb2ffd5a030ef57" sha256 cellar: :any, arm64_monterey: "71c70490362c17d144fa49a0fe9adf79898303cc41378a851442cdb00795a6ec" sha256 cellar: :any, arm64_big_sur: "27431a5cbc23a0f9d755c34b5d4f2b88e5e4257ab6c34d1709ad4f86f4410153" sha256 cellar: :any, ventura: "b44e22503221d74441c4d8f1712f3a53ed6c0f6a4f56a4ea101b163398a6ca9b" sha256 cellar: :any, monterey: "6ccf9bf10da42b5d8100cab7ab1fc6494b87182db4a8af818e235574efafd609" sha256 cellar: :any, big_sur: "924b69c32c6f6e8659f6c3d8eca264472e31079fdfe062c54aab879497c7c2cb" sha256 cellar: :any_skip_relocation, x86_64_linux: "fbc46502e4a2f3eb17198723e33f6a3a45b23a5a7877a3ae14fe644ec09ccbb7" end head do url "https://github.com/protocolbuffers/protobuf.git", branch: "main" depends_on "jsoncpp" end depends_on "cmake" => :build depends_on "python@3.10" => [:build, :test] depends_on "python@3.11" => [:build, :test] depends_on "abseil" # TODO: Add the dependency below in Protobuf 24+. Also remove `head` block. # TODO: depends_on "jsoncpp" uses_from_macos "zlib" def pythons deps.map(&:to_formula) .select { |f| f.name.match?(/^python@\d\.\d+$/) } .map { |f| f.opt_libexec/"bin/python" } end def install odie "Dependencies need adjusting!" if build.stable? && version >= "24" # Keep `CMAKE_CXX_STANDARD` in sync with the same variable in `abseil.rb`. abseil_cxx_standard = 17 cmake_args = %w[ -DBUILD_SHARED_LIBS=ON -Dprotobuf_BUILD_LIBPROTOC=ON -Dprotobuf_BUILD_SHARED_LIBS=ON -Dprotobuf_INSTALL_EXAMPLES=ON -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_ABSL_PROVIDER=package -Dprotobuf_JSONCPP_PROVIDER=package ] cmake_args << "-DCMAKE_CXX_STANDARD=#{abseil_cxx_standard}" system "cmake", "-S", ".", "-B", "build", *cmake_args, *std_cmake_args system "cmake", "--build", "build" system "cmake", "--install", "build" pkgshare.install "editors/proto.vim" elisp.install "editors/protobuf-mode.el" ENV.append_to_cflags "-I#{include}" ENV.append_to_cflags "-L#{lib}" ENV["PROTOC"] = bin/"protoc" cd "python" do # Keep C++ standard in sync with `abseil.rb`. inreplace "setup.py", "extra_compile_args.append('-std=c++14')", "extra_compile_args.append('-std=c++#{abseil_cxx_standard}')" pythons.each do |python| pyext_dir = prefix/Language::Python.site_packages(python)/"google/protobuf/pyext" with_env(LDFLAGS: "-Wl,-rpath,#{rpath(source: pyext_dir)} #{ENV.ldflags}".strip) do system python, *Language::Python.setup_install_args(prefix, python), "--cpp_implementation" end end end end test do testdata = <<~EOS syntax = "proto3"; package test; message TestCase { string name = 4; } message Test { repeated TestCase case = 1; } EOS (testpath/"test.proto").write testdata system bin/"protoc", "test.proto", "--cpp_out=." pythons.each do |python| system python, "-c", "import google.protobuf" end end end