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 2 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
8 changes: 4 additions & 4 deletions .github/workflows/ruby_install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,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
52 changes: 40 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,71 @@ 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
for src in $(SRCS); do
cp --parents "$$src" "$(GENDIR)"
done
for wkt in $(execpaths //:well_known_ruby_protos); do
cp "$$wkt" "$(GENDIR)/ruby/lib/google/protobuf/"
done
cd $(GENDIR)/ruby
chmod -R 777 ./
gem build google-protobuf.gemspec
""",
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
for src in $(SRCS); do
cp --parents "$$src" "$(GENDIR)"
done
mkdir -p "$(GENDIR)/ruby/ext/google/protobuf_c/third_party/utf8_range"
for utf in $(execpaths @utf8_range//:utf8_range_srcs) $(execpath @utf8_range//:LICENSE); do
cp "$$utf" "$(GENDIR)/ruby/ext/google/protobuf_c/third_party/utf8_range"
done
for wkt in $(execpaths //:well_known_ruby_protos); do
cp "$$wkt" "$(GENDIR)/ruby/lib/google/protobuf/"
done
cd $(GENDIR)/ruby
chmod -R 777 ./
gem build google-protobuf.gemspec
pwd
""",
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.