Skip to content

Commit 08bbb57

Browse files
thomasvlcopybara-github
authored andcommitted
[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
1 parent ff1da69 commit 08bbb57

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/google/protobuf/compiler/objectivec/generator.cc

+4-2
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,12 @@ bool ObjectiveCGenerator::GenerateAll(
319319
}
320320
}
321321

322-
// Multi source generation forces off the use of fwd decls in favor of
323-
// imports.
322+
// Multi source generation forces:
323+
// - off the use of fwd decls in favor of imports
324+
// - on the minimal imports support
324325
if (generation_options.experimental_multi_source_generation) {
325326
generation_options.headers_use_forward_declarations = false;
327+
generation_options.generate_minimal_imports = true;
326328
}
327329
if (generation_options.experimental_strip_nonfunctional_codegen) {
328330
generation_options.generate_minimal_imports = true;

src/google/protobuf/compiler/objectivec/options.h

+6-8
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,14 @@ struct GenerationOptions {
4343
std::string generate_for_named_framework;
4444
std::string named_framework_to_proto_path_mappings_path;
4545
std::string runtime_import_prefix;
46-
// TODO(thomasvl): Eventually flip this default to false for better interop
47-
// with Swift if proto usages span modules made from ObjC sources.
48-
bool headers_use_forward_declarations = true;
49-
// TODO(thomasvl): Removing this so there is one less path to validate in
50-
// code generation.
46+
47+
bool headers_use_forward_declarations = false;
5148
bool strip_custom_options = true;
52-
// TODO(thomasvl): Eventually flip this default to true.
53-
bool generate_minimal_imports = false;
49+
bool generate_minimal_imports = true;
50+
51+
// These are experiments that are not officially supported. They can change
52+
// in behavior or go away at any time.
5453
bool experimental_multi_source_generation = false;
55-
// This is used by some of the protobuf infrastructure.
5654
bool experimental_strip_nonfunctional_codegen = false;
5755
};
5856

0 commit comments

Comments
 (0)