Skip to content

Commit

Permalink
Swift 6-ify the package manifest (grpc#1955)
Browse files Browse the repository at this point in the history
Motivation:

v2 will require the Swift 6 language mode. In order to continue
developing v1 and v2 on main we'll need a Swift 6 specific manifest
version in addition to the 5.x version.

Moving forward we'll have two package manifests, `Package.swift` for 5.x
containing only v1, and `[email protected]` using tools version 6.0
targetting v1 and v2.

Modifications:

- Remove v2 targets from Package.swift
- Add a second manifest and make it warning free with Swift 6, this
  requires turning `static let`s to `static var`s.
- Conditionalise some imports in `protoc-gen-grpc-swift` (as it is
  shared by v1 and v2)
- Fix an error in the plugin for Swift 6

Result:

v2 now only compiles with a Swift 6 compiler
  • Loading branch information
glbrntt authored Jul 2, 2024
1 parent 1cf1053 commit 36ffcb4
Show file tree
Hide file tree
Showing 28 changed files with 956 additions and 360 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
matrix:
include:
- image: swiftlang/swift:nightly-jammy
swift-version: main
swift-version: 'main'
env:
MAX_ALLOCS_ALLOWED_bidi_1k_rpcs_10_requests: 323000
MAX_ALLOCS_ALLOWED_bidi_1k_rpcs_1_request: 161000
Expand All @@ -72,7 +72,7 @@ jobs:
MAX_ALLOCS_ALLOWED_unary_1k_ping_pong_interceptors_client: 170000
MAX_ALLOCS_ALLOWED_unary_1k_ping_pong_interceptors_server: 170000
- image: swiftlang/swift:nightly-6.0-jammy
swift-version: main
swift-version: '6.0'
env:
MAX_ALLOCS_ALLOWED_bidi_1k_rpcs_10_requests: 323000
MAX_ALLOCS_ALLOWED_bidi_1k_rpcs_1_request: 161000
Expand Down Expand Up @@ -126,9 +126,11 @@ jobs:
env: ${{ matrix.env }}
timeout-minutes: 20
- name: Install jemalloc for benchmarking
if: ${{ matrix.swift-version == '6.0' || matrix.swift-version == 'main' }}
run: apt update && apt-get install -y libjemalloc-dev
timeout-minutes: 20
- name: Run Benchmarks
if: ${{ matrix.swift-version == '6.0' || matrix.swift-version == 'main' }}
working-directory: ./Performance/Benchmarks
run: swift package benchmark baseline check --no-progress --check-absolute-path Thresholds/${{ matrix.swift-version }}/
timeout-minutes: 20
Expand Down
255 changes: 0 additions & 255 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ let packageDependencies: [Package.Dependency] = [
url: "https://github.com/apple/swift-collections.git",
from: "1.0.5"
),
.package(
url: "https://github.com/apple/swift-atomics.git",
from: "1.2.0"
),
.package(
url: "https://github.com/apple/swift-protobuf.git",
from: "1.20.2"
Expand All @@ -68,14 +64,6 @@ let packageDependencies: [Package.Dependency] = [
// version and indluded async support.
from: "1.1.1"
),
.package(
url: "https://github.com/apple/swift-docc-plugin",
from: "1.0.0"
),
.package(
url: "https://github.com/apple/swift-distributed-tracing.git",
from: "1.0.0"
),
].appending(
.package(
url: "https://github.com/apple/swift-nio-ssl.git",
Expand All @@ -91,11 +79,7 @@ extension Target.Dependency {
static let grpc: Self = .target(name: grpcTargetName)
static let cgrpcZlib: Self = .target(name: cgrpcZlibTargetName)
static let protocGenGRPCSwift: Self = .target(name: "protoc-gen-grpc-swift")
static let performanceWorker: Self = .target(name: "performance-worker")
static let reflectionService: Self = .target(name: "GRPCReflectionService")
static let grpcCodeGen: Self = .target(name: "GRPCCodeGen")
static let grpcProtobuf: Self = .target(name: "GRPCProtobuf")
static let grpcProtobufCodeGen: Self = .target(name: "GRPCProtobufCodeGen")

// Target dependencies; internal
static let grpcSampleData: Self = .target(name: "GRPCSampleData")
Expand Down Expand Up @@ -140,15 +124,6 @@ extension Target.Dependency {
package: "swift-protobuf"
)
static let dequeModule: Self = .product(name: "DequeModule", package: "swift-collections")
static let atomics: Self = .product(name: "Atomics", package: "swift-atomics")
static let tracing: Self = .product(name: "Tracing", package: "swift-distributed-tracing")

static let grpcCore: Self = .target(name: "GRPCCore")
static let grpcInProcessTransport: Self = .target(name: "GRPCInProcessTransport")
static let grpcInterceptors: Self = .target(name: "GRPCInterceptors")
static let grpcHTTP2Core: Self = .target(name: "GRPCHTTP2Core")
static let grpcHTTP2TransportNIOPosix: Self = .target(name: "GRPCHTTP2TransportNIOPosix")
static let grpcHTTP2TransportNIOTransportServices: Self = .target(name: "GRPCHTTP2TransportNIOTransportServices")
}

// MARK: - Targets
Expand Down Expand Up @@ -177,63 +152,6 @@ extension Target {
path: "Sources/GRPC"
)

static let grpcCore: Target = .target(
name: "GRPCCore",
dependencies: [
.dequeModule,
.atomics
],
path: "Sources/GRPCCore"
)

static let grpcInProcessTransport: Target = .target(
name: "GRPCInProcessTransport",
dependencies: [
.grpcCore
]
)

static let grpcInterceptors: Target = .target(
name: "GRPCInterceptors",
dependencies: [
.grpcCore,
.tracing
]
)

static let grpcHTTP2Core: Target = .target(
name: "GRPCHTTP2Core",
dependencies: [
.grpcCore,
.nioCore,
.nioHTTP2,
.cgrpcZlib,
.dequeModule,
.atomics
]
)

static let grpcHTTP2TransportNIOPosix: Target = .target(
name: "GRPCHTTP2TransportNIOPosix",
dependencies: [
.grpcCore,
.grpcHTTP2Core,
.nioPosix,
.nioExtras
]
)

static let grpcHTTP2TransportNIOTransportServices: Target = .target(
name: "GRPCHTTP2TransportNIOTransportServices",
dependencies: [
.grpcCore,
.grpcHTTP2Core,
.nioCore,
.nioExtras,
.nioTransportServices
]
)

static let cgrpcZlib: Target = .target(
name: cgrpcZlibTargetName,
path: "Sources/CGRPCZlib",
Expand All @@ -247,27 +165,12 @@ extension Target {
dependencies: [
.protobuf,
.protobufPluginLibrary,
.grpcCodeGen,
.grpcProtobufCodeGen
],
exclude: [
"README.md",
]
)

static let performanceWorker: Target = .executableTarget(
name: "performance-worker",
dependencies: [
.grpcCore,
.grpcHTTP2Core,
.grpcHTTP2TransportNIOPosix,
.grpcProtobuf,
.nioCore,
.nioFileSystem,
.argumentParser
]
)

static let grpcSwiftPlugin: Target = .plugin(
name: "GRPCSwiftPlugin",
capability: .buildTool(),
Expand Down Expand Up @@ -304,91 +207,6 @@ extension Target {
]
)

static let grpcCoreTests: Target = .testTarget(
name: "GRPCCoreTests",
dependencies: [
.grpcCore,
.grpcInProcessTransport,
.dequeModule,
.atomics,
.protobuf,
]
)

static let grpcInProcessTransportTests: Target = .testTarget(
name: "GRPCInProcessTransportTests",
dependencies: [
.grpcCore,
.grpcInProcessTransport
]
)

static let grpcInterceptorsTests: Target = .testTarget(
name: "GRPCInterceptorsTests",
dependencies: [
.grpcCore,
.tracing,
.nioCore,
.grpcInterceptors
]
)

static let grpcHTTP2CoreTests: Target = .testTarget(
name: "GRPCHTTP2CoreTests",
dependencies: [
.grpcHTTP2Core,
.nioCore,
.nioHTTP2,
.nioEmbedded,
.nioTestUtils,
]
)

static let grpcHTTP2TransportTests: Target = .testTarget(
name: "GRPCHTTP2TransportTests",
dependencies: [
.grpcHTTP2Core,
.grpcHTTP2TransportNIOPosix,
.grpcHTTP2TransportNIOTransportServices,
.grpcProtobuf
]
)

static let grpcCodeGenTests: Target = .testTarget(
name: "GRPCCodeGenTests",
dependencies: [
.grpcCodeGen
]
)

static let grpcProtobufTests: Target = .testTarget(
name: "GRPCProtobufTests",
dependencies: [
.grpcProtobuf,
.grpcCore,
.protobuf
]
)

static let grpcProtobufCodeGenTests: Target = .testTarget(
name: "GRPCProtobufCodeGenTests",
dependencies: [
.grpcCodeGen,
.grpcProtobufCodeGen,
.protobuf,
.protobufPluginLibrary
]
)

static let inProcessInteroperabilityTests: Target = .testTarget(
name: "InProcessInteroperabilityTests",
dependencies: [
.grpcInProcessTransport,
.interoperabilityTests,
.grpcCore
]
)

static let interopTestModels: Target = .target(
name: "GRPCInteroperabilityTestModels",
dependencies: [
Expand All @@ -407,25 +225,6 @@ extension Target {
]
)

static let interoperabilityTestImplementation: Target = .target(
name: "InteroperabilityTests",
dependencies: [
.grpcCore,
.grpcProtobuf
]
)

static let interoperabilityTestsExecutable: Target = .executableTarget(
name: "interoperability-tests",
dependencies: [
.grpcCore,
.grpcHTTP2Core,
.grpcHTTP2TransportNIOPosix,
.interoperabilityTests,
.argumentParser
]
)

static let interopTestImplementation: Target = .target(
name: "GRPCInteroperabilityTestsImplementation",
dependencies: [
Expand Down Expand Up @@ -639,29 +438,6 @@ extension Target {
.copy("Generated")
]
)

static let grpcCodeGen: Target = .target(
name: "GRPCCodeGen",
path: "Sources/GRPCCodeGen"
)

static let grpcProtobuf: Target = .target(
name: "GRPCProtobuf",
dependencies: [
.grpcCore,
.protobuf,
],
path: "Sources/GRPCProtobuf"
)
static let grpcProtobufCodeGen: Target = .target(
name: "GRPCProtobufCodeGen",
dependencies: [
.protobuf,
.protobufPluginLibrary,
.grpcCodeGen
],
path: "Sources/GRPCProtobufCodeGen"
)
}

// MARK: - Products
Expand All @@ -672,11 +448,6 @@ extension Product {
targets: [grpcTargetName]
)

static let grpcCore: Product = .library(
name: "_GRPCCore",
targets: ["GRPCCore"]
)

static let cgrpcZlib: Product = .library(
name: cgrpcZlibProductName,
targets: [cgrpcZlibTargetName]
Expand Down Expand Up @@ -704,7 +475,6 @@ let package = Package(
name: grpcPackageName,
products: [
.grpc,
.grpcCore,
.cgrpcZlib,
.grpcReflectionService,
.protocGenGRPCSwift,
Expand Down Expand Up @@ -740,31 +510,6 @@ let package = Package(
.routeGuideServer,
.packetCapture,
.reflectionServer,

// v2
.grpcCore,
.grpcInProcessTransport,
.grpcCodeGen,
.grpcInterceptors,
.grpcHTTP2Core,
.grpcHTTP2TransportNIOPosix,
.grpcHTTP2TransportNIOTransportServices,
.grpcProtobuf,
.grpcProtobufCodeGen,
.interoperabilityTestImplementation,
.interoperabilityTestsExecutable,
.performanceWorker,

// v2 tests
.grpcCoreTests,
.grpcInProcessTransportTests,
.grpcCodeGenTests,
.grpcInterceptorsTests,
.grpcHTTP2CoreTests,
.grpcHTTP2TransportTests,
.grpcProtobufTests,
.grpcProtobufCodeGenTests,
.inProcessInteroperabilityTests
]
)

Expand Down
Loading

0 comments on commit 36ffcb4

Please sign in to comment.