-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add swift_proto_library_group rule (#1173)
- Loading branch information
1 parent
72347ab
commit ea2d4bd
Showing
29 changed files
with
1,139 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
load( | ||
"//swift:swift.bzl", | ||
"swift_binary", | ||
"swift_test", | ||
) | ||
|
||
swift_binary( | ||
name = "echo_server", | ||
srcs = ["server_main.swift"], | ||
deps = [ | ||
"//examples/xplatform/proto_library_group/service:service_server_swift_proto", | ||
], | ||
) | ||
|
||
swift_binary( | ||
name = "echo_client", | ||
srcs = ["client_main.swift"], | ||
deps = [ | ||
"//examples/xplatform/proto_library_group/service:service_client_swift_proto", | ||
], | ||
) | ||
|
||
swift_test( | ||
name = "echo_client_unit_test", | ||
srcs = [ | ||
"client_unit_test.swift", | ||
"main.swift", | ||
], | ||
deps = [ | ||
"//examples/xplatform/proto_library_group/service:service_client_swift_proto", | ||
"//examples/xplatform/proto_library_group/service:service_server_swift_proto", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright 2019 The Bazel Authors. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import Foundation | ||
import SwiftProtobuf | ||
import GRPC | ||
import NIOCore | ||
import NIOPosix | ||
import examples_xplatform_proto_library_group_request_request_proto | ||
import ServiceClient | ||
|
||
@main | ||
struct ClientMain { | ||
static func main() throws { | ||
// Setup an `EventLoopGroup` for the connection to run on. | ||
// | ||
// See: https://github.com/apple/swift-nio#eventloops-and-eventloopgroups | ||
let group = MultiThreadedEventLoopGroup(numberOfThreads: 1) | ||
|
||
// Make sure the group is shutdown when we're done with it. | ||
defer { | ||
try! group.syncShutdownGracefully() | ||
} | ||
|
||
// Configure the channel, we're not using TLS so the connection is `insecure`. | ||
let channel = try GRPCChannelPool.with( | ||
target: .host("localhost", port: 9000), | ||
transportSecurity: .plaintext, | ||
eventLoopGroup: group | ||
) | ||
|
||
// Initialize the client using the same address the server is started on. | ||
let client = Service_EchoServiceNIOClient(channel: channel) | ||
|
||
// Construct a request to the echo service. | ||
let request = Request_Request.with { | ||
$0.message = "Hello, world!" | ||
let timestamp = Google_Protobuf_Timestamp(date: Date()) | ||
$0.extra = try! Google_Protobuf_Any(message: timestamp) | ||
} | ||
|
||
let call = client.echo(request) | ||
|
||
// Make the remote method call and print the response we receive. | ||
do { | ||
let response = try call.response.wait() | ||
print(response.request.message) | ||
print(response.request.extra) | ||
} catch { | ||
print("Echo failed: \(error)") | ||
} | ||
} | ||
} |
Oops, something went wrong.