Browse Source

Add `protoc` product (#1836)

Franz Busch 7 months ago
parent
commit
371744ed99
3 changed files with 115 additions and 2 deletions
  1. 6 1
      Makefile
  2. 11 1
      Package.swift
  3. 98 0
      Package@swift-5.10.swift

+ 6 - 1
Makefile

@@ -209,7 +209,12 @@ test-plugin: build ${PROTOC_GEN_SWIFT}
 
 # Test the SPM plugin.
 test-spm-plugin:
-	env PROTOC_PATH=$(shell realpath ${PROTOC}) ${SWIFT} test --package-path PluginExamples
+	@SWIFT_VERSION=$$(${SWIFT} --version | head -n1 | sed 's/.*Swift version \([0-9]*\)\..*/\1/'); \
+	if [ "$$SWIFT_VERSION" -lt 6 ]; then \
+		env PROTOC_PATH=$$(realpath ${PROTOC}) ${SWIFT} test --package-path PluginExamples; \
+	else \
+		${SWIFT} test --package-path PluginExamples; \
+	fi
 
 compile-tests: \
 	compile-tests-multimodule \

+ 11 - 1
Package.swift

@@ -18,6 +18,10 @@ let package = Package(
             name: "protoc-gen-swift",
             targets: ["protoc-gen-swift"]
         ),
+        .executable(
+            name: "protoc",
+            targets: ["protoc"]
+        ),
         .library(
             name: "SwiftProtobuf",
             targets: ["SwiftProtobuf"]
@@ -50,6 +54,12 @@ let package = Package(
             dependencies: ["SwiftProtobuf"],
             swiftSettings: .packageSettings
         ),
+        .binaryTarget(
+            name: "protoc",
+            url:
+                "https://github.com/apple/swift-protobuf/releases/download/protoc-artifactbundle-v31.1/protoc-31.1.artifactbundle.zip",
+            checksum: "f18bf2cfbbebd83133a4c29733b01871e3afdc73c102d62949a841d4f9bab86f"
+        ),
         .executableTarget(
             name: "protoc-gen-swift",
             dependencies: ["SwiftProtobufPluginLibrary", "SwiftProtobuf"],
@@ -65,7 +75,7 @@ let package = Package(
         .plugin(
             name: "SwiftProtobufPlugin",
             capability: .buildTool(),
-            dependencies: ["protoc-gen-swift"]
+            dependencies: ["protoc-gen-swift", "protoc"]
         ),
         .testTarget(
             name: "SwiftProtobufTests",

+ 98 - 0
Package@swift-5.10.swift

@@ -0,0 +1,98 @@
+// swift-tools-version:5.10
+
+// 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"]
+        ),
+    ],
+    targets: [
+        .target(
+            name: "SwiftProtobuf",
+            exclude: ["CMakeLists.txt"],
+            resources: [.copy("PrivacyInfo.xcprivacy")],
+            swiftSettings: .packageSettings
+        ),
+        .target(
+            name: "SwiftProtobufPluginLibrary",
+            dependencies: ["SwiftProtobuf"],
+            exclude: ["CMakeLists.txt"],
+            resources: [.copy("PrivacyInfo.xcprivacy")],
+            swiftSettings: .packageSettings
+        ),
+        .target(
+            name: "SwiftProtobufTestHelpers",
+            dependencies: ["SwiftProtobuf"],
+            swiftSettings: .packageSettings
+        ),
+        .executableTarget(
+            name: "protoc-gen-swift",
+            dependencies: ["SwiftProtobufPluginLibrary", "SwiftProtobuf"],
+            exclude: ["CMakeLists.txt"],
+            swiftSettings: .packageSettings
+        ),
+        .executableTarget(
+            name: "Conformance",
+            dependencies: ["SwiftProtobuf"],
+            exclude: ["failure_list_swift.txt", "text_format_failure_list_swift.txt"],
+            swiftSettings: .packageSettings
+        ),
+        .plugin(
+            name: "SwiftProtobufPlugin",
+            capability: .buildTool(),
+            dependencies: ["protoc-gen-swift"]
+        ),
+        .testTarget(
+            name: "SwiftProtobufTests",
+            dependencies: ["SwiftProtobuf"],
+            swiftSettings: .packageSettings
+        ),
+        .testTarget(
+            name: "SwiftProtobufPluginLibraryTests",
+            dependencies: ["SwiftProtobufPluginLibrary", "SwiftProtobufTestHelpers"],
+            swiftSettings: .packageSettings
+        ),
+        .testTarget(
+            name: "protoc-gen-swiftTests",
+            dependencies: ["protoc-gen-swift", "SwiftProtobufTestHelpers"],
+            swiftSettings: .packageSettings
+        ),
+    ],
+    swiftLanguageVersions: [.v5]
+)
+
+// Settings for every Swift target in this package, like project-level settings
+// in an Xcode project.
+extension Array where Element == PackageDescription.SwiftSetting {
+    static var packageSettings: Self {
+        [
+            .enableExperimentalFeature("StrictConcurrency=complete"),
+            .enableUpcomingFeature("ExistentialAny"),
+        ]
+    }
+}