[ObjC] Flip the default for two generation options.

- `generate_minimal_imports` is now `yes`, this reduces the imports generated
into the generated source.

- `headers_use_forward_declarations` is now `no`; this causes the generated
.pbobj.h files to directly import all the headers needed to define types used by
this types defined in the file. This provides better compatibility for Swift
interop especially when the ObjC protos are used in multiple libraries as
forward declarations can cause issues for importing into Swift.

If you need to override either options, please open an issue on github to report
the reason. A future release of the library will remove these options locking in
the new behaviors.

PiperOrigin-RevId: 559737716
pull/13633/head
Thomas Van Lenten 1 year ago committed by Copybara-Service
parent ff1da698eb
commit 08bbb577e8
  1. 6
      src/google/protobuf/compiler/objectivec/generator.cc
  2. 14
      src/google/protobuf/compiler/objectivec/options.h

@ -319,10 +319,12 @@ bool ObjectiveCGenerator::GenerateAll(
}
}
// Multi source generation forces off the use of fwd decls in favor of
// imports.
// Multi source generation forces:
// - off the use of fwd decls in favor of imports
// - on the minimal imports support
if (generation_options.experimental_multi_source_generation) {
generation_options.headers_use_forward_declarations = false;
generation_options.generate_minimal_imports = true;
}
if (generation_options.experimental_strip_nonfunctional_codegen) {
generation_options.generate_minimal_imports = true;

@ -43,16 +43,14 @@ struct GenerationOptions {
std::string generate_for_named_framework;
std::string named_framework_to_proto_path_mappings_path;
std::string runtime_import_prefix;
// TODO(thomasvl): Eventually flip this default to false for better interop
// with Swift if proto usages span modules made from ObjC sources.
bool headers_use_forward_declarations = true;
// TODO(thomasvl): Removing this so there is one less path to validate in
// code generation.
bool headers_use_forward_declarations = false;
bool strip_custom_options = true;
// TODO(thomasvl): Eventually flip this default to true.
bool generate_minimal_imports = false;
bool generate_minimal_imports = true;
// These are experiments that are not officially supported. They can change
// in behavior or go away at any time.
bool experimental_multi_source_generation = false;
// This is used by some of the protobuf infrastructure.
bool experimental_strip_nonfunctional_codegen = false;
};

Loading…
Cancel
Save