Skip to content

Commit 443e3c7

Browse files
chore: generate protobuf rbs (#414)
* otel regression test * fix: address hidden steep issues * test: place steep ignore on block pass * chore: generate protobuf rbs
1 parent b516d11 commit 443e3c7

88 files changed

Lines changed: 44631 additions & 512 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,10 @@ jobs:
5959
with:
6060
go-version: stable
6161

62-
# Needed because gRPC tools does not have a macOS protoc binary
63-
# currently, see https://github.com/grpc/grpc/issues/25755
64-
- name: Install protoc for mac
65-
if: ${{ matrix.os == 'macos-latest' }}
62+
- name: Install protoc
6663
uses: arduino/setup-protoc@v3
6764
with:
68-
version: "23.x"
65+
version: "34.x"
6966
repo-token: ${{ secrets.GITHUB_TOKEN }}
7067

7168
- name: Install bundle
@@ -76,8 +73,7 @@ jobs:
7673
if: ${{ matrix.checkTarget }}
7774
working-directory: ./temporalio
7875
run: |
79-
bundle exec rake proto:generate
80-
[[ -z $(git status --porcelain lib/temporalio/api) ]] || (git diff lib/temporalio/api; echo "Protos changed" 1>&2; exit 1)
76+
bundle exec rake proto:check_generated
8177
8278
- name: Lint, compile, test Ruby
8379
working-directory: ./temporalio

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,6 +1333,7 @@ Prerequisites:
13331333

13341334
* [Ruby](https://www.ruby-lang.org/) >= 3.2 (i.e. `ruby` and `bundle` on the `PATH`)
13351335
* [Rust](https://www.rust-lang.org/) latest stable (i.e. `cargo` on the `PATH`)
1336+
* [protoc](https://protobuf.dev/installation/) >= 34.0 (i.e. `protoc` on the `PATH`)
13361337
* This repository, cloned recursively
13371338
* Change to the `temporalio/` directory
13381339

@@ -1416,3 +1417,6 @@ Now can run `steep`:
14161417
Run:
14171418

14181419
bundle exec rake proto:generate
1420+
1421+
`proto:generate` now requires `protoc >= 34.0` because we generate RBS alongside the generated Ruby
1422+
protobuf files.

temporalio/Gemfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ group :development do
1010
gem 'async'
1111
gem 'base64'
1212
gem 'googleapis-common-protos-types'
13-
gem 'grpc-tools', '~> 1.69'
1413
gem 'irb'
1514
gem 'minitest'
1615
# Have to explicitly depend on openssl for macos issue in GH CI described at

temporalio/Rakefile

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,6 @@ Rake::TestTask.new(:test) do |t|
2727
t.test_files = FileList['test/**/*_test.rb']
2828
end
2929

30-
def add_protoc_to_path
31-
tools_spec = Gem::Specification.find_by_name('grpc-tools')
32-
cpu = RbConfig::CONFIG['host_cpu']
33-
cpu = 'x86_64' if cpu == 'x64'
34-
os = RbConfig::CONFIG['host_os']
35-
os = 'windows' if os.start_with?('mingw')
36-
protoc_path = "#{tools_spec.gem_dir}/bin/#{cpu}-#{os}"
37-
separator = os == 'windows' ? ';' : ':'
38-
ENV['PATH'] = "#{ENV.fetch('PATH', nil)}#{separator}#{protoc_path}"
39-
end
40-
41-
add_protoc_to_path
42-
4330
require 'rubocop/rake_task'
4431

4532
RuboCop::RakeTask.new
@@ -75,6 +62,18 @@ namespace :proto do
7562
require_relative 'extra/proto_gen'
7663
ProtoGen.new.run
7764
end
65+
66+
desc 'Fail if checked-in generated proto files are out of date'
67+
task check_generated: :generate do
68+
require_relative 'extra/proto_gen'
69+
proto_generated_paths = ProtoGen.generated_paths
70+
71+
changed_paths = IO.popen(['git', 'status', '--porcelain', '--', *proto_generated_paths], &:read)
72+
next if changed_paths.empty?
73+
74+
sh 'git', 'diff', '--', *proto_generated_paths
75+
raise 'Protos changed'
76+
end
7877
end
7978

8079
namespace :rbs do

temporalio/Steepfile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
D = Steep::Diagnostic
44

55
common_diagnostics = {
6-
# TODO(cretz): Needed because lack of proto RBS, waiting on https://github.com/protocolbuffers/protobuf/pull/15633
7-
D::Ruby::UnknownConstant => :information,
8-
96
# Steep >= 1.9 started becoming too noisy in these cases
107
D::Ruby::UnannotatedEmptyCollection => :information,
118
D::Ruby::UndeclaredMethodDefinition => :information
@@ -14,7 +11,6 @@ common_diagnostics = {
1411
target :lib do
1512
signature 'sig'
1613
check 'lib'
17-
ignore 'lib/temporalio/api', 'lib/temporalio/internal/bridge/api'
1814
library 'uri', 'objspace', 'etc'
1915
configure_code_diagnostics do |hash|
2016
hash.update(common_diagnostics)
@@ -27,6 +23,7 @@ target :test do
2723
library 'uri', 'objspace', 'etc'
2824
configure_code_diagnostics do |hash|
2925
hash.update(common_diagnostics)
26+
hash[D::Ruby::UnknownConstant] = :information
3027
# Steep cannot infer some things, so we can ignore them in tests
3128
hash[D::Ruby::InsufficientKeywordArguments] = :information
3229
end

temporalio/extra/payload_visitor_gen.rb

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,7 @@ class PayloadVisitorGen
2121
#
2222
# @return [String] File code.
2323
def gen_file_code
24-
# Collect all the methods of all the classes
25-
methods = {}
26-
DESCRIPTORS.each do |name|
27-
desc = Google::Protobuf::DescriptorPool.generated_pool.lookup(name) or raise "Unknown name: #{name}"
28-
walk_desc(desc:, methods:)
29-
end
24+
methods = payload_methods
3025

3126
# Build the code for each method
3227
method_bodies = methods.map do |_, method_hash|
@@ -108,7 +103,7 @@ def initialize(
108103
# @param value [Google::Protobuf::Message] Message to visit.
109104
def run(value)
110105
return unless value.is_a?(Google::Protobuf::MessageExts)
111-
method_name = method_name_from_proto_name(value.class.descriptor.name)
106+
method_name = method_name_from_proto_name(value.class.descriptor.name) # steep:ignore NoMethod
112107
send(method_name, value) if respond_to?(method_name, true)
113108
nil
114109
end
@@ -158,8 +153,54 @@ def google_protobuf_any(value)
158153
TEXT
159154
end
160155

156+
# Generate file signature.
157+
#
158+
# @return [String] File signature.
159+
def gen_rbs_code
160+
method_defs = payload_methods.filter_map do |_, method_hash|
161+
next if method_hash[:fields].empty?
162+
163+
"def #{method_name_from_desc(method_hash[:desc])}: (untyped value) -> void"
164+
end.sort
165+
166+
<<~TEXT
167+
module Temporalio
168+
module Api
169+
class PayloadVisitor
170+
def initialize: (
171+
?on_enter: untyped,
172+
?on_exit: untyped,
173+
?skip_search_attributes: bool,
174+
?traverse_any: bool
175+
) { (untyped) -> untyped } -> void
176+
def run: (untyped value) -> nil
177+
def _run_activation: (untyped value) -> void
178+
def _run_activation_completion: (untyped value) -> void
179+
180+
private
181+
182+
def method_name_from_proto_name: (::String name) -> ::String
183+
def api_common_v1_payload: (untyped value) -> untyped
184+
def api_common_v1_payload_repeated: (untyped value) -> untyped
185+
def google_protobuf_any: (untyped value) -> void
186+
#{method_defs.join("\n ")}
187+
end
188+
end
189+
end
190+
TEXT
191+
end
192+
161193
private
162194

195+
def payload_methods
196+
methods = {}
197+
DESCRIPTORS.each do |name|
198+
desc = Google::Protobuf::DescriptorPool.generated_pool.lookup(name) or raise "Unknown name: #{name}"
199+
walk_desc(desc:, methods:)
200+
end
201+
methods
202+
end
203+
163204
def walk_desc(desc:, methods:)
164205
case desc
165206
when Google::Protobuf::ServiceDescriptor

0 commit comments

Comments
 (0)