Skip to content

Commit

Permalink
[ObjC] Flip the default for two generation options.
Browse files Browse the repository at this point in the history
- `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
  • Loading branch information
thomasvl authored and Copybara-Service committed Aug 24, 2023
1 parent ff1da69 commit 08bbb57
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
6 changes: 4 additions & 2 deletions src/google/protobuf/compiler/objectivec/generator.cc
Expand Up @@ -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;
Expand Down
14 changes: 6 additions & 8 deletions src/google/protobuf/compiler/objectivec/options.h
Expand Up @@ -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;
};

Expand Down

0 comments on commit 08bbb57

Please sign in to comment.