Skip to content
Merged
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
32 changes: 32 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,38 @@ jobs:
- run: echo ${{ matrix.ruby }} > .ruby-version
- run: ./do_test

examples-proto:
name: Examples / Proto
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
ruby:
- 3.4.5
os:
- ubuntu-latest
- macos-latest
# Fails with an error on the grpc gem:
# linking shared-object grpc/grpc_c.so
# D:/_bazel/external/rules_ruby++ruby+ruby/dist/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/15.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
# cannot find -lx64-ucrt-ruby340: No such file or directory
# D:/_bazel/external/rules_ruby++ruby+ruby/dist/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/15.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
# have you installed the static version of the x64-ucrt-ruby340 library ?
# - windows-latest
defaults:
run:
working-directory: examples/proto
steps:
- uses: actions/checkout@v5
- uses: bazel-contrib/setup-bazel@0.15.0
with:
# Move autoload_externally to .bazelrc once Bazel 6 support is dropped.
bazelrc: common --announce_rc --incompatible_autoload_externally=
module-root: examples/proto
repository-cache: true
- run: echo ${{ matrix.ruby }} > .ruby-version
- run: bazel build app

release:
name: Release
if: startsWith(github.ref, 'refs/tags/v')
Expand Down
3 changes: 3 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ bazel_dep(name = "platforms", version = "0.0.5")
bazel_dep(name = "rules_cc", version = "0.0.9")
bazel_dep(name = "rules_java", version = "7.2.0")

# NB: LOWER BOUND on earliest BCR release of protobuf module, to avoid upgrading the root module by accident
bazel_dep(name = "protobuf", version = "3.19.6")
Comment thread
alexeagle marked this conversation as resolved.

# Ruleset development dependencies.
bazel_dep(name = "aspect_bazel_lib", version = "2.21.2", dev_dependency = True)
bazel_dep(name = "bazel_skylib_gazelle_plugin", version = "1.8.2", dev_dependency = True)
Expand Down
5 changes: 5 additions & 0 deletions docs/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ stardoc_with_diff_test(
bzl_library_target = "//rails:rails_test_factory",
)

stardoc_with_diff_test(
name = "proto",
bzl_library_target = "//ruby:proto",
)

update_docs(name = "update")
28 changes: 28 additions & 0 deletions docs/proto.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions examples/proto/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
common --@protobuf//bazel/toolchains:prefer_prebuilt_protoc
common --repo_env="JAVA_HOME=../bazel_tools/jdk"
1 change: 1 addition & 0 deletions examples/proto/.ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.4.1
Empty file added examples/proto/BUILD
Empty file.
5 changes: 5 additions & 0 deletions examples/proto/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source "https://rubygems.org"

gem 'google-protobuf'
gem 'grpc'
gem 'grpc-tools'
81 changes: 81 additions & 0 deletions examples/proto/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
GEM
remote: https://rubygems.org/
specs:
bigdecimal (4.0.1)
google-protobuf (4.33.4)
bigdecimal
rake (>= 13)
google-protobuf (4.33.4-aarch64-linux-gnu)
bigdecimal
rake (>= 13)
google-protobuf (4.33.4-aarch64-linux-musl)
bigdecimal
rake (>= 13)
google-protobuf (4.33.4-arm64-darwin)
bigdecimal
rake (>= 13)
google-protobuf (4.33.4-x86-linux-gnu)
bigdecimal
rake (>= 13)
google-protobuf (4.33.4-x86-linux-musl)
bigdecimal
rake (>= 13)
google-protobuf (4.33.4-x86_64-darwin)
bigdecimal
rake (>= 13)
google-protobuf (4.33.4-x86_64-linux-gnu)
bigdecimal
rake (>= 13)
google-protobuf (4.33.4-x86_64-linux-musl)
bigdecimal
rake (>= 13)
googleapis-common-protos-types (1.22.0)
google-protobuf (~> 4.26)
grpc (1.76.0)
google-protobuf (>= 3.25, < 5.0)
googleapis-common-protos-types (~> 1.0)
grpc (1.76.0-aarch64-linux-gnu)
google-protobuf (>= 3.25, < 5.0)
googleapis-common-protos-types (~> 1.0)
grpc (1.76.0-aarch64-linux-musl)
google-protobuf (>= 3.25, < 5.0)
googleapis-common-protos-types (~> 1.0)
grpc (1.76.0-arm64-darwin)
google-protobuf (>= 3.25, < 5.0)
googleapis-common-protos-types (~> 1.0)
grpc (1.76.0-x86-linux-gnu)
google-protobuf (>= 3.25, < 5.0)
googleapis-common-protos-types (~> 1.0)
grpc (1.76.0-x86-linux-musl)
google-protobuf (>= 3.25, < 5.0)
googleapis-common-protos-types (~> 1.0)
grpc (1.76.0-x86_64-darwin)
google-protobuf (>= 3.25, < 5.0)
googleapis-common-protos-types (~> 1.0)
grpc (1.76.0-x86_64-linux-gnu)
google-protobuf (>= 3.25, < 5.0)
googleapis-common-protos-types (~> 1.0)
grpc (1.76.0-x86_64-linux-musl)
google-protobuf (>= 3.25, < 5.0)
googleapis-common-protos-types (~> 1.0)
grpc-tools (1.76.0)
rake (13.3.1)

