Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,18 @@ jobs:
working-directory: "./IntegrationTests/Benchmarks"
run: swift package benchmark baseline check --no-progress --check-absolute-path Thresholds/${{ matrix.swift-version }}/
timeout-minutes: 20
examples:
strategy:
fail-fast: false
matrix:
include:
- image: swiftlang/swift:nightly-jammy
- image: swift:6.0-jammy
name: Build examples using ${{ matrix.image }}
runs-on: ubuntu-latest
container:
image: ${{ matrix.image }}
steps:
- uses: actions/checkout@v4
- name: Build examples
run: ./dev/build-examples.sh
8 changes: 8 additions & 0 deletions Examples/echo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.DS_Store
/.build
/Packages
xcuserdata/
DerivedData/
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
38 changes: 38 additions & 0 deletions Examples/echo/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// swift-tools-version:6.0
/*
* Copyright 2024, gRPC 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 PackageDescription

let package = Package(
name: "echo",
platforms: [.macOS("15.0")],
dependencies: [
.package(url: "https://github.com/grpc/grpc-swift-protobuf", branch: "main"),
.package(url: "https://github.com/grpc/grpc-swift-nio-transport", branch: "main"),
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.5.0"),
],
targets: [
.executableTarget(
name: "echo",
dependencies: [
.product(name: "GRPCNIOTransportHTTP2", package: "grpc-swift-nio-transport"),
.product(name: "GRPCProtobuf", package: "grpc-swift-protobuf"),
.product(name: "ArgumentParser", package: "swift-argument-parser"),
]
)
]
)
46 changes: 46 additions & 0 deletions Examples/echo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Echo

This example demonstrates all four RPC types using a simple 'echo' service and
client and the Swift NIO based HTTP/2 transport.

## Overview

An "echo" command line tool that uses generated stubs for an 'echo' service
which allows you to start a server and to make requests against it for each of
the four RPC types.

The tool uses the [SwiftNIO](https://github.com/grpc/grpc-swift-nio-transport)
HTTP/2 transport.

## Usage

Build and run the server using the CLI:

```console
$ swift run echo serve
Echo listening on [ipv4]127.0.0.1:1234
```

Use the CLI to make a unary 'Get' request against it:

```console
$ swift run echo get --message "Hello"
get → Hello
get ← Hello
```

Use the CLI to make a bidirectional streaming 'Update' request:

```console
$ swift run echo update --message "Hello World"
update → Hello
update → World
update ← Hello
update ← World
```

Get help with the CLI by running:

```console
$ swift run echo --help
```
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import ArgumentParser

@main
@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
struct Echo: AsyncParsableCommand {
static let configuration = CommandConfiguration(
commandName: "echo",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import ArgumentParser
import GRPCHTTP2Core
import GRPCNIOTransportHTTP2

struct ClientArguments: ParsableArguments {
@Option(help: "The server's listening port")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@

import ArgumentParser
import GRPCCore
import GRPCHTTP2Core
import GRPCHTTP2TransportNIOPosix
import GRPCNIOTransportHTTP2

@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
struct Collect: AsyncParsableCommand {
static let configuration = CommandConfiguration(
abstract: "Makes a client streaming RPC to the echo server."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@

import ArgumentParser
import GRPCCore
import GRPCHTTP2Core
import GRPCHTTP2TransportNIOPosix
import GRPCNIOTransportHTTP2

@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
struct Expand: AsyncParsableCommand {
static let configuration = CommandConfiguration(
abstract: "Makes a server streaming RPC to the echo server."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@

import ArgumentParser
import GRPCCore
import GRPCHTTP2Core
import GRPCHTTP2TransportNIOPosix
import GRPCNIOTransportHTTP2

@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
struct Get: AsyncParsableCommand {
static let configuration = CommandConfiguration(abstract: "Makes a unary RPC to the echo server.")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@

import ArgumentParser
import GRPCCore
import GRPCHTTP2Core
import GRPCHTTP2TransportNIOPosix
import GRPCNIOTransportHTTP2

@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
struct Serve: AsyncParsableCommand {
static let configuration = CommandConfiguration(abstract: "Starts an echo server.")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@

import ArgumentParser
import GRPCCore
import GRPCHTTP2Core
import GRPCHTTP2TransportNIOPosix
import GRPCNIOTransportHTTP2

@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
struct Update: AsyncParsableCommand {
static let configuration = CommandConfiguration(
abstract: "Makes a bidirectional server streaming RPC to the echo server."
Expand Down
8 changes: 8 additions & 0 deletions Examples/hello-world/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.DS_Store
/.build
/Packages
xcuserdata/
DerivedData/
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
38 changes: 38 additions & 0 deletions Examples/hello-world/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// swift-tools-version:6.0
/*
* Copyright 2024, gRPC 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 PackageDescription

let package = Package(
name: "hello-world",
platforms: [.macOS("15.0")],
dependencies: [
.package(url: "https://github.com/grpc/grpc-swift-protobuf", branch: "main"),
.package(url: "https://github.com/grpc/grpc-swift-nio-transport", branch: "main"),
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.5.0"),
],
targets: [
.executableTarget(
name: "hello-world",
dependencies: [
.product(name: "GRPCNIOTransportHTTP2", package: "grpc-swift-nio-transport"),
.product(name: "GRPCProtobuf", package: "grpc-swift-protobuf"),
.product(name: "ArgumentParser", package: "swift-argument-parser"),
]
)
]
)
34 changes: 34 additions & 0 deletions Examples/hello-world/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Hello World

This example demonstrates the canonical "Hello World" in gRPC.

## Overview

A "hello-world" command line tool that uses generated stubs for the 'Greeter'
service which allows you to start a server and to make requests against it.

The tool uses the [SwiftNIO](https://github.com/grpc/grpc-swift-nio-transport)
HTTP/2 transport.

## Usage

Build and run the server using the CLI:

```console
$ swift run hello-world serve
Greeter listening on [ipv4]127.0.0.1:31415
```

Use the CLI to send a request to the service:

```console
$ swift run hello-world greet
Hello, stranger
```

Send the name of the greetee in the request by specifying a `--name`:

```console
$ swift run hello-world greet --name "PanCakes 🐶"
Hello, PanCakes 🐶
```
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import ArgumentParser

@main
@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
struct HelloWorld: AsyncParsableCommand {
static let configuration = CommandConfiguration(
commandName: "hello-world",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
*/

import ArgumentParser
import GRPCHTTP2Transport
import GRPCNIOTransportHTTP2
import GRPCProtobuf

@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
struct Greet: AsyncParsableCommand {
static let configuration = CommandConfiguration(abstract: "Sends a request to the greeter server")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
*/

import ArgumentParser
import GRPCHTTP2Transport
import GRPCNIOTransportHTTP2
import GRPCProtobuf

@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
struct Serve: AsyncParsableCommand {
static let configuration = CommandConfiguration(abstract: "Starts a greeter server.")

Expand All @@ -43,7 +42,6 @@ struct Serve: AsyncParsableCommand {
}
}

@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
struct Greeter: Helloworld_GreeterServiceProtocol {
func sayHello(
request: ServerRequest.Single<Helloworld_HelloRequest>,
Expand Down
8 changes: 8 additions & 0 deletions Examples/route-guide/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.DS_Store
/.build
/Packages
xcuserdata/
DerivedData/
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
41 changes: 41 additions & 0 deletions Examples/route-guide/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// swift-tools-version:6.0
/*
* Copyright 2024, gRPC 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 PackageDescription

let package = Package(
name: "route-guide",
platforms: [.macOS("15.0")],
dependencies: [
.package(url: "https://github.com/grpc/grpc-swift-protobuf", branch: "main"),
.package(url: "https://github.com/grpc/grpc-swift-nio-transport", branch: "main"),
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.5.0"),
],
targets: [
.executableTarget(
name: "route-guide",
dependencies: [
.product(name: "GRPCNIOTransportHTTP2", package: "grpc-swift-nio-transport"),
.product(name: "GRPCProtobuf", package: "grpc-swift-protobuf"),
.product(name: "ArgumentParser", package: "swift-argument-parser"),
],
resources: [
.copy("route_guide_db.json")
]
)
]
)
Loading
Loading