Depend on all deps of a proto_library, not just the first

The code this is fixing was not done properly. This CL fixes it.

PiperOrigin-RevId: 598832639
pull/15448/head
Marcel Hlopko 1 year ago committed by Copybara-Service
parent c12c96e194
commit 88d991d310
  1. 2
      rust/aspects.bzl
  2. 10
      rust/test/rust_proto_library_unit_test/parent2.proto
  3. 21
      rust/test/rust_proto_library_unit_test/rust_proto_library_unit_test.bzl
  4. 13
      src/google/protobuf/compiler/rust/generator.cc

@ -347,7 +347,7 @@ def _rust_proto_aspect_common(target, ctx, is_upb):
src = gencode[0],
extra_srcs = gencode[1:],
deps = [dep_variant_info_for_runtime, dep_variant_info_for_native_gencode] + (
[proto_deps[0][RustProtoInfo].dep_variant_info] if proto_deps else []
[d[RustProtoInfo].dep_variant_info for d in proto_deps]
),
)
return [RustProtoInfo(

@ -0,0 +1,10 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2023 Google LLC. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd
syntax = "proto2";
package third_party_protobuf_rust_test_rust_proto_library_unit_test;

@ -34,6 +34,9 @@ rust/test/rust_proto_library_unit_test/grandparent2.proto
parent_proto
1
rust/test/rust_proto_library_unit_test/parent.proto
parent2_proto
1
rust/test/rust_proto_library_unit_test/parent2.proto
"""
if crate_mapping_action.content != expected_content:
fail("The crate mapping file content didn't match. Was: {}".format(
@ -105,6 +108,10 @@ def _rust_upb_aspect_test_impl(ctx):
# The action needs to have the Rust runtime as an input
_find_rust_lib_input(rustc_action.inputs, "protobuf")
# The action needs to have rlibs for direct deps
_find_rust_lib_input(rustc_action.inputs, "parent")
_find_rust_lib_input(rustc_action.inputs, "parent2")
# The action needs to produce a .rlib artifact (sometimes .rmeta as well, not tested here).
asserts.true(env, rustc_action.outputs.to_list()[0].path.endswith(".rlib"))
@ -136,6 +143,10 @@ def _rust_cc_aspect_test_impl(ctx):
# The rustc action needs to have the Rust runtime as an input
_find_rust_lib_input(rustc_action.inputs, "protobuf")
# The action needs to have rlibs for direct deps
_find_rust_lib_input(rustc_action.inputs, "parent")
_find_rust_lib_input(rustc_action.inputs, "parent2")
# The action needs to produce a .rlib artifact (sometimes .rmeta as well, not tested here).
asserts.true(env, rustc_action.outputs.to_list()[0].path.endswith(".rlib"))
@ -166,12 +177,20 @@ def rust_proto_library_unit_test(name):
name = "grandparent_proto",
srcs = ["grandparent1.proto", "grandparent2.proto"],
)
native.proto_library(
name = "parent_proto",
srcs = ["parent.proto"],
deps = [":grandparent_proto"],
)
native.proto_library(name = "child_proto", srcs = ["child.proto"], deps = [":parent_proto"])
native.proto_library(name = "parent2_proto", srcs = ["parent2.proto"])
native.proto_library(
name = "child_proto",
srcs = ["child.proto"],
deps = [":parent_proto", ":parent2_proto"],
)
cc_proto_library(name = "child_cc_proto", deps = [":child_proto"])
_test_upb_aspect()

@ -14,7 +14,6 @@
#include "absl/algorithm/container.h"
#include "absl/container/btree_map.h"
#include "absl/container/flat_hash_map.h"
#include "absl/container/flat_hash_set.h"
#include "absl/memory/memory.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
@ -56,7 +55,7 @@ void EmitOpeningOfPackageModules(Context& ctx, absl::string_view pkg) {
ctx.Emit({{"segment", segment}},
R"rs(
#[allow(non_snake_case)]
pub mod $segment$ {
pub mod r#$segment$ {
)rs");
}
}
@ -79,7 +78,7 @@ void EmitClosingOfPackageModules(Context& ctx, absl::string_view pkg) {
for (absl::string_view segment : segments) {
ctx.Emit({{"segment", segment}}, R"rs(
} // mod $segment$
} // mod r#$segment$
)rs");
}
}
@ -95,17 +94,17 @@ void EmitPubUseOfOwnTypes(Context& ctx, const FileDescriptor& primary_file,
auto& msg = *non_primary_src.message_type(i);
ctx.Emit({{"mod", mod}, {"Msg", msg.name()}},
R"rs(
pub use crate::$mod$::$Msg$;
pub use crate::r#$mod$::$Msg$;
// TODO Address use for imported crates
pub use crate::$mod$::$Msg$View;
pub use crate::$mod$::$Msg$Mut;
pub use crate::r#$mod$::$Msg$View;
pub use crate::r#$mod$::$Msg$Mut;
)rs");
}
for (int i = 0; i < non_primary_src.enum_type_count(); ++i) {
auto& enum_ = *non_primary_src.enum_type(i);
ctx.Emit({{"mod", mod}, {"Enum", EnumRsName(enum_)}},
R"rs(
pub use crate::$mod$::$Enum$;
pub use crate::r#$mod$::$Enum$;
)rs");
}
}

Loading…
Cancel
Save