Internal changes

PiperOrigin-RevId: 652892331
pull/17448/head
Mike Kruskal 7 months ago committed by Copybara-Service
parent 3bfa9b9784
commit 151ee45381
  1. 2
      editions/codegen_tests/BUILD
  2. 27
      editions/codegen_tests/rust_bazel_crate_mapping.txt
  3. 7
      src/google/protobuf/compiler/rust/context.cc
  4. 29
      src/google/protobuf/compiler/rust/context.h
  5. 2
      src/google/protobuf/compiler/rust/naming.cc

@ -1,7 +1,7 @@
load("//bazel:cc_proto_library.bzl", "cc_proto_library")
exports_files(
glob(["*.proto"]) + ["rust_bazel_crate_mapping.txt"],
glob(["*.proto"]),
visibility = [
"//editions:__pkg__",
],

@ -1,27 +0,0 @@
proto3_implicit_proto
1
third_party/protobuf/editions/codegen_tests/proto3_implicit.proto
proto2_optional_proto
1
third_party/protobuf/editions/codegen_tests/proto2_optional.proto
proto3_enum_proto
1
third_party/protobuf/editions/codegen_tests/proto3_enum.proto
struct
1
google/protobuf/struct.proto
wrappers
1
google/protobuf/wrappers.proto
duration
1
google/protobuf/duration.proto
timestamp
1
google/protobuf/timestamp.proto
field_mask
1
google/protobuf/field_mask.proto
any
1
google/protobuf/any.proto

@ -71,6 +71,13 @@ absl::StatusOr<Options> Options::Parse(absl::string_view param) {
opts.mapping_file_path = mapping_arg->second;
}
auto strip_nonfunctional_codegen_arg = absl::c_find_if(args, [](auto& arg) {
return arg.first == "experimental_strip_nonfunctional_codegen";
});
if (strip_nonfunctional_codegen_arg != args.end()) {
opts.strip_nonfunctional_codegen = true;
}
return opts;
}

@ -46,6 +46,7 @@ inline absl::string_view KernelRsName(Kernel kernel) {
struct Options {
Kernel kernel;
std::string mapping_file_path;
bool strip_nonfunctional_codegen = false;
static absl::StatusOr<Options> Parse(absl::string_view param);
};
@ -69,20 +70,12 @@ class RustGeneratorContext {
&f) != files_in_current_crate_.end();
}
absl::string_view ImportPathToCrateName(absl::string_view import_path) const {
auto it = import_path_to_crate_name_.find(import_path);
if (it == import_path_to_crate_name_.end()) {
ABSL_LOG(FATAL) << "Path " << import_path
<< " not found in crate mapping. Crate mapping has "
<< import_path_to_crate_name_.size() << " entries";
}
return it->second;
}
private:
const std::vector<const FileDescriptor*>& files_in_current_crate_;
const absl::flat_hash_map<std::string, std::string>&
import_path_to_crate_name_;
friend class Context;
};
// A context for generating a particular kind of definition.
@ -127,6 +120,22 @@ class Context {
printer_->Emit(vars, format, loc);
}
absl::string_view ImportPathToCrateName(absl::string_view import_path) const {
if (opts_->strip_nonfunctional_codegen) {
return "test";
}
auto it =
rust_generator_context_->import_path_to_crate_name_.find(import_path);
if (it == rust_generator_context_->import_path_to_crate_name_.end()) {
ABSL_LOG(FATAL)
<< "Path " << import_path
<< " not found in crate mapping. Crate mapping has "
<< rust_generator_context_->import_path_to_crate_name_.size()
<< " entries";
}
return it->second;
}
private:
const Options* opts_;
const RustGeneratorContext* rust_generator_context_;

@ -37,7 +37,7 @@ namespace compiler {
namespace rust {
std::string GetCrateName(Context& ctx, const FileDescriptor& dep) {
return RsSafeName(ctx.generator_context().ImportPathToCrateName(dep.name()));
return RsSafeName(ctx.ImportPathToCrateName(dep.name()));
}
std::string GetRsFile(Context& ctx, const FileDescriptor& file) {

Loading…
Cancel
Save