Skip to content

Commit

Permalink
Add support for package visibility modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
gjcairo committed Sep 28, 2023
1 parent eebfda3 commit d88d9b1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Documentation/PLUGIN.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ The possible values for `Visibility` are:

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

Expand Down
5 changes: 5 additions & 0 deletions Plugins/SwiftProtobufPlugin/plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,18 @@ struct SwiftProtobufPlugin {
case `internal` = "Internal"
/// The generated files should have `public` access level.
case `public` = "Public"
/// The generated files should have `package` access level.
/// - Note: Swift 5.9 or later is needed to use this option.
case `package` = "Package"

init?(rawValue: String) {
switch rawValue.lowercased() {
case "internal":
self = .internal
case "public":
self = .public
case "package":
self = .package
default:
return nil
}
Expand Down
5 changes: 5 additions & 0 deletions Sources/protoc-gen-swift/GeneratorOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,16 @@ class GeneratorOptions {
enum Visibility {
case `internal`
case `public`
case `package`

init?(flag: String) {
switch flag.lowercased() {
case "internal":
self = .internal
case "public":
self = .public
case "package":
self = .package
default:
return nil
}
Expand Down Expand Up @@ -119,6 +122,8 @@ class GeneratorOptions {
visibilitySourceSnippet = ""
case .public:
visibilitySourceSnippet = "public "
case .package:
visibilitySourceSnippet = "package "
}

self.implementationOnlyImports = implementationOnlyImports
Expand Down

0 comments on commit d88d9b1

Please sign in to comment.