From d88d9b105b49220dd61f484c12884bd5d1c0ca2e Mon Sep 17 00:00:00 2001 From: Gus Cairo Date: Tue, 26 Sep 2023 14:23:25 +0100 Subject: [PATCH] Add support for `package` visibility modifier --- Documentation/PLUGIN.md | 2 ++ Plugins/SwiftProtobufPlugin/plugin.swift | 5 +++++ Sources/protoc-gen-swift/GeneratorOptions.swift | 5 +++++ 3 files changed, 12 insertions(+) diff --git a/Documentation/PLUGIN.md b/Documentation/PLUGIN.md index e6b2c7972..09e86811a 100644 --- a/Documentation/PLUGIN.md +++ b/Documentation/PLUGIN.md @@ -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. diff --git a/Plugins/SwiftProtobufPlugin/plugin.swift b/Plugins/SwiftProtobufPlugin/plugin.swift index 434db2238..ca846b0a8 100644 --- a/Plugins/SwiftProtobufPlugin/plugin.swift +++ b/Plugins/SwiftProtobufPlugin/plugin.swift @@ -37,6 +37,9 @@ 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() { @@ -44,6 +47,8 @@ struct SwiftProtobufPlugin { self = .internal case "public": self = .public + case "package": + self = .package default: return nil } diff --git a/Sources/protoc-gen-swift/GeneratorOptions.swift b/Sources/protoc-gen-swift/GeneratorOptions.swift index 69ecdb869..f8f8dced4 100644 --- a/Sources/protoc-gen-swift/GeneratorOptions.swift +++ b/Sources/protoc-gen-swift/GeneratorOptions.swift @@ -33,6 +33,7 @@ class GeneratorOptions { enum Visibility { case `internal` case `public` + case `package` init?(flag: String) { switch flag.lowercased() { @@ -40,6 +41,8 @@ class GeneratorOptions { self = .internal case "public": self = .public + case "package": + self = .package default: return nil } @@ -119,6 +122,8 @@ class GeneratorOptions { visibilitySourceSnippet = "" case .public: visibilitySourceSnippet = "public " + case .package: + visibilitySourceSnippet = "package " } self.implementationOnlyImports = implementationOnlyImports