-
Notifications
You must be signed in to change notification settings - Fork 487
Add Prost and Tonic rules. #2033
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
Changes from 17 commits
6cb92b2
2c6d472
fced3e7
09d8142
c1f3d99
a603dc2
cb0ab09
a1714e1
f3ccc01
a58749c
d7e7312
d67c839
e03d107
e901991
c4fe6aa
0f80615
2870e43
6554778
7e82121
00682b3
6ceafbb
e848353
3c91f2c
e08d9ad
d3ea3d7
74e5b08
9bd48e1
b9b2872
5d64e3c
38b9989
7ac0bd1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,5 +48,6 @@ bzl_library( | |
srcs = glob(["**/*.bzl"]), | ||
deps = [ | ||
"//proto/3rdparty:bzl_lib", | ||
"//proto/prost:bzl_lib", | ||
], | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
"""Rust proto rules.""" | ||
|
||
load( | ||
"//proto/prost:defs.bzl", | ||
_rust_prost_library = "rust_prost_library", | ||
_rust_tonic_library = "rust_tonic_library", | ||
) | ||
load( | ||
":proto.bzl", | ||
_rust_grpc_library = "rust_grpc_library", | ||
_rust_proto_library = "rust_proto_library", | ||
) | ||
|
||
rust_proto_library = _rust_proto_library | ||
rust_grpc_library = _rust_grpc_library | ||
|
||
rust_prost_library = _rust_prost_library | ||
rust_tonic_library = _rust_tonic_library |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
load("@bazel_skylib//:bzl_library.bzl", "bzl_library") | ||
load("//rust:defs.bzl", "rust_library_group") | ||
load(":defs.bzl", "rust_prost_toolchain") | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
toolchain_type( | ||
name = "toolchain_type", | ||
) | ||
|
||
rust_library_group( | ||
name = "prost_runtime", | ||
deps = [ | ||
"//proto/prost/private/3rdparty/crates:prost", | ||
], | ||
) | ||
|
||
rust_library_group( | ||
name = "tonic_runtime", | ||
deps = [ | ||
":prost_runtime", | ||
"//proto/prost/private/3rdparty/crates:tonic", | ||
], | ||
) | ||
|
||
rust_prost_toolchain( | ||
name = "default_prost_toolchain_impl", | ||
prost_plugin = "//proto/prost/private/3rdparty/crates:protoc-gen-prost__protoc-gen-prost", | ||
prost_plugin_flag = "--plugin=protoc-gen-prost=%s", | ||
prost_runtime = ":prost_runtime", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure about providing a default toolchain with a rules_rust-private runtime... When trying this out in some of my private repos, I spent quite a while chasing "X doesn't implement trait Y" issues because of my copy of tonic and prost, despite being the same version numbers, being distinct libraries from the bundled ones, before eventually realising I needed to make and register my own toolchain. I suspect most of our users will need to specify their own toolchains for this reason, and given how inscrutible the errors are, I'd lean towards documenting this as a required step, and not supplying a default at all... WDYT? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, users should just define their own toolchain to avoid any of this confusion. I'll get this deleted. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I moved the toolchain into |
||
proto_compiler = "@com_google_protobuf//:protoc", | ||
tonic_plugin = "//proto/prost/private/3rdparty/crates:protoc-gen-tonic__protoc-gen-tonic", | ||
tonic_plugin_flag = "--plugin=protoc-gen-tonic=%s", | ||
tonic_runtime = ":tonic_runtime", | ||
) | ||
|
||
toolchain( | ||
name = "default_prost_toolchain_linux", | ||
target_compatible_with = [ | ||
"@platforms//os:linux", | ||
], | ||
toolchain = "default_prost_toolchain_impl", | ||
toolchain_type = "//proto/prost:toolchain_type", | ||
) | ||
|
||
toolchain( | ||
name = "default_prost_toolchain_osx", | ||
target_compatible_with = [ | ||
"@platforms//os:osx", | ||
], | ||
toolchain = "default_prost_toolchain_impl", | ||
toolchain_type = "//proto/prost:toolchain_type", | ||
) | ||
|
||
bzl_library( | ||
name = "bzl_lib", | ||
srcs = glob(["**/*.bzl"]), | ||
deps = [ | ||
"//proto/prost/private:bzl_lib", | ||
"//rust:bzl_lib", | ||
], | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
"""Rules for building proto libraries in Rust.""" | ||
|
||
load( | ||
"//proto/prost/private:prost.bzl", | ||
_rust_prost_library = "rust_prost_library", | ||
_rust_prost_toolchain = "rust_prost_toolchain", | ||
_rust_tonic_library = "rust_tonic_library", | ||
) | ||
|
||
def rust_prost_library(name, **kwargs): | ||
"""A rule for generating a Rust library using Prost. | ||
|
||
Args: | ||
name (str): The name of the target. | ||
**kwargs (dict): Additional keyword arguments for the underlying | ||
`rust_prost_library` rule. | ||
""" | ||
|
||
# Clippy and Rustfmt will attempt to run on these targets. | ||
# This is not correct and likely a bug in target detection. | ||
tags = kwargs.pop("tags", []) | ||
if "no-clippy" not in tags: | ||
tags.append("no-clippy") | ||
if "no-rustfmt" not in tags: | ||
tags.append("no-rustfmt") | ||
|
||
_rust_prost_library( | ||
name = name, | ||
tags = tags, | ||
**kwargs | ||
) | ||
|
||
def rust_tonic_library(name, **kwargs): | ||
"""A rule for generating a Rust library using Prost and Tonic. | ||
|
||
Args: | ||
name (str): The name of the target. | ||
**kwargs (dict): Additional keyword arguments for the underlying | ||
`rust_tonic_library` rule. | ||
""" | ||
|
||
# Clippy and Rustfmt will attempt to run on these targets. | ||
# This is not correct and likely a bug in target detection. | ||
tags = kwargs.pop("tags", []) | ||
if "no-clippy" not in tags: | ||
tags.append("no-clippy") | ||
if "no-rustfmt" not in tags: | ||
tags.append("no-rustfmt") | ||
|
||
_rust_tonic_library( | ||
name = name, | ||
tags = tags, | ||
**kwargs | ||
) | ||
|
||
rust_prost_toolchain = _rust_prost_toolchain |
Uh oh!
There was an error while loading. Please reload this page.