Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate ruby release targets to genrule to work around Bazel 5 bug #11619

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.