Skip to content

Commit

Permalink
Migrate ruby release targets to genrule to work around Bazel 5 bug (#…
Browse files Browse the repository at this point in the history
…11619)

sh_binary doesn't treat its data dependencies correctly prior to Bazel 6 (see https://github.com/mkruskal-google/protobuf/pull/new/ruby_release)

Closes #11619

COPYBARA_INTEGRATE_REVIEW=#11619 from mkruskal-google:ruby_release f91352a
PiperOrigin-RevId: 503564788
  • Loading branch information
mkruskal-google authored and copybara-github committed Jan 21, 2023
1 parent 354fe99 commit e207bcd
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 169 deletions.
21 changes: 15 additions & 6 deletions .github/workflows/ruby_install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,24 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: [2.6, 2.7, 3.0, 3.1, 3.2, jruby-9.2, jruby-9.3]
include:
- { ruby: 2.6, bazel: 6.0.0}
- { ruby: 2.7, bazel: 6.0.0}
- { ruby: 3.0, bazel: 6.0.0}
- { ruby: 3.1, bazel: 6.0.0}
- { ruby: 3.2, bazel: 6.0.0}
- { ruby: jruby-9.2, bazel: 6.0.0}
- { ruby: jruby-9.3, bazel: 6.0.0}
- { ruby: 2.6, bazel: 5.1.1}
- { ruby: jruby-9.2, bazel: 5.1.1}

steps:
- uses: actions/checkout@v2
- name: Install bazel
run: |
sudo apt-get install -qy wget
mkdir $HOME/bin
wget -O $HOME/bin/bazel https://github.com/bazelbuild/bazel/releases/download/6.0.0/bazel-6.0.0-linux-x86_64
wget -O $HOME/bin/bazel https://github.com/bazelbuild/bazel/releases/download/${{ matrix.bazel }}/bazel-${{ matrix.bazel }}-linux-x86_64
chmod a+x $HOME/bin/bazel
- name: Install git
run: |
Expand All @@ -40,16 +49,16 @@ jobs:
with:
submodules: recursive
- name: Build cruby gem
run: $HOME/bin/bazel run ruby:release
run: $HOME/bin/bazel build ruby:release
if: ${{ !contains(matrix.ruby, 'jruby') }}
- name: Install cruby gem
run: gem install bazel-bin/ruby/release.runfiles/com_google_protobuf/tmp/google-protobuf-*
run: gem install bazel-bin/ruby/google-protobuf-*
if: ${{ !contains(matrix.ruby, 'jruby') }}
- name: Build jruby gem
run: $HOME/bin/bazel run ruby:jruby_release
run: $HOME/bin/bazel build ruby:jruby_release
if: ${{ contains(matrix.ruby, 'jruby') }}
- name: Install jruby gem
run: gem install bazel-bin/ruby/jruby_release.runfiles/com_google_protobuf/tmp/google-protobuf-*
run: gem install bazel-bin/ruby/google-protobuf-*
if: ${{ contains(matrix.ruby, 'jruby') }}
- name: Test installation
run: |
Expand Down
60 changes: 48 additions & 12 deletions ruby/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
load("@rules_ruby//ruby:defs.bzl", "ruby_library")
load("//build_defs:internal_shell.bzl", "inline_sh_binary")
load("//:protobuf.bzl", "internal_ruby_proto_library")
load("//conformance:defs.bzl", "conformance_test")
load("//:protobuf_version.bzl", "PROTOBUF_RUBY_VERSION")
Expand All @@ -20,44 +21,79 @@ ruby_library(
],
)

sh_binary(
# Note: these can be greatly simplified using inline_sh_binary in Bazel 6,
# but doesn't work prior to that due to https://github.com/bazelbuild/bazel/issues/15043.
# Instead, we need to manually copy all of the srcs into gendir from a genrule.
genrule(
name = "jruby_release",
data = [
srcs = [
"//ruby/lib/google:copy_jar",
"//ruby/lib/google:dist_files",
"//:well_known_ruby_protos",
"google-protobuf.gemspec",
],
srcs = [
"build_jruby_release.sh",
],
deps = ["@bazel_tools//tools/bash/runfiles"],
outs = ["google-protobuf-"+PROTOBUF_RUBY_VERSION+"-java.gem"],
cmd = """
set -eux
mkdir tmp
for src in $(SRCS); do
cp --parents -L "$$src" tmp
done
for wkt in $(execpaths //:well_known_ruby_protos); do
mv "tmp/$$wkt" "tmp/ruby/lib/google/protobuf/"
done
mv "tmp/$(execpath //ruby/lib/google:copy_jar)" "tmp/ruby/lib/google"
cd tmp/ruby
chmod -R 777 ./
gem build google-protobuf.gemspec
cd ../..
mv tmp/ruby/google-protobuf-*.gem $@
""",
tags = ["manual"],
target_compatible_with = select({
"@rules_ruby//ruby/runtime:config_jruby": [],
"//conditions:default": ["@platforms//:incompatible"],
}),
)

sh_binary(
genrule(
name = "release",
data = [
srcs = [
"@utf8_range//:utf8_range_srcs",
"@utf8_range//:LICENSE",
"//:well_known_ruby_protos",
"//ruby/ext/google/protobuf_c:dist_files",
"//ruby/lib/google:dist_files",
"google-protobuf.gemspec",
],
srcs = [
"build_release.sh",
],
deps = ["@bazel_tools//tools/bash/runfiles"],
outs = ["google-protobuf-"+PROTOBUF_RUBY_VERSION+".gem"],
cmd = """
set -eux
mkdir tmp
for src in $(SRCS); do
cp --parents -L "$$src" "tmp"
done
mkdir -p "tmp/ruby/ext/google/protobuf_c/third_party/utf8_range"
for utf in $(execpaths @utf8_range//:utf8_range_srcs) $(execpath @utf8_range//:LICENSE); do
mv "tmp/$$utf" "tmp/ruby/ext/google/protobuf_c/third_party/utf8_range"
done
for wkt in $(execpaths //:well_known_ruby_protos); do
mv "tmp/$$wkt" "tmp/ruby/lib/google/protobuf/"
done
cd tmp/ruby
chmod -R 777 ./
gem build google-protobuf.gemspec
cd ../..
mv tmp/ruby/google-protobuf-*.gem $@
""",
tags = ["manual"],
target_compatible_with = select({
"@rules_ruby//ruby/runtime:config_ruby": [],
"//conditions:default": ["@platforms//:incompatible"],
}),
)


################################################################################
# Tests
################################################################################
Expand Down
63 changes: 0 additions & 63 deletions ruby/build_jruby_release.sh

This file was deleted.

88 changes: 0 additions & 88 deletions ruby/build_release.sh

This file was deleted.

0 comments on commit e207bcd

Please sign in to comment.