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 26, 2023
1 parent eebfda3 commit e2c79d5
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 2 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
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.8
// swift-tools-version:5.9

// Package.swift
//
Expand Down
2 changes: 1 addition & 1 deletion Package@swift-5.7.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.6
// swift-tools-version:5.7

// Package.swift
//
Expand Down
91 changes: 91 additions & 0 deletions Package@swift-5.8.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// swift-tools-version:5.8

// Package.swift
//
// Copyright (c) 2014 - 2018 Apple Inc. and the project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See LICENSE.txt for license information:
// https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt
//

import PackageDescription

let package = Package(
name: "SwiftProtobuf",
products: [
.executable(
name: "protoc-gen-swift",
targets: ["protoc-gen-swift"]
),
.library(
name: "SwiftProtobuf",
targets: ["SwiftProtobuf"]
),
.library(
name: "SwiftProtobufPluginLibrary",
targets: ["SwiftProtobufPluginLibrary"]
),
.plugin(
name: "SwiftProtobufPlugin",
targets: ["SwiftProtobufPlugin"]
),
],
dependencies: [
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
],
targets: [
.target(
name: "SwiftProtobuf",
exclude: ["CMakeLists.txt"],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency=complete"),
]
),
.target(
name: "SwiftProtobufPluginLibrary",
dependencies: ["SwiftProtobuf"],
exclude: ["CMakeLists.txt"]
),
.target(
name: "SwiftProtobufTestHelpers",
dependencies: ["SwiftProtobuf"],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency=complete"),
]
),
.executableTarget(
name: "protoc-gen-swift",
dependencies: ["SwiftProtobufPluginLibrary", "SwiftProtobuf"],
exclude: ["CMakeLists.txt"]
),
.executableTarget(
name: "Conformance",
dependencies: ["SwiftProtobuf"],
exclude: ["failure_list_swift.txt", "text_format_failure_list_swift.txt"]
),
.plugin(
name: "SwiftProtobufPlugin",
capability: .buildTool(),
dependencies: [
"protoc-gen-swift"
]
),
.testTarget(
name: "SwiftProtobufTests",
dependencies: ["SwiftProtobuf"],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency=complete"),
]
),
.testTarget(
name: "SwiftProtobufPluginLibraryTests",
dependencies: ["SwiftProtobufPluginLibrary", "SwiftProtobufTestHelpers"]
),
.testTarget(
name: "protoc-gen-swiftTests",
dependencies: ["protoc-gen-swift", "SwiftProtobufTestHelpers"]
),
],
swiftLanguageVersions: [.v5]
)
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 e2c79d5

Please sign in to comment.