diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 6e05d6bac..26d4e0447 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -141,14 +141,19 @@ jobs: include: - image: swiftlang/swift:nightly-jammy swift-tools-version: '6.0' + supports-v2: true - image: swiftlang/swift:nightly-6.0-jammy swift-tools-version: '6.0' + supports-v2: true - image: swift:5.10.1-noble swift-tools-version: '5.10' + supports-v2: false - image: swift:5.9-jammy swift-tools-version: '5.9' + supports-v2: false - image: swift:5.8-focal swift-tools-version: '5.8' + supports-v2: false name: Integration Tests on ${{ matrix.image }} runs-on: ubuntu-latest container: @@ -157,8 +162,11 @@ jobs: - uses: actions/checkout@v4 - name: Install protoc run: apt update && apt install -y protobuf-compiler - - name: SwiftPM plugin test - run: ./scripts/run-plugin-tests.sh ${{ matrix.swift-tools-version }} + - name: SwiftPM plugin test (v1) + run: ./scripts/run-plugin-tests.sh ${{ matrix.swift-tools-version }} "v1" + - name: SwiftPM plugin test (v2) + if: ${{ matrix.supports-v2 }} + run: ./scripts/run-plugin-tests.sh ${{ matrix.swift-tools-version }} "v2" - name: Build without NIOSSL run: swift build env: diff --git a/Package@swift-6.swift b/Package@swift-6.swift index c89ca9b08..24f1982d0 100644 --- a/Package@swift-6.swift +++ b/Package@swift-6.swift @@ -810,13 +810,20 @@ extension Product { ) } - static var grpcCore: Product { + static var _grpcCore: Product { .library( name: "_GRPCCore", targets: ["GRPCCore"] ) } + static var _grpcProtobuf: Product { + .library( + name: "_GRPCProtobuf", + targets: ["GRPCProtobuf"] + ) + } + static var cgrpcZlib: Product { .library( name: cgrpcZlibProductName, @@ -851,12 +858,15 @@ extension Product { let package = Package( name: grpcPackageName, products: [ + // v1 .grpc, - .grpcCore, .cgrpcZlib, .grpcReflectionService, .protocGenGRPCSwift, .grpcSwiftPlugin, + // v2 + ._grpcCore, + ._grpcProtobuf, ], dependencies: packageDependencies, targets: [ diff --git a/scripts/run-plugin-tests.sh b/scripts/run-plugin-tests.sh index a0af91597..c772508c2 100755 --- a/scripts/run-plugin-tests.sh +++ b/scripts/run-plugin-tests.sh @@ -20,10 +20,11 @@ HERE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" GRPC_PATH="${HERE}/.." function generate_package_manifest { - local version=$1 + local tools_version=$1 local grpc_path=$2 + local grpc_version=$3 - echo "// swift-tools-version: $version" + echo "// swift-tools-version: $tools_version" echo "import PackageDescription" echo "" echo "let package = Package(" @@ -36,7 +37,14 @@ function generate_package_manifest { echo " .executableTarget(" echo " name: \"Foo\"," echo " dependencies: [" - echo " .product(name: \"GRPC\", package: \"grpc-swift\")," + + if [ "$grpc_version" == "v1" ]; then + echo " .product(name: \"GRPC\", package: \"grpc-swift\")," + elif [ "$grpc_version" == "v2" ]; then + echo " .product(name: \"_GRPCCore\", package: \"grpc-swift\")," + echo " .product(name: \"_GRPCProtobuf\", package: \"grpc-swift\")," + fi + echo " ]," echo " path: \"Sources/Foo\"," echo " plugins: [" @@ -49,20 +57,30 @@ function generate_package_manifest { } function generate_grpc_plugin_config { - cat < "$dir/Package.swift" - generate_grpc_plugin_config > "$dir/Sources/Foo/grpc-swift-config.json" + generate_package_manifest "$tools_version" "$grpc_path" "$grpc_version" > "$dir/Package.swift" + generate_protobuf_plugin_config > "$dir/Sources/Foo/swift-protobuf-config.json" generate_proto > "$dir/Sources/Foo/Foo.proto" generate_main > "$dir/Sources/Foo/main.swift" + generate_grpc_plugin_config "$grpc_version" > "$dir/Sources/Foo/grpc-swift-config.json" PROTOC_PATH=$protoc_path swift build --package-path "$dir" } -if [[ $# -lt 1 ]]; then - echo "Usage: $0 SWIFT_TOOLS_VERSION" +if [[ $# -lt 2 ]]; then + echo "Usage: $0 SWIFT_TOOLS_VERSION GRPC_SWIFT_VERSION" +fi + +if [ "$2" != "v1" ] && [ "$2" != "v2" ]; then + echo "Invalid gRPC Swift version '$2' (must be 'v1' or 'v2')" exit 1 fi -generate_and_build "$1" "${GRPC_PATH}" +generate_and_build "$1" "${GRPC_PATH}" "$2"