diff --git a/PKGBUILD b/PKGBUILD index 8520599..ee74ea6 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -8,7 +8,7 @@ # Contributor: Daniel J Griffiths pkgbase='protobuf' -pkgname=('protobuf' 'python-protobuf') +pkgname=('protobuf' 'python-protobuf' 'ruby-google-protobuf') pkgver=25.1 pkgrel=1 pkgdesc="Protocol Buffers - Google's data interchange format" @@ -20,6 +20,8 @@ depends=( 'glibc' 'zlib' 'abseil-cpp' + 'ruby' + 'ruby-rake-compiler' ) makedepends=( 'cmake' @@ -36,17 +38,30 @@ checkdepends=( source=(https://github.com/protocolbuffers/protobuf/archive/v$pkgver/$pkgname-$pkgver.tar.gz https://github.com/protocolbuffers/protobuf/commit/2e62ef1e.patch soversion.patch - $pkgbase-21.12-pep517.patch) # let's not call setup.py like a script and just build... + $pkgbase-21.12-pep517.patch # let's not call setup.py like a script and just build... + $pkgbase-25.1-ruby-format-security.patch # fix error with -Werror=format-security + $pkgbase-25-1-ruby-disable-LTO.patch) # https://github.com/protocolbuffers/protobuf/issues/11935 sha512sums=('d2fad2188118ced2cd951bdb472d72cc9e9b2158c88eeca652c76332a884b5b5b4b58628f7777272fa693140753823584ea9c7924f1655b1d5a363f59bdf7a4c' 'f42d9bd702abe2c7fc4dcb07d050376287ac60b0b7e2fde0d7a9e9df24a620866bee5fd7de2e3b216095376de47e1fe7443cca74c9a9e85c1a0bc42e8973a280' 'f0813a415cff5639e4709400f15b0c5565294e7907ae164e620b76258734c643115d8e5170bf0e4aee264c347fb7e01ac4be60d19be2a91c0ce9c561dad8c8e9' - 'a297e74ee4f807b3fad7da7d0de6dd9647963521be66cd2a2370343f5bd191cbb38759157ac0cdb161a5893a30a10520a5098e88a292c800859af33db5cf7a41') + 'a297e74ee4f807b3fad7da7d0de6dd9647963521be66cd2a2370343f5bd191cbb38759157ac0cdb161a5893a30a10520a5098e88a292c800859af33db5cf7a41' + '633a43ba8cf4f874383f8b7bba95387eb73482d9795793c765e59783a6f483722b7fd38c99492e2b82082ad32fe0b9ed0972730eaa53ce431360df62c98e1828' + '1ebdea4e533ee0f71baf1b3fe2623ca723b36a08c6b97475ea5996b10aeb6873cf94d9120596ddd1216bd2f6feb991f8c33078e8104008a5078ace5be5431efd') + +_gemname=google-protobuf prepare() { patch -d $pkgbase-$pkgver -p1 < $pkgname-21.12-pep517.patch patch -d $pkgname-$pkgver -p1 < 2e62ef1e.patch # Fix cmake config compatibility mode patch -d $pkgbase-$pkgver -p1 < soversion.patch # Restore soversion + patch -d $pkgbase-$pkgver -p1 < $pkgbase-25.1-ruby-format-security.patch + patch -d $pkgbase-$pkgver -p1 < $pkgbase-25-1-ruby-disable-LTO.patch sed -e 's|c++14|c++17|' -i $pkgbase-$pkgver/python/setup.py + + + cd $pkgbase-$pkgver/ruby + # update gemspec/Gemfile to allow newer version of the dependencies + sed -i 's|~>|>=|g' $_gemname.gemspec Gemfile } build() { @@ -64,17 +79,68 @@ build() { cmake "${cmake_options[@]}" cmake --build build --verbose - cd $pkgbase-$pkgver/python + pushd $pkgbase-$pkgver/python LDFLAGS+=" -L${srcdir}/build" \ PROTOC="$srcdir"/build/protoc \ python -m build --wheel --no-isolation + popd + + pushd $pkgbase-$pkgver/ruby + local _gemdir="$(gem env gemdir)" + + PROTOC="$srcdir"/build/protoc \ + rake genproto + rake copy_third_party + + gem build "${_gemname}.gemspec" + + local _gemver=3.$pkgver + gem install \ + --local \ + --verbose \ + --ignore-dependencies \ + --no-user-install \ + --install-dir "tmp_install/${_gemdir}" \ + --bindir "tmp_install/usr/bin" \ + "${_gemname}-${_gemver}.gem" + + # remove unrepreducible files + rm --force --recursive --verbose \ + "tmp_install/${_gemdir}/cache/" \ + "tmp_install/${_gemdir}/gems/${_gemname}-${_gemver}/vendor/" \ + "tmp_install/${_gemdir}/doc/${_gemname}-${_gemver}/ri/ext/" + + find "tmp_install/${_gemdir}/gems/" \ + -type f \ + \( \ + -iname "*.o" -o \ + -iname "*.c" -o \ + -iname "*.so" -o \ + -iname "*.time" -o \ + -iname "gem.build_complete" -o \ + -iname "Makefile" \ + \) \ + -delete + + find "tmp_install/${_gemdir}/extensions/" \ + -type f \ + \( \ + -iname "mkmf.log" -o \ + -iname "gem_make.out" \ + \) \ + -delete } check() { ctest --test-dir build - cd $pkgbase-$pkgver/python + pushd $pkgbase-$pkgver/python pytest -vv google/$pkgbase/internal/ || true + popd + + pushd $pkgbase-$pkgver/ruby + local _gemdir="$(gem env gemdir)" + IN_DOCKER=true GEM_HOME="tmp_install/${_gemdir}" rake test } package_protobuf() { @@ -101,3 +167,15 @@ package_python-protobuf() { python -m installer --destdir="$pkgdir" $pkgbase-$pkgver/python/dist/*.whl install -vDm 644 $pkgbase-$pkgver/LICENSE -t "$pkgdir/usr/share/licenses/$pkgname/" } + +package_ruby-google-protobuf() { + pkgdesc='Ruby bindings for Google Protocol Buffers' + depends=( + 'ruby' + ) + + cp -a $pkgbase-$pkgver/ruby/tmp_install/* "$pkgdir" + + install -vDm 644 $pkgbase-$pkgver/LICENSE -t "$pkgdir/usr/share/licenses/$pkgname/" + install -Dm 0644 $pkgbase-$pkgver/ruby/*.md -t "$pkgdir/usr/share/doc/${pkgname}" +} diff --git a/protobuf-25-1-ruby-disable-LTO.patch b/protobuf-25-1-ruby-disable-LTO.patch new file mode 100644 index 0000000..07b41d7 --- /dev/null +++ b/protobuf-25-1-ruby-disable-LTO.patch @@ -0,0 +1,14 @@ +diff --git a/ruby/ext/google/protobuf_c/extconf.rb b/ruby/ext/google/protobuf_c/extconf.rb +index 4bb49bb..37266d7 100755 +--- a/ruby/ext/google/protobuf_c/extconf.rb ++++ b/ruby/ext/google/protobuf_c/extconf.rb +@@ -14,7 +14,8 @@ end + + if RUBY_PLATFORM =~ /linux/ + # Instruct the linker to point memcpy calls at our __wrap_memcpy wrapper. +- $LDFLAGS += " -Wl,-wrap,memcpy" ++ $CFLAGS += " -fno-lto" ++ $LDFLAGS += " -Wl,-wrap,memcpy -fno-lto" + end + + $VPATH << "$(srcdir)/third_party/utf8_range" diff --git a/protobuf-25.1-ruby-format-security.patch b/protobuf-25.1-ruby-format-security.patch new file mode 100644 index 0000000..91cbbf8 --- /dev/null +++ b/protobuf-25.1-ruby-format-security.patch @@ -0,0 +1,43 @@ +diff --git a/ruby/ext/google/protobuf_c/convert.c b/ruby/ext/google/protobuf_c/convert.c +index c9448cd..dd968b5 100644 +--- a/ruby/ext/google/protobuf_c/convert.c ++++ b/ruby/ext/google/protobuf_c/convert.c +@@ -296,7 +296,7 @@ bool Msgval_IsEqual(upb_MessageValue val1, upb_MessageValue val2, + if (upb_Status_IsOk(&status)) { + return return_value; + } else { +- rb_raise(rb_eRuntimeError, upb_Status_ErrorMessage(&status)); ++ rb_raise(rb_eRuntimeError, "%s", upb_Status_ErrorMessage(&status)); + } + } + +@@ -309,6 +309,6 @@ uint64_t Msgval_GetHash(upb_MessageValue val, TypeInfo type_info, + if (upb_Status_IsOk(&status)) { + return return_value; + } else { +- rb_raise(rb_eRuntimeError, upb_Status_ErrorMessage(&status)); ++ rb_raise(rb_eRuntimeError, "%s", upb_Status_ErrorMessage(&status)); + } + } +diff --git a/ruby/ext/google/protobuf_c/message.c b/ruby/ext/google/protobuf_c/message.c +index d64d411..836bd5e 100644 +--- a/ruby/ext/google/protobuf_c/message.c ++++ b/ruby/ext/google/protobuf_c/message.c +@@ -678,7 +678,7 @@ bool Message_Equal(const upb_Message* m1, const upb_Message* m2, + if (upb_Status_IsOk(&status)) { + return return_value; + } else { +- rb_raise(cParseError, upb_Status_ErrorMessage(&status)); ++ rb_raise(cParseError, "%s", upb_Status_ErrorMessage(&status)); + } + } + +@@ -709,7 +709,7 @@ uint64_t Message_Hash(const upb_Message* msg, const upb_MessageDef* m, + if (upb_Status_IsOk(&status)) { + return return_value; + } else { +- rb_raise(cParseError, upb_Status_ErrorMessage(&status)); ++ rb_raise(cParseError, "%s", upb_Status_ErrorMessage(&status)); + } + } +