It's not yet possible to import any of the well-known types from a proto file in another crate. To enable this I think we'll need to generate a function that dependent crates can call to determine the directory that contains the well-known types. PiperOrigin-RevId: 706745114pull/19559/head
parent
4681c2bd96
commit
512319bc78
8 changed files with 90 additions and 4 deletions
@ -0,0 +1,38 @@ |
||||
load("@rules_pkg//pkg:mappings.bzl", "pkg_files", "strip_prefix") |
||||
load("@rules_pkg//pkg:tar.bzl", "pkg_tar") |
||||
load("//:protobuf_version.bzl", "PROTOBUF_RUST_VERSION") |
||||
|
||||
pkg_tar( |
||||
name = "crate", |
||||
srcs = [ |
||||
":crate_root_files", |
||||
":well_known_types", |
||||
"//:LICENSE", |
||||
], |
||||
visibility = ["//rust:__subpackages__"], |
||||
) |
||||
|
||||
pkg_files( |
||||
name = "crate_root_files", |
||||
srcs = [":srcs"], |
||||
strip_prefix = strip_prefix.from_root("rust/release_crates/protobuf_well_known_types"), |
||||
) |
||||
|
||||
genrule( |
||||
name = "gen_cargo_toml", |
||||
srcs = ["Cargo-template.toml"], |
||||
outs = ["Cargo.toml"], |
||||
cmd = "cat $(SRCS) | sed -e 's/{{VERSION}}/{0}-beta/g' > $(OUTS)".format(PROTOBUF_RUST_VERSION), |
||||
) |
||||
|
||||
filegroup( |
||||
name = "srcs", |
||||
srcs = [":gen_cargo_toml"] + glob(["**/*"]), |
||||
visibility = ["//rust:__subpackages__"], |
||||
) |
||||
|
||||
pkg_files( |
||||
name = "well_known_types", |
||||
srcs = ["//src/google/protobuf:well_known_type_protos"], |
||||
prefix = "proto/google/protobuf", |
||||
) |
@ -0,0 +1,12 @@ |
||||
[package] |
||||
name = "staging-protobuf-well-known-types" |
||||
version = "{VERSION}" |
||||
edition = "2021" |
||||
description = "Protobuf Well-Known Types" |
||||
license = "BSD-3-Clause" |
||||
|
||||
[dependencies] |
||||
protobuf = { version = "{VERSION}", path = "../protobuf", package = "staging-protobuf" } |
||||
|
||||
[build-dependencies] |
||||
protobuf-codegen = { version = "{VERSION}", path = "../protobuf_codegen", package = "staging-protobuf-codegen" } |
@ -0,0 +1,2 @@ |
||||
This crate contains the protobuf |
||||
[well-known types](https://protobuf.dev/reference/protobuf/google.protobuf/). |
@ -0,0 +1,20 @@ |
||||
use protobuf_codegen::CodeGen; |
||||
|
||||
fn main() { |
||||
CodeGen::new() |
||||
.inputs([ |
||||
"google/protobuf/any.proto", |
||||
"google/protobuf/api.proto", |
||||
"google/protobuf/duration.proto", |
||||
"google/protobuf/empty.proto", |
||||
"google/protobuf/field_mask.proto", |
||||
"google/protobuf/source_context.proto", |
||||
"google/protobuf/struct.proto", |
||||
"google/protobuf/timestamp.proto", |
||||
"google/protobuf/type.proto", |
||||
"google/protobuf/wrappers.proto", |
||||
]) |
||||
.include("proto") |
||||
.generate_and_compile() |
||||
.unwrap(); |
||||
} |
@ -0,0 +1 @@ |
||||
include!(concat!(env!("OUT_DIR"), "/protobuf_generated/google/protobuf/any.u.pb.rs")); |
Loading…
Reference in new issue