Skip to content

Instantly share code, notes, and snippets.

@jonasschneider
Last active October 12, 2018 00:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonasschneider/f1e99b8f29dc826fd2d31b76db753c4a to your computer and use it in GitHub Desktop.
Save jonasschneider/f1e99b8f29dc826fd2d31b76db753c4a to your computer and use it in GitHub Desktop.
class Protobuf < Formula
desc "Protocol buffers (Google's data interchange format)"
homepage "https://github.com/google/protobuf/"
url "https://github.com/google/protobuf/archive/v3.5.1.tar.gz"
sha256 "826425182ee43990731217b917c5c3ea7190cfda141af4869e6d4ad9085a740f"
head "https://github.com/google/protobuf.git"
bottle do
sha256 "5f55e9d369bfc4b6c910010ecfa549ddeb394e1934f3b231295d30348f8823ca" => :high_sierra
sha256 "c354f6c84d6454be78a8cec4e26726f87ff8c9322a834a215e162ba07e6fc9fc" => :sierra
sha256 "b6af1ce4c02bb2063a4084890e2c09d4c7e68c8e7ec1f0cba765f583a364d25f" => :el_capitan
end
# this will double the build time approximately if enabled
option "with-test", "Run build-time check"
option "without-python", "Build without python support"
deprecated_option "with-check" => "with-test"
depends_on "autoconf" => :build
depends_on "automake" => :build
depends_on "libtool" => :build
#depends_on :python => :recommended if MacOS.version <= :snow_leopard
#depends_on :python3 => :optional
resource "six" do
url "https://files.pythonhosted.org/packages/16/d8/bc6316cf98419719bd59c91742194c111b6f2e85abac88e496adefaf7afe/six-1.11.0.tar.gz"
sha256 "70e8a77beed4562e7f14fe23a786b54f6296e34344c23bc42f07b15018ff98e9"
end
# Upstream's autogen script fetches this if not present
# but does no integrity verification & mandates being online to install.
resource "gmock" do
url "https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/googlemock/gmock-1.7.0.zip"
mirror "https://dl.bintray.com/homebrew/mirror/gmock-1.7.0.zip"
sha256 "26fcbb5925b74ad5fc8c26b0495dfc96353f4d553492eb97e85a8a6d2f43095b"
end
needs :cxx11
def install
# Don't build in debug mode. See:
# https://github.com/Homebrew/homebrew/issues/9279
# https://github.com/google/protobuf/blob/5c24564811c08772d090305be36fae82d8f12bbe/configure.ac#L61
ENV.prepend "CXXFLAGS", "-DNDEBUG"
ENV.cxx11
(buildpath/"gmock").install resource("gmock")
system "./autogen.sh"
system "./configure", "--disable-debug", "--disable-dependency-tracking",
"--prefix=#{prefix}", "--with-zlib"
system "make"
system "make", "check" if build.with?("test") || build.bottle?
system "make", "install"
# Install editor support and examples
doc.install "editors", "examples"
Language::Python.each_python(build) do |python, version|
resource("six").stage do
system python, *Language::Python.setup_install_args(libexec)
end
chdir "python" do
ENV.append_to_cflags "-I#{include}"
ENV.append_to_cflags "-L#{lib}"
args = Language::Python.setup_install_args libexec
args << "--cpp_implementation"
system python, *args
end
site_packages = "lib/python#{version}/site-packages"
pth_contents = "import site; site.addsitedir('#{libexec/site_packages}')\n"
(prefix/site_packages/"homebrew-protobuf.pth").write pth_contents
end
end
def caveats; <<~EOS
Editor support and examples have been installed to:
#{doc}
EOS
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=."
system "python", "-c", "import google.protobuf" if build.with? "python"
system "python3", "-c", "import google.protobuf" if build.with? "python3"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment