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
2 changes: 1 addition & 1 deletion async-grpc-xds.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
"source_code_uri" => "https://github.com/socketry/async-grpc-xds.git",
}

spec.files = Dir.glob(["{context,lib,proto,xds}/**/*", "*.md"], File::FNM_DOTMATCH, base: __dir__)
spec.files = Dir.glob(["{context,lib,proto}/**/*", "*.md"], File::FNM_DOTMATCH, base: __dir__)

spec.required_ruby_version = ">= 3.3"

Expand Down
75 changes: 75 additions & 0 deletions bake.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,81 @@
# Released under the MIT License.
# Copyright, 2025-2026, by Samuel Williams.

require "fileutils"
require "tmpdir"

PROTOBUF_SOURCES = {
"envoy" => ["https://github.com/envoyproxy/data-plane-api.git", "84e84367f2560cdb47b9bb78fd3e615feb80c3e4"],
"google/protobuf" => ["https://github.com/protocolbuffers/protobuf.git", "68cb3eaca7cf86ee8eec7e1b54523643fd6aa344", "src"],
"google/rpc" => ["https://github.com/googleapis/api-common-protos.git", "3332dec527759859840a3a2ff108c67a54708130"],
"xds" => ["https://github.com/cncf/xds.git", "dba9d589def2cd10099a3a64887d859188c2f57a"],
"udpa" => ["https://github.com/cncf/udpa.git", "c52dc94e7fbe6449d8465faaeda22c76ca62d4ff"],
"validate" => ["https://github.com/envoyproxy/protoc-gen-validate.git", "414042a5ff2e98dc47f8161937316a25b1da5bba"],
}.freeze

# Update the vendored protobuf definitions from pinned upstream revisions and regenerate their Ruby classes.
#
# @parameter proto_dir [String] The directory containing vendored protobuf definitions.
# @parameter output_dir [String] The directory containing generated Ruby classes.
def update_protos(proto_dir: "proto", output_dir: "lib")
proto_dir = File.expand_path(proto_dir)
files = Dir.glob(File.join(proto_dir, "**/*.proto"))

Dir.mktmpdir("async-grpc-xds-protos") do |temporary_root|
repositories = {}

PROTOBUF_SOURCES.each_value do |url, revision, source_root|
repository = File.join(temporary_root, repositories.size.to_s)
system("git", "init", "--quiet", repository) or raise "Could not initialize a repository for #{url}!"
system("git", "-C", repository, "remote", "add", "origin", url) or raise "Could not configure #{url}!"
system("git", "-C", repository, "fetch", "--quiet", "--depth", "1", "origin", revision) or raise "Could not fetch #{revision} from #{url}!"
system("git", "-C", repository, "checkout", "--quiet", "FETCH_HEAD") or raise "Could not check out #{revision} from #{url}!"

repositories[url] = File.join(repository, source_root.to_s)
end

files.each do |destination|
relative_path = destination.delete_prefix("#{proto_dir}/")
prefix, source = PROTOBUF_SOURCES.find{|prefix, _source| relative_path.start_with?("#{prefix}/")}
raise "No upstream source for #{relative_path}!" unless source

url = source.first
source_path = File.join(repositories.fetch(url), relative_path)
raise "Could not find #{relative_path} in #{url}!" unless File.file?(source_path)

FileUtils.cp(source_path, destination)
end
end

{
updated: files.size,
sources: PROTOBUF_SOURCES.transform_values{|_url, revision, _source_root| revision},
generated: generate_protos(proto_dir: proto_dir, output_dir: output_dir),
}
end

# Generate the checked-in Ruby classes from the vendored protobuf definitions.
#
# @parameter proto_dir [String] The directory containing vendored protobuf definitions.
# @parameter output_dir [String] The output directory for generated Ruby classes.
def generate_protos(proto_dir: "proto", output_dir: "lib")
proto_dir = File.expand_path(proto_dir)
output_dir = File.expand_path(output_dir)

files = Dir.glob(File.join(output_dir, "**/*_pb.rb")).map do |path|
relative_path = path.delete_prefix("#{output_dir}/").sub(/_pb\.rb\z/, ".proto")
File.join(proto_dir, relative_path)
end

missing = files.reject{|path| File.file?(path)}
raise "Missing protobuf definitions: #{missing.join(', ')}" unless missing.empty?

FileUtils.mkdir_p(output_dir)
system("protoc", "--ruby_out=#{output_dir}", "--proto_path=#{proto_dir}", *files) or raise "Could not generate Ruby protobuf classes!"

files.size
end

# Update the project documentation with the new version number.
#
# @parameter version [String] The new version number.
Expand Down
126 changes: 0 additions & 126 deletions bake/async/grpc/xds.rb

This file was deleted.

32 changes: 8 additions & 24 deletions proto/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,45 +25,29 @@ These files come from [envoyproxy/data-plane-api](https://github.com/envoyproxy/
To update these files, run:

```bash
./xds/update_protos.sh
bundle exec bake update_protos
```

Or manually:

```bash
# Clone envoy data-plane-api
git clone --depth 1 https://github.com/envoyproxy/data-plane-api.git /tmp/envoy-api

# Copy needed files
cp -r /tmp/envoy-api/envoy proto/
cp -r /tmp/envoy-api/google proto/

# Cleanup
rm -rf /tmp/envoy-api
```
This fetches the pinned upstream revisions defined in `bake.rb`, updates the vendored definitions, and regenerates the checked-in Ruby classes.

## Generating Ruby Code

After updating proto files, generate Ruby classes:

```bash
bundle exec bake async:grpc:xds:generate_protos
bundle exec bake generate_protos
```

## Version

These files are from the latest `main` branch of:
The source repositories and revisions are defined by `PROTOBUF_SOURCES` in `bake.rb`. They include:

- `envoyproxy/data-plane-api` - Envoy API definitions
- `protocolbuffers/protobuf` - Google protobuf well-known types
- `googleapis/api-common-protos` - Google RPC status

To lock to a specific version, modify `xds/update_protos.sh` to check out specific tags:

```bash
cd /tmp/envoy-api
git checkout v1.30.0 # Use specific Envoy version
# Then copy files
```
- `cncf/xds` - xDS API definitions
- `cncf/udpa` - UDPA annotations
- `envoyproxy/protoc-gen-validate` - Validation annotations

## Note on Dependencies

Expand Down
123 changes: 0 additions & 123 deletions xds/update_protos.sh

This file was deleted.

Loading