Skip to content

Commit a5c37ba

Browse files
committed
more tests, use source dir as -I path
1 parent 454684d commit a5c37ba

File tree

14 files changed

+372
-1
lines changed

14 files changed

+372
-1
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// swift-tools-version: 6.0
2+
/*
3+
* Copyright 2024, gRPC Authors All rights reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import PackageDescription
19+
20+
let package = Package(
21+
name: "grpc-adopter",
22+
platforms: [
23+
.macOS(.v15),
24+
.iOS(.v18),
25+
.tvOS(.v18),
26+
.watchOS(.v11),
27+
.visionOS(.v2),
28+
],
29+
dependencies: [
30+
.package(
31+
path: "../../../../grpc-swift-protobuf"
32+
),
33+
.package(
34+
url: "https://github.com/grpc/grpc-swift.git",
35+
exact: "2.0.0-beta.2"
36+
),
37+
],
38+
targets: [
39+
.executableTarget(
40+
name: "grpc-adopter",
41+
dependencies: [
42+
.product(name: "GRPCCore", package: "grpc-swift"),
43+
.product(name: "GRPCInProcessTransport", package: "grpc-swift"),
44+
.product(name: "GRPCProtobuf", package: "grpc-swift-protobuf"),
45+
],
46+
plugins: [
47+
.plugin(name: "GRPCGeneratorPlugin", package: "grpc-swift-protobuf")
48+
]
49+
)
50+
]
51+
)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
syntax = "proto3";
2+
3+
package foo;
4+
5+
message FooInput {}
6+
message FooOutput {}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
syntax = "proto3";
2+
3+
import "foo-messages.proto";
4+
5+
package foo;
6+
7+
service FooService1 {
8+
rpc Foo (FooInput) returns (FooOutput) {}
9+
}
10+
11+
service FooService2 {
12+
rpc Foo (FooInput) returns (FooOutput) {}
13+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright 2015, gRPC Authors All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
syntax = "proto3";
15+
16+
option java_multiple_files = true;
17+
option java_package = "io.grpc.examples.helloworld";
18+
option java_outer_classname = "HelloWorldProto";
19+
option objc_class_prefix = "HLW";
20+
21+
package helloworld;
22+
23+
// The greeting service definition.
24+
service Greeter {
25+
// Sends a greeting
26+
rpc SayHello (HelloRequest) returns (HelloReply) {}
27+
}
28+
29+
// The request message containing the user's name.
30+
message HelloRequest {
31+
string name = 1;
32+
}
33+
34+
// The response message containing the greetings
35+
message HelloReply {
36+
string message = 1;
37+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Copyright 2024, gRPC Authors All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import GRPCCore
18+
import GRPCInProcessTransport
19+
import GRPCProtobuf
20+
21+
@main
22+
struct PluginAdopter {
23+
static func main() async throws {
24+
let inProcess = InProcessTransport()
25+
try await withGRPCServer(transport: inProcess.server, services: [Greeter()]) { server in
26+
try await withGRPCClient(transport: inProcess.client) { client in
27+
try await Self.doRPC(Helloworld_Greeter.Client(wrapping: client))
28+
}
29+
}
30+
31+
try await withGRPCServer(transport: inProcess.server, services: [FooService1()]) { server in
32+
try await withGRPCClient(transport: inProcess.client) { client in
33+
try await Self.doRPC(Foo_FooService1.Client(wrapping: client))
34+
}
35+
}
36+
}
37+
38+
static func doRPC(_ greeter: Helloworld_Greeter.Client) async throws {
39+
do {
40+
let reply = try await greeter.sayHello(.with { $0.name = "(ignored)" })
41+
print("Reply: \(reply.message)")
42+
} catch {
43+
print("Error: \(error)")
44+
}
45+
}
46+
47+
static func doRPC(_ fooService1: Foo_FooService1.Client) async throws {
48+
do {
49+
let reply = try await fooService1.foo(.with { _ in () })
50+
print("Reply: \(reply.hashValue)")
51+
} catch {
52+
print("Error: \(error)")
53+
}
54+
}
55+
}
56+
57+
struct Greeter: Helloworld_Greeter.SimpleServiceProtocol {
58+
func sayHello(
59+
request: Helloworld_HelloRequest,
60+
context: ServerContext
61+
) async throws -> Helloworld_HelloReply {
62+
return .with { reply in
63+
reply.message = "Hello, world!"
64+
}
65+
}
66+
}
67+
68+
struct FooService1: Foo_FooService1.SimpleServiceProtocol {
69+
func foo(request: Foo_FooInput, context: GRPCCore.ServerContext) async throws -> Foo_FooOutput {
70+
return .with { _ in
71+
()
72+
}
73+
}
74+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"visibility": "internal"
3+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// swift-tools-version: 6.0
2+
/*
3+
* Copyright 2024, gRPC Authors All rights reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import PackageDescription
19+
20+
let package = Package(
21+
name: "grpc-adopter",
22+
platforms: [
23+
.macOS(.v15),
24+
.iOS(.v18),
25+
.tvOS(.v18),
26+
.watchOS(.v11),
27+
.visionOS(.v2),
28+
],
29+
dependencies: [
30+
.package(
31+
path: "../../../../grpc-swift-protobuf"
32+
),
33+
.package(
34+
url: "https://github.com/grpc/grpc-swift.git",
35+
exact: "2.0.0-beta.2"
36+
),
37+
],
38+
targets: [
39+
.executableTarget(
40+
name: "grpc-adopter",
41+
dependencies: [
42+
.product(name: "GRPCCore", package: "grpc-swift"),
43+
.product(name: "GRPCInProcessTransport", package: "grpc-swift"),
44+
.product(name: "GRPCProtobuf", package: "grpc-swift-protobuf"),
45+
],
46+
plugins: [
47+
.plugin(name: "GRPCGeneratorPlugin", package: "grpc-swift-protobuf")
48+
]
49+
)
50+
]
51+
)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
syntax = "proto3";
2+
3+
package foo;
4+
5+
message FooInput {}
6+
message FooOutput {}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
syntax = "proto3";
2+
3+
import "foo-messages.proto";
4+
5+
package foo;
6+
7+
service FooService1 {
8+
rpc Foo (FooInput) returns (FooOutput) {}
9+
}
10+
11+
service FooService2 {
12+
rpc Foo (FooInput) returns (FooOutput) {}
13+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"visibility": "public"
3+
}

0 commit comments

Comments
 (0)