diff --git a/.travis-install.sh b/.travis-install.sh index 253c40155..f6763ebd6 100755 --- a/.travis-install.sh +++ b/.travis-install.sh @@ -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 + 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 diff --git a/.travis.yml b/.travis.yml index f2463be49..ab9bae6a8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 @@ -28,8 +45,6 @@ cache: # Use Ubuntu 14.04 dist: trusty -osx_image: xcode9.3 - sudo: false addons: @@ -37,14 +52,14 @@ addons: 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 diff --git a/Package.swift b/Package.swift index d450b46d4..482fdaf66 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:4.0 +// swift-tools-version:4.2 /* * Copyright 2017, gRPC Authors All rights reserved. * @@ -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) diff --git a/README.md b/README.md index b6abbc5a7..d029353f4 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/Sources/SwiftGRPC/Core/ByteBuffer.swift b/Sources/SwiftGRPC/Core/ByteBuffer.swift index faf998198..e45b59f3f 100644 --- a/Sources/SwiftGRPC/Core/ByteBuffer.swift +++ b/Sources/SwiftGRPC/Core/ByteBuffer.swift @@ -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 { @@ -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 {