Skip to content

Commit 5b27b4f

Browse files
deannagarciacopybara-github
authored andcommitted
Add ruby release targets (#11468)
Add bazel targets to create ruby release artifacts. Should be run with: ``` bazel run ruby:release bazel run ruby:jruby_release ``` Closes #11468 COPYBARA_INTEGRATE_REVIEW=#11468 from deannagarcia:rubyTargets b7b7eb6 PiperOrigin-RevId: 503277136
1 parent 196193d commit 5b27b4f

File tree

9 files changed

+263
-4
lines changed

9 files changed

+263
-4
lines changed

.github/workflows/ruby_install.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Ruby Install Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- '[0-9]+.x'
8+
pull_request:
9+
branches:
10+
- main
11+
- '[0-9]+.x'
12+
workflow_dispatch:
13+
14+
jobs:
15+
test_ruby_gems:
16+
name: Test ruby gems
17+
runs-on: ubuntu-20.04
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
ruby: [2.6, 2.7, 3.0, 3.1, 3.2, jruby-9.2, jruby-9.3]
22+
23+
steps:
24+
- uses: actions/checkout@v2
25+
- name: Install bazel
26+
run: |
27+
sudo apt-get install -qy wget
28+
mkdir $HOME/bin
29+
wget -O $HOME/bin/bazel https://github.com/bazelbuild/bazel/releases/download/6.0.0/bazel-6.0.0-linux-x86_64
30+
chmod a+x $HOME/bin/bazel
31+
- name: Install git
32+
run: |
33+
sudo apt-get install -qy --no-install-recommends git
34+
- name: Install ruby
35+
uses: ruby/setup-ruby@v1
36+
with:
37+
ruby-version: ${{ matrix.ruby }}
38+
- name: Checkout
39+
uses: actions/checkout@v3
40+
with:
41+
submodules: recursive
42+
- name: Build cruby gem
43+
run: $HOME/bin/bazel run ruby:release
44+
if: ${{ !contains(matrix.ruby, 'jruby') }}
45+
- name: Install cruby gem
46+
run: gem install bazel-bin/ruby/release.runfiles/com_google_protobuf/tmp/google-protobuf-*
47+
if: ${{ !contains(matrix.ruby, 'jruby') }}
48+
- name: Build jruby gem
49+
run: $HOME/bin/bazel run ruby:jruby_release
50+
if: ${{ contains(matrix.ruby, 'jruby') }}
51+
- name: Install jruby gem
52+
run: gem install bazel-bin/ruby/jruby_release.runfiles/com_google_protobuf/tmp/google-protobuf-*
53+
if: ${{ contains(matrix.ruby, 'jruby') }}
54+
- name: Test installation
55+
run: |
56+
bazel run //:protoc -- --proto_path=$GITHUB_WORKSPACE/src --proto_path=$GITHUB_WORKSPACE/ruby/tests --proto_path=$GITHUB_WORKSPACE/ruby --ruby_out=$GITHUB_WORKSPACE/ruby tests/test_import_proto2.proto
57+
bazel run //:protoc -- --proto_path=$GITHUB_WORKSPACE/src --proto_path=$GITHUB_WORKSPACE/ruby/tests --proto_path=$GITHUB_WORKSPACE/ruby --ruby_out=$GITHUB_WORKSPACE/ruby tests/basic_test.proto
58+
ruby ruby/tests/basic.rb

WORKSPACE

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ http_archive(
3535
load("//:protobuf_deps.bzl", "PROTOBUF_MAVEN_ARTIFACTS", "protobuf_deps")
3636
protobuf_deps()
3737

38+
load("@rules_jvm_external//:repositories.bzl", "rules_jvm_external_deps")
39+
40+
rules_jvm_external_deps()
41+
42+
load("@rules_jvm_external//:setup.bzl", "rules_jvm_external_setup")
43+
44+
rules_jvm_external_setup()
45+
3846
load("@rules_jvm_external//:defs.bzl", "maven_install")
3947

4048
maven_install(

protobuf_deps.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ def protobuf_deps():
110110
_github_archive(
111111
name = "rules_ruby",
112112
repo = "https://github.com/protocolbuffers/rules_ruby",
113-
commit = "59732544ce3a4bc4e8e4d4e8c8f318c931c17eae",
114-
sha256 = "4fc45adf1056c824afde9a52b743b915eeada3633539eb1dbd641a66dc9f4c4f",
113+
commit = "5cf6ff74161d7f985b9bf86bb3c5fb16cef6337b",
114+
sha256 = "c88dd69eb50fcfd7fbc5d7db79adc6631ef0e1d80b3c94efe33ac5ee3ccc37f7",
115115
)
116116

117117
if not native.existing_rule("rules_jvm_external"):

protobuf_version.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ PROTOC_VERSION = "21.12"
22
PROTOBUF_JAVA_VERSION = "3.21.12"
33
PROTOBUF_PYTHON_VERSION = "4.21.12"
44
PROTOBUF_PHP_VERSION = "3.21.12"
5+
PROTOBUF_RUBY_VERSION = "3.21.12"

ruby/BUILD.bazel

100644100755
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
66
load("@rules_ruby//ruby:defs.bzl", "ruby_library")
77
load("//:protobuf.bzl", "internal_ruby_proto_library")
88
load("//conformance:defs.bzl", "conformance_test")
9+
load("//:protobuf_version.bzl", "PROTOBUF_RUBY_VERSION")
910

1011
################################################################################
1112
# Ruby Runtime
@@ -19,6 +20,44 @@ ruby_library(
1920
],
2021
)
2122

23+
sh_binary(
24+
name = "jruby_release",
25+
data = [
26+
"//ruby/lib/google:copy_jar",
27+
"//ruby/lib/google:dist_files",
28+
"//:well_known_ruby_protos",
29+
"google-protobuf.gemspec",
30+
],
31+
srcs = [
32+
"build_jruby_release.sh",
33+
],
34+
deps = ["@bazel_tools//tools/bash/runfiles"],
35+
target_compatible_with = select({
36+
"@rules_ruby//ruby/runtime:config_jruby": [],
37+
"//conditions:default": ["@platforms//:incompatible"],
38+
}),
39+
)
40+
41+
sh_binary(
42+
name = "release",
43+
data = [
44+
"@utf8_range//:utf8_range_srcs",
45+
"@utf8_range//:LICENSE",
46+
"//:well_known_ruby_protos",
47+
"//ruby/ext/google/protobuf_c:dist_files",
48+
"//ruby/lib/google:dist_files",
49+
"google-protobuf.gemspec",
50+
],
51+
srcs = [
52+
"build_release.sh",
53+
],
54+
deps = ["@bazel_tools//tools/bash/runfiles"],
55+
target_compatible_with = select({
56+
"@rules_ruby//ruby/runtime:config_ruby": [],
57+
"//conditions:default": ["@platforms//:incompatible"],
58+
}),
59+
)
60+
2261
################################################################################
2362
# Tests
2463
################################################################################

ruby/build_jruby_release.sh

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/bin/bash
2+
# This file should be executed with jruby
3+
4+
set -ex
5+
6+
# --- begin runfiles.bash initialization ---
7+
# Copy-pasted from Bazel's Bash runfiles library (tools/bash/runfiles/runfiles.bash).
8+
set -euo pipefail
9+
if [[ ! -d "${RUNFILES_DIR:-/dev/null}" && ! -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then
10+
if [[ -f "$0.runfiles_manifest" ]]; then
11+
export RUNFILES_MANIFEST_FILE="$0.runfiles_manifest"
12+
elif [[ -f "$0.runfiles/MANIFEST" ]]; then
13+
export RUNFILES_MANIFEST_FILE="$0.runfiles/MANIFEST"
14+
elif [[ -f "$0.runfiles/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then
15+
export RUNFILES_DIR="$0.runfiles"
16+
fi
17+
fi
18+
if [[ -f "${RUNFILES_DIR:-/dev/null}/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then
19+
source "${RUNFILES_DIR}/bazel_tools/tools/bash/runfiles/runfiles.bash"
20+
elif [[ -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then
21+
source "$(grep -m1 "^bazel_tools/tools/bash/runfiles/runfiles.bash " \
22+
"$RUNFILES_MANIFEST_FILE" | cut -d ' ' -f 2-)"
23+
else
24+
echo >&2 "ERROR: cannot find @bazel_tools//tools/bash/runfiles:runfiles.bash"
25+
exit 1
26+
fi
27+
# --- end runfiles.bash initialization ---
28+
29+
# Make a temporary directory and move to it to do all packaging work
30+
mkdir -p tmp
31+
cd tmp
32+
33+
# Move all generated files to lib/google/protobuf
34+
mkdir -p lib/google/protobuf
35+
cp "$(rlocation com_google_protobuf/src/google/protobuf/any_pb.rb)" lib/google/protobuf
36+
cp "$(rlocation com_google_protobuf/src/google/protobuf/api_pb.rb)" lib/google/protobuf
37+
cp "$(rlocation com_google_protobuf/src/google/protobuf/descriptor_pb.rb)" lib/google/protobuf
38+
cp "$(rlocation com_google_protobuf/src/google/protobuf/duration_pb.rb)" lib/google/protobuf
39+
cp "$(rlocation com_google_protobuf/src/google/protobuf/empty_pb.rb)" lib/google/protobuf
40+
cp "$(rlocation com_google_protobuf/src/google/protobuf/field_mask_pb.rb)" lib/google/protobuf
41+
cp "$(rlocation com_google_protobuf/src/google/protobuf/source_context_pb.rb)" lib/google/protobuf
42+
cp "$(rlocation com_google_protobuf/src/google/protobuf/struct_pb.rb)" lib/google/protobuf
43+
cp "$(rlocation com_google_protobuf/src/google/protobuf/timestamp_pb.rb)" lib/google/protobuf
44+
cp "$(rlocation com_google_protobuf/src/google/protobuf/type_pb.rb)" lib/google/protobuf
45+
cp "$(rlocation com_google_protobuf/src/google/protobuf/wrappers_pb.rb)" lib/google/protobuf
46+
47+
cp "$(rlocation com_google_protobuf/ruby/lib/google/protobuf_java.jar)" lib/google
48+
49+
# Move all source files to the correct location
50+
cp "$(rlocation com_google_protobuf/ruby/lib/google/protobuf.rb)" lib/google
51+
cp "$(rlocation com_google_protobuf/ruby/lib/google/protobuf/descriptor_dsl.rb)" lib/google/protobuf
52+
cp "$(rlocation com_google_protobuf/ruby/lib/google/protobuf/message_exts.rb)" lib/google/protobuf
53+
cp "$(rlocation com_google_protobuf/ruby/lib/google/protobuf/repeated_field.rb)" lib/google/protobuf
54+
cp "$(rlocation com_google_protobuf/ruby/lib/google/protobuf/well_known_types.rb)" lib/google/protobuf
55+
56+
# Move gemspec file to current directory
57+
cp "$(rlocation com_google_protobuf/ruby/google.protobuf.gemspec)" .
58+
59+
# Make all files global readable/writable/executable
60+
chmod -R 777 ./
61+
62+
# Build gem
63+
gem build google-protobuf.gemspec

ruby/build_release.sh

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/bin/bash
2+
# This file should be executed with ruby
3+
4+
set -ex
5+
6+
# --- begin runfiles.bash initialization ---
7+
# Copy-pasted from Bazel's Bash runfiles library (tools/bash/runfiles/runfiles.bash).
8+
set -euo pipefail
9+
if [[ ! -d "${RUNFILES_DIR:-/dev/null}" && ! -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then
10+
if [[ -f "$0.runfiles_manifest" ]]; then
11+
export RUNFILES_MANIFEST_FILE="$0.runfiles_manifest"
12+
elif [[ -f "$0.runfiles/MANIFEST" ]]; then
13+
export RUNFILES_MANIFEST_FILE="$0.runfiles/MANIFEST"
14+
elif [[ -f "$0.runfiles/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then
15+
export RUNFILES_DIR="$0.runfiles"
16+
fi
17+
fi
18+
if [[ -f "${RUNFILES_DIR:-/dev/null}/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then
19+
source "${RUNFILES_DIR}/bazel_tools/tools/bash/runfiles/runfiles.bash"
20+
elif [[ -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then
21+
source "$(grep -m1 "^bazel_tools/tools/bash/runfiles/runfiles.bash " \
22+
"$RUNFILES_MANIFEST_FILE" | cut -d ' ' -f 2-)"
23+
else
24+
echo >&2 "ERROR: cannot find @bazel_tools//tools/bash/runfiles:runfiles.bash"
25+
exit 1
26+
fi
27+
# --- end runfiles.bash initialization ---
28+
29+
# rvm use ruby-3.0
30+
31+
# Make a temporary directory and move to it to do all packaging work
32+
mkdir -p tmp
33+
cd tmp
34+
35+
# Move all generated files to lib/google/protobuf
36+
mkdir -p lib/google/protobuf
37+
cp "$(rlocation com_google_protobuf/src/google/protobuf/any_pb.rb)" lib/google/protobuf
38+
cp "$(rlocation com_google_protobuf/src/google/protobuf/api_pb.rb)" lib/google/protobuf
39+
cp "$(rlocation com_google_protobuf/src/google/protobuf/descriptor_pb.rb)" lib/google/protobuf
40+
cp "$(rlocation com_google_protobuf/src/google/protobuf/duration_pb.rb)" lib/google/protobuf
41+
cp "$(rlocation com_google_protobuf/src/google/protobuf/empty_pb.rb)" lib/google/protobuf
42+
cp "$(rlocation com_google_protobuf/src/google/protobuf/field_mask_pb.rb)" lib/google/protobuf
43+
cp "$(rlocation com_google_protobuf/src/google/protobuf/source_context_pb.rb)" lib/google/protobuf
44+
cp "$(rlocation com_google_protobuf/src/google/protobuf/struct_pb.rb)" lib/google/protobuf
45+
cp "$(rlocation com_google_protobuf/src/google/protobuf/timestamp_pb.rb)" lib/google/protobuf
46+
cp "$(rlocation com_google_protobuf/src/google/protobuf/type_pb.rb)" lib/google/protobuf
47+
cp "$(rlocation com_google_protobuf/src/google/protobuf/wrappers_pb.rb)" lib/google/protobuf
48+
49+
# Move all utf-8 files to ext/google/protobuf_c/third_party/utf8_range
50+
UTF8_DIR=ext/google/protobuf_c/third_party/utf8_range
51+
mkdir -p $UTF8_DIR
52+
cp "$(rlocation utf8_range/LICENSE)" $UTF8_DIR/LICENSE
53+
cp "$(rlocation utf8_range/naive.c)" $UTF8_DIR
54+
cp "$(rlocation utf8_range/range2-neon.c)" $UTF8_DIR
55+
cp "$(rlocation utf8_range/range2-sse.c)" $UTF8_DIR
56+
cp "$(rlocation utf8_range/utf8_range.h)" $UTF8_DIR
57+
58+
# Move all source files to the correct location
59+
cp "$(rlocation com_google_protobuf/ruby/ext/google/protobuf_c/convert.c)" ext/google/protobuf_c
60+
cp "$(rlocation com_google_protobuf/ruby/ext/google/protobuf_c/convert.h)" ext/google/protobuf_c
61+
cp "$(rlocation com_google_protobuf/ruby/ext/google/protobuf_c/defs.c)" ext/google/protobuf_c
62+
cp "$(rlocation com_google_protobuf/ruby/ext/google/protobuf_c/defs.h)" ext/google/protobuf_c
63+
cp "$(rlocation com_google_protobuf/ruby/ext/google/protobuf_c/extconf.rb)" ext/google/protobuf_c
64+
cp "$(rlocation com_google_protobuf/ruby/ext/google/protobuf_c/map.c)" ext/google/protobuf_c
65+
cp "$(rlocation com_google_protobuf/ruby/ext/google/protobuf_c/map.h)" ext/google/protobuf_c
66+
cp "$(rlocation com_google_protobuf/ruby/ext/google/protobuf_c/message.c)" ext/google/protobuf_c
67+
cp "$(rlocation com_google_protobuf/ruby/ext/google/protobuf_c/message.h)" ext/google/protobuf_c
68+
cp "$(rlocation com_google_protobuf/ruby/ext/google/protobuf_c/protobuf.c)" ext/google/protobuf_c
69+
cp "$(rlocation com_google_protobuf/ruby/ext/google/protobuf_c/protobuf.h)" ext/google/protobuf_c
70+
cp "$(rlocation com_google_protobuf/ruby/ext/google/protobuf_c/repeated_field.c)" ext/google/protobuf_c
71+
cp "$(rlocation com_google_protobuf/ruby/ext/google/protobuf_c/repeated_field.h)" ext/google/protobuf_c
72+
cp "$(rlocation com_google_protobuf/ruby/ext/google/protobuf_c/ruby-upb.c)" ext/google/protobuf_c
73+
cp "$(rlocation com_google_protobuf/ruby/ext/google/protobuf_c/ruby-upb.h)" ext/google/protobuf_c
74+
cp "$(rlocation com_google_protobuf/ruby/ext/google/protobuf_c/wrap_memcpy.c)" ext/google/protobuf_c
75+
cp "$(rlocation com_google_protobuf/ruby/lib/google/protobuf.rb)" lib/google
76+
cp "$(rlocation com_google_protobuf/ruby/lib/google/protobuf/descriptor_dsl.rb)" lib/google/protobuf
77+
cp "$(rlocation com_google_protobuf/ruby/lib/google/protobuf/message_exts.rb)" lib/google/protobuf
78+
cp "$(rlocation com_google_protobuf/ruby/lib/google/protobuf/repeated_field.rb)" lib/google/protobuf
79+
cp "$(rlocation com_google_protobuf/ruby/lib/google/protobuf/well_known_types.rb)" lib/google/protobuf
80+
81+
# Move gemspec file to current directory
82+
cp "$(rlocation com_google_protobuf/ruby/google.protobuf.gemspec)" .
83+
84+
# Make all files global readable/writable/executable
85+
chmod -R 777 ./
86+
87+
# Build gem
88+
gem build google-protobuf.gemspec

ruby/ext/google/protobuf_c/extconf.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
dir_config(ext_name)
88

99
if RUBY_PLATFORM =~ /darwin/ || RUBY_PLATFORM =~ /linux/ || RUBY_PLATFORM =~ /freebsd/
10-
$CFLAGS += " -std=gnu99 -O3 -DNDEBUG -fvisibility=hidden -Wall -Wsign-compare -Wno-declaration-after-statement"
10+
$CFLAGS += " -std=gnu99 -O3 -DNDEBUG -fvisibility=hidden -Wall -Wsign-compare -Wno-declaration-after-statement -I$(srcdir)/third_party/utf8_range"
1111
else
1212
$CFLAGS += " -std=gnu99 -O3 -DNDEBUG"
1313
end
@@ -25,4 +25,4 @@
2525
"repeated_field.c", "map.c", "ruby-upb.c", "wrap_memcpy.c",
2626
"naive.c", "range2-neon.c", "range2-sse.c"]
2727

28-
create_makefile(ext_name, Dir.pwd+"/../../../../ext/google/protobuf_c")
28+
create_makefile(ext_name)

ruby/lib/google/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ java_binary(
2727
runtime_deps = [
2828
"//ruby/src/main/java:protobuf_java"
2929
],
30+
deploy_env = ["@rules_ruby//ruby/runtime:jruby_binary"],
3031
create_executable = False,
3132
)
3233

@@ -37,6 +38,7 @@ genrule(
3738
outs = ["protobuf_java.jar"],
3839
cmd = "cp $< $@",
3940
tags = ["manual"],
41+
visibility = ["//ruby:__subpackages__"],
4042
)
4143

4244
ruby_library(

0 commit comments

Comments
 (0)