Skip to content

Commit bed8eb0

Browse files
committed
base the default behavior of UseAccessLevelOnImports on Swift version the protoc plugin is compiled with, update docs to explain interoperability of UseAccessLevelOnImports and ImplementationOnlyImports
1 parent 322f814 commit bed8eb0

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

Documentation/PLUGIN.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,19 +184,23 @@ this will only work if the `Visibility` is set to `internal`.
184184

185185
##### Generation Option: `UseAccessLevelOnImports` - imports preceded by a visibility modifier (`public`, `package`, `internal`)
186186

187-
By default, the code generator does not precede any imports with a visibility modifier.
188-
You can change this with the `UseAccessLevelOnImports` option:
187+
The default behavior depends on the Swift version the plugin is compiled with.
188+
For Swift versions below 6.0 the default is `false` and the code generator does not precede any imports with a visibility modifier.
189+
You can change this by explicitly setting the `UseAccessLevelOnImports` option:
189190

190191
```
191192
$ protoc --swift_opt=UseAccessLevelOnImports=[value] --swift_out=. foo/bar/*.proto mumble/*.proto
192193
```
193194

194195
The possible values for `UseAccessLevelOnImports` are:
195196

196-
* `false` (default): Generates plain import directives without a visibility modifier.
197+
* `false`: Generates plain import directives without a visibility modifier.
197198
* `true`: Imports of internal dependencies and any modules defined in the module
198199
mappings will be preceded by a visibility modifier corresponding to the visibility of the generated types - see `Visibility` option.
199200

201+
**Important:** It is strongly encouraged to use `internal` imports instead of `@_implementationOnly` imports.
202+
Hence `UseAccessLevelOnImports` and `ImplementationOnlyImports` options exclude each other.
203+
200204

201205
### Building your project
202206

Sources/protoc-gen-swift/Docs.docc/index.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,19 +190,23 @@ this will only work if the `Visibility` is set to `internal`.
190190

191191
##### Generation Option: `UseAccessLevelOnImports` - imports preceded by a visibility modifier (`public`, `package`, `internal`)
192192

193-
By default, the code generator does not precede any imports with a visibility modifier.
194-
You can change this with the `UseAccessLevelOnImports` option:
193+
The default behavior depends on the Swift version the plugin is compiled with.
194+
For Swift versions below 6.0 the default is `false` and the code generator does not precede any imports with a visibility modifier.
195+
You can change this by explicitly setting the `UseAccessLevelOnImports` option:
195196

196197
```
197198
$ protoc --swift_opt=UseAccessLevelOnImports=[value] --swift_out=. foo/bar/*.proto mumble/*.proto
198199
```
199200

200201
The possible values for `UseAccessLevelOnImports` are:
201202

202-
* `false` (default): Generates plain import directives without a visibility modifier.
203+
* `false`: Generates plain import directives without a visibility modifier.
203204
* `true`: Imports of internal dependencies and any modules defined in the module
204205
mappings will be preceded by a visibility modifier corresponding to the visibility of the generated types - see `Visibility` option.
205206

207+
**Important:** It is strongly encouraged to use `internal` imports instead of `@_implementationOnly` imports.
208+
Hence `UseAccessLevelOnImports` and `ImplementationOnlyImports` options exclude each other.
209+
206210

207211
### Building your project
208212

Sources/protoc-gen-swift/GeneratorOptions.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ class GeneratorOptions {
7979
var visibility: Visibility = .internal
8080
var swiftProtobufModuleName: String? = nil
8181
var implementationOnlyImports: Bool = false
82+
#if swift(>=6.0)
83+
var useAccessLevelOnImports = true
84+
#else
8285
var useAccessLevelOnImports = false
86+
#endif
8387
var experimentalStripNonfunctionalCodegen: Bool = false
8488

8589
for pair in parameter.parsedPairs {

0 commit comments

Comments
 (0)