Skip to content

Commit edb04c6

Browse files
gjcairothomasvl
authored andcommitted
Add support for package visibility modifier
1 parent b77507b commit edb04c6

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

Documentation/PLUGIN.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ The possible values for `Visibility` are:
124124

125125
* `Internal` (default): No visibility is set for the types, so they get the
126126
default internal visibility.
127+
* `Package` (Swift 5.9 or later required): The visibility on the types is set to
128+
`package` so the types will be exposed across the whole Swift package they belong to.
127129
* `Public`: The visibility on the types is set to `public` so the types will
128130
be exposed outside the module they are compiled into.
129131

Plugins/SwiftProtobufPlugin/plugin.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,18 @@ struct SwiftProtobufPlugin {
3737
case `internal` = "Internal"
3838
/// The generated files should have `public` access level.
3939
case `public` = "Public"
40+
/// The generated files should have `package` access level.
41+
/// - Note: Swift 5.9 or later is needed to use this option.
42+
case `package` = "Package"
4043

4144
init?(rawValue: String) {
4245
switch rawValue.lowercased() {
4346
case "internal":
4447
self = .internal
4548
case "public":
4649
self = .public
50+
case "package":
51+
self = .package
4752
default:
4853
return nil
4954
}

Sources/protoc-gen-swift/GeneratorOptions.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,16 @@ class GeneratorOptions {
3333
enum Visibility {
3434
case `internal`
3535
case `public`
36+
case `package`
3637

3738
init?(flag: String) {
3839
switch flag.lowercased() {
3940
case "internal":
4041
self = .internal
4142
case "public":
4243
self = .public
44+
case "package":
45+
self = .package
4346
default:
4447
return nil
4548
}
@@ -119,6 +122,8 @@ class GeneratorOptions {
119122
visibilitySourceSnippet = ""
120123
case .public:
121124
visibilitySourceSnippet = "public "
125+
case .package:
126+
visibilitySourceSnippet = "package "
122127
}
123128

124129
self.implementationOnlyImports = implementationOnlyImports

0 commit comments

Comments
 (0)