PLATFORMS
aarch64-linux-gnu
aarch64-linux-musl
arm64-darwin
ruby
x86-linux-gnu
x86-linux-musl
x86_64-darwin
x86_64-linux-gnu
x86_64-linux-musl

DEPENDENCIES
google-protobuf
grpc
grpc-tools

BUNDLED WITH
2.6.2
54 changes: 54 additions & 0 deletions examples/proto/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
bazel_dep(name = "rules_ruby")
bazel_dep(name = "protobuf", version = "3.19.6")
bazel_dep(
name = "aspect_bazel_lib",
version = "2.22.5",
# repo_name = None (we don't dep on this but need a newer version)
)

local_path_override(
module_name = "rules_ruby",
path = "../..",
)

ruby = use_extension("@rules_ruby//ruby:extensions.bzl", "ruby")
ruby.toolchain(
name = "ruby",
version_file = "//:.ruby-version",
)
use_repo(ruby, "ruby", "ruby_toolchains")

register_toolchains("@ruby_toolchains//:all")

ruby.bundle_fetch(
name = "bundle",
gem_checksums = {
"bigdecimal-4.0.1": "8b07d3d065a9f921c80ceaea7c9d4ae596697295b584c296fe599dd0ad01c4a7",
"google-protobuf-4.33.4": "86921935b023ed0d872d6e84382e79016c91689be0520d614c74426778f13c16",
"google-protobuf-4.33.4-aarch64-linux-gnu": "7b091ec8a80520738a4dbff59458e2a7ed4304d7fc20fd779b3d019ff52fbead",
"google-protobuf-4.33.4-aarch64-linux-musl": "c017371e6fe8144285a3dd5d1ae2776f92892f7455bea26537f0f3072b6d894c",
"google-protobuf-4.33.4-arm64-darwin": "63bb57e3d7108986f961546a536adaa38bd9ab5b1ebc39a1741a16c6eba3e869",
"google-protobuf-4.33.4-x86-linux-gnu": "c54fab97506b79d6c7857d2caf373df5428c4f318fcffcd7acddc4ee29af383f",
"google-protobuf-4.33.4-x86-linux-musl": "6e9a67b83e70090f72b65b4386b9273f460cf4f4d6cba61f3b4817bb3b416c97",
"google-protobuf-4.33.4-x86_64-darwin": "72906abcb572b324eba760b0abdbb827ab781b8e26f718fa3f7f49485295c8d3",
"google-protobuf-4.33.4-x86_64-linux-gnu": "a8cff953d742bc804ece78bd96e82d88cf65a7d8c1910e045359e2f53074e55d",
"google-protobuf-4.33.4-x86_64-linux-musl": "265e6e5bbcc0ba1367268739e31c4cc84ff310b56e8d738d2a3245b5cccfc2e7",
"googleapis-common-protos-types-1.22.0": "f97492b77bd6da0018c860d5004f512fe7cd165554d7019a8f4df6a56fbfc4c7",
"grpc-1.76.0": "112416fa42153aee440fd1b975de4b2bf746656df071bace97c197a6b5575598",
"grpc-1.76.0-aarch64-linux-gnu": "25159422ade5690adc1cbefac0d102395378d5aadf143817611e7bd08de06eff",
"grpc-1.76.0-aarch64-linux-musl": "38ecb67c40ee550723a38d9dfdf676d8d21d81429a5144ce7b78ae896f2e8e53",
"grpc-1.76.0-arm64-darwin": "c23f30c2e6a51bb75d8f617b028453e66e09665d8bf571d99c7be1b1f9dd2b59",
"grpc-1.76.0-x86-linux-gnu": "ccd532d55c23e5e8973d86051092d87ce0754b668d4606d4666e36d5db0c6187",
"grpc-1.76.0-x86-linux-musl": "511a111389d2cbbfef153fa3a0259a535bb87ba231088feb775c9098e19eb7c3",
"grpc-1.76.0-x86_64-darwin": "60a70eb9c0660d6ea2d79aad26c9aac696b34c3ece36200f292f669d16283bec",
"grpc-1.76.0-x86_64-linux-gnu": "1561c852903617acae0a9ef9011bcf313054ba65c5528519b002a9f6b4d5c024",
"grpc-1.76.0-x86_64-linux-musl": "b942a6ae0828e0e696ce26d8b797167314ae7633810c41dd09b45c2176f966cd",
"grpc-tools-1.76.0": "1b943edf89fd5d125c3476d657b4d89ac85adc6144c5e00a10ed750631f1228e",
"rake-13.3.1": "8c9e89d09f66a26a01264e7e3480ec0607f0c497a861ef16063604b1b08eb19c",
},
gemfile = "//:Gemfile",
gemfile_lock = "//:Gemfile.lock",
)
use_repo(ruby, "bundle")

