Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run CI on both Swift 4.2 and 5, and fix Swift 5 warning #426

Merged
merged 7 commits into from
Apr 16, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 6 additions & 6 deletions .travis-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@
#
# Install dependencies that aren't available as Ubuntu packages (or already present on macOS).
#
# Everything goes into $HOME/local.
# Everything goes into $HOME/local.
#
# Scripts should add
# - $HOME/local/bin to PATH
# Scripts should add
# - $HOME/local/bin to PATH
# - $HOME/local/lib to LD_LIBRARY_PATH
#

cd
mkdir -p local

if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
if [[ "${TRAVIS_OS_NAME}" == "osx" ]]; then
PROTOC_URL=https://github.com/google/protobuf/releases/download/v3.5.1/protoc-3.5.1-osx-x86_64.zip
else
# Install swift
SWIFT_URL=https://swift.org/builds/swift-4.1.1-release/ubuntu1404/swift-4.1.1-RELEASE/swift-4.1.1-RELEASE-ubuntu14.04.tar.gz
rebello95 marked this conversation as resolved.
Show resolved Hide resolved
SWIFT_URL=https://swift.org/builds/swift-${SWIFT_VERSION}-release/ubuntu1404/swift-${SWIFT_VERSION}-RELEASE/swift-${SWIFT_VERSION}-RELEASE-ubuntu14.04.tar.gz
echo $SWIFT_URL
curl -fSsL $SWIFT_URL -o swift.tar.gz
curl -fSsL $SWIFT_URL -o swift.tar.gz
tar -xzf swift.tar.gz --strip-components=2 --directory=local

PROTOC_URL=https://github.com/google/protobuf/releases/download/v3.5.1/protoc-3.5.1-linux-x86_64.zip
Expand Down
41 changes: 28 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,26 @@
#
# Travis CI build file for Swift gRPC.

os:
- linux
- osx
matrix:
include:
- os: linux
env:
- SWIFT_VERSION=4.2
- MAJOR_VERSION=4.2
- os: osx
osx_image: xcode10.2
env:
- SWIFT_VERSION=4.2
- MAJOR_VERSION=4.2
- os: linux
env:
- SWIFT_VERSION=5.0
- MAJOR_VERSION=5
- os: osx
osx_image: xcode10.2
env:
- SWIFT_VERSION=5.0
- MAJOR_VERSION=5

cache:
apt: true
Expand All @@ -28,23 +45,21 @@ cache:
# Use Ubuntu 14.04
dist: trusty

osx_image: xcode9.3

sudo: false

addons:
apt:
sources:
- sourceline: 'ppa:ondrej/apache2' # for libnghttp2-dev
packages:
- clang-3.8
- lldb-3.8
- libicu-dev
- libtool
- libcurl4-openssl-dev
- libbsd-dev
- build-essential
- libssl-dev
- clang-3.8
- lldb-3.8
- libicu-dev
- libtool
- libcurl4-openssl-dev
- libbsd-dev
- build-essential
- libssl-dev
- uuid-dev
- curl
- unzip
Expand Down
3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:4.0
// swift-tools-version:4.2
/*
* Copyright 2017, gRPC Authors All rights reserved.
*
Expand Down Expand Up @@ -95,5 +95,6 @@ let package = Package(
.testTarget(name: "SwiftGRPCTests", dependencies: ["SwiftGRPC"]),
.testTarget(name: "SwiftGRPCNIOTests", dependencies: ["SwiftGRPC", "SwiftGRPCNIO"])
],
swiftLanguageVersions: [.v4, .v4_2, .version("5")],
cLanguageStandard: .gnu11,
cxxLanguageStandard: .cxx11)
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ Original SwiftGRPC issue: https://github.com/grpc/grpc-swift/issues/337.
grpc-swift depends on Swift, Xcode, and swift-protobuf. We are currently
testing with the following versions:

- Xcode 9.1
- Swift 4.0
- Xcode 10.0 / 10.2
- Swift 4.2 / 5.0
- swift-protobuf 1.3.1

## `SwiftGRPCNIO` package
Expand Down
17 changes: 11 additions & 6 deletions Sources/SwiftGRPC/Core/ByteBuffer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
* limitations under the License.
*/
#if SWIFT_PACKAGE
import CgRPC
import CgRPC
#endif
import Foundation // for String.Encoding
import Foundation

/// Representation of raw data that may be sent and received using gRPC
public class ByteBuffer {
Expand All @@ -35,11 +35,16 @@ public class ByteBuffer {
///
/// - Parameter data: the data to store in the buffer
public init(data: Data) {
var underlyingByteBuffer: UnsafeMutableRawPointer?
data.withUnsafeBytes { bytes in
underlyingByteBuffer = cgrpc_byte_buffer_create_by_copying_data(bytes, data.count)
#if swift(>=5.0)
self.underlyingByteBuffer = data.withUnsafeBytes { bytes in
let buffer = bytes.bindMemory(to: UInt8.self).baseAddress
return cgrpc_byte_buffer_create_by_copying_data(buffer, data.count)
}
self.underlyingByteBuffer = underlyingByteBuffer!
#else
self.underlyingByteBuffer = data.withUnsafeBytes { bytes in
return cgrpc_byte_buffer_create_by_copying_data(bytes, data.count)
}
#endif
}

deinit {
Expand Down