register_toolchains("//tools/toolchains:all")
11 changes: 11 additions & 0 deletions examples/proto/app/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
load("@rules_ruby//ruby:defs.bzl", "rb_binary")

rb_binary(
name = "app",
srcs = ["hello.rb"],
main = "hello.rb",
deps = [
"//proto:foo_proto",
"@bundle",
],
)
22 changes: 22 additions & 0 deletions examples/proto/app/hello.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# TODO: is there a ruby runfiles helper?
runfiles_dir = ENV["RUNFILES_DIR"]
if runfiles_dir
main_root = File.join(runfiles_dir, "_main")
$LOAD_PATH.unshift(main_root) if Dir.exist?(main_root) && !$LOAD_PATH.include?(main_root)
end

require "grpc"
require "proto/foo_pb"
require "proto/foo_services_pb"

class FooServer < Foo::FooService::Service
def get_foo(_req, _call)
Foo::GetFooResponse.new(name: "Hello from Bazel + Ruby gRPC server!")
end
end

server = GRPC::RpcServer.new
server.add_http2_port("0.0.0.0:50051", :this_port_is_insecure)
server.handle(FooServer.new)
puts "gRPC server listening on 0.0.0.0:50051"
server.run_till_terminated
8 changes: 8 additions & 0 deletions examples/proto/proto/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
load("@protobuf//bazel:proto_library.bzl", "proto_library")

proto_library(
name = "foo_proto",
srcs = ["foo.proto"],
visibility = ["//visibility:public"],
deps = ["@protobuf//:empty_proto"],
)
16 changes: 16 additions & 0 deletions examples/proto/proto/foo.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
syntax = "proto3";

package foo;
import "google/protobuf/empty.proto";

service FooService {
rpc GetFoo(GetFooRequest) returns (GetFooResponse);
}

message GetFooRequest {
google.protobuf.Empty empty = 1;
}

message GetFooResponse {
string name = 1;
}
9 changes: 9 additions & 0 deletions examples/proto/tools/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
load("@rules_ruby//ruby:defs.bzl", "rb_binary")

package(default_visibility = ["//visibility:public"])

rb_binary(
name = "grpc_tools_ruby_protoc_plugin",
main = "@bundle//bin:grpc_tools_ruby_protoc_plugin",
deps = ["@bundle"],
)
6 changes: 6 additions & 0 deletions examples/proto/tools/toolchains/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
load("@rules_ruby//ruby:proto.bzl", "rb_grpc_protoc_plugin_toolchain")

rb_grpc_protoc_plugin_toolchain(
name = "grpc_protoc_plugin",
grpc_plugin = "//tools:grpc_tools_ruby_protoc_plugin",
)
1 change: 1 addition & 0 deletions examples/rails/.bazelversion
19 changes: 12 additions & 7 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:recommended"
":dependencyDashboard",
":enablePreCommit",
":semanticPrefixFixDepsChoreOthers",
"group:monorepos",
"group:recommended",
"replacements:all",
"workarounds:all"
],
"ignoreDeps": [
"bazel_features",
"bazel_skylib",
"platforms",
"rules_cc",
"rules_java"
"packageRules": [
{
"matchFiles": ["MODULE.bazel"],
"enabled": false
}
]
}
14 changes: 14 additions & 0 deletions ruby/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ toolchain_type(
visibility = ["//visibility:public"],
)

toolchain_type(
name = "ruby_grpc_protoc_plugin.toolchain_type",
visibility = ["//visibility:public"],
)

bzl_library(
name = "defs",
srcs = ["defs.bzl"],
Expand Down Expand Up @@ -44,6 +49,15 @@ bzl_library(
],
)

bzl_library(
name = "proto",
srcs = ["proto.bzl"],
deps = [
"//ruby/private:proto",
"@protobuf//bazel/toolchains:proto_lang_toolchain_bzl",
],
)

bzl_library(
name = "toolchain",
srcs = ["toolchain.bzl"],
Expand Down
15 changes: 14 additions & 1 deletion ruby/private/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,20 @@ bzl_library(
name = "library",
srcs = ["library.bzl"],
visibility = ["//ruby:__subpackages__"],
deps = [":providers"],
deps = [
":proto",
":providers",
],
)

bzl_library(
name = "proto",
srcs = ["proto.bzl"],
visibility = ["//ruby:__subpackages__"],
deps = [
":providers",
"@protobuf//bazel/common:proto_info_bzl",
],
)

bzl_library(
Expand Down
Loading
Loading