diff --git a/.swift-version b/.swift-version index 4d0dcda..bf77d54 100644 --- a/.swift-version +++ b/.swift-version @@ -1 +1 @@ -4.1.2 +4.2 diff --git a/.travis.yml b/.travis.yml index 537c703..453f1b6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,7 @@ matrix: - os: linux dist: trusty sudo: required + env: SWIFT_SNAPSHOT=4.1.3 - os: linux dist: trusty sudo: required @@ -21,7 +22,6 @@ matrix: - os: linux dist: trusty sudo: required - env: SWIFT_SNAPSHOT=swift-4.2-DEVELOPMENT-SNAPSHOT-2018-06-19-a - os: osx osx_image: xcode9.2 sudo: required @@ -29,11 +29,10 @@ matrix: - os: osx osx_image: xcode9.4 sudo: required - env: JAZZY_ELIGIBLE=true + env: SWIFT_SNAPSHOT=4.1.2 JAZZY_ELIGIBLE=true - os: osx - osx_image: xcode9.4 + osx_image: xcode10 sudo: required - env: SWIFT_SNAPSHOT=swift-4.2-DEVELOPMENT-SNAPSHOT-2018-06-04-a script: - ./build.sh diff --git a/Package.swift b/Package.swift index 215b92a..2843421 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:4.0 +// swift-tools-version:4.2 // The swift-tools-version declares the minimum version of Swift required to build this package. /** @@ -22,30 +22,51 @@ import PackageDescription var dependencies: [Package.Dependency] = [ .package(url: "https://github.com/IBM-Swift/LoggerAPI.git", from: "1.7.3"), .package(url: "https://github.com/IBM-Swift/BlueSocket.git", from: "1.0.0"), - .package(url: "https://github.com/IBM-Swift/CCurl.git", from: "1.0.0"), .package(url: "https://github.com/IBM-Swift/BlueSSLService.git", from: "1.0.0") ] var kituraNetDependencies: [Target.Dependency] = [ - .byNameItem(name: "CHTTPParser"), - .byNameItem(name: "LoggerAPI"), - .byNameItem(name: "Socket"), - .byNameItem(name: "CCurl"), - .byNameItem(name: "SSLService") + .byName(name: "CHTTPParser"), + .byName(name: "LoggerAPI"), + .byName(name: "Socket"), + .target(name: "CCurl"), + .byName(name: "SSLService") ] #if os(Linux) dependencies.append(contentsOf: [ - .package(url: "https://github.com/IBM-Swift/CEpoll.git", from: "1.0.0"), .package(url: "https://github.com/IBM-Swift/BlueSignals.git", from: "1.0.0") ]) kituraNetDependencies.append(contentsOf: [ - .byNameItem(name: "CEpoll"), - .byNameItem(name: "Signals") + .target(name: "CEpoll"), + .byName(name: "Signals") ]) #endif +var targets: [Target] = [ + .target( + name: "CHTTPParser" + ), + .systemLibrary( + name: "CCurl" + ), + .target( + name: "KituraNet", + dependencies: kituraNetDependencies + ), + .testTarget( + name: "KituraNetTests", + dependencies: ["KituraNet"] + ) +] + +#if os(Linux) +targets.append( + .systemLibrary(name: "CEpoll") +) +#endif + let package = Package( name: "Kitura-net", products: [ @@ -56,19 +77,5 @@ let package = Package( ) ], dependencies: dependencies, - targets: [ - // Targets are the basic building blocks of a package. A target can define a module or a test suite. - // Targets can depend on other targets in this package, and on products in packages which this package depends on. - .target( - name: "CHTTPParser" - ), - .target( - name: "KituraNet", - dependencies: kituraNetDependencies - ), - .testTarget( - name: "KituraNetTests", - dependencies: ["KituraNet"] - ) - ] + targets: targets ) diff --git a/Package@swift-4.0.swift b/Package@swift-4.0.swift new file mode 100644 index 0000000..215b92a --- /dev/null +++ b/Package@swift-4.0.swift @@ -0,0 +1,74 @@ +// swift-tools-version:4.0 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +/** + * Copyright IBM Corporation 2016, 2017 + * + * 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 + +var dependencies: [Package.Dependency] = [ + .package(url: "https://github.com/IBM-Swift/LoggerAPI.git", from: "1.7.3"), + .package(url: "https://github.com/IBM-Swift/BlueSocket.git", from: "1.0.0"), + .package(url: "https://github.com/IBM-Swift/CCurl.git", from: "1.0.0"), + .package(url: "https://github.com/IBM-Swift/BlueSSLService.git", from: "1.0.0") +] + +var kituraNetDependencies: [Target.Dependency] = [ + .byNameItem(name: "CHTTPParser"), + .byNameItem(name: "LoggerAPI"), + .byNameItem(name: "Socket"), + .byNameItem(name: "CCurl"), + .byNameItem(name: "SSLService") +] + +#if os(Linux) +dependencies.append(contentsOf: [ + .package(url: "https://github.com/IBM-Swift/CEpoll.git", from: "1.0.0"), + .package(url: "https://github.com/IBM-Swift/BlueSignals.git", from: "1.0.0") + ]) + +kituraNetDependencies.append(contentsOf: [ + .byNameItem(name: "CEpoll"), + .byNameItem(name: "Signals") + ]) +#endif + +let package = Package( + name: "Kitura-net", + products: [ + // Products define the executables and libraries produced by a package, and make them visible to other packages. + .library( + name: "KituraNet", + targets: ["KituraNet"] + ) + ], + dependencies: dependencies, + targets: [ + // Targets are the basic building blocks of a package. A target can define a module or a test suite. + // Targets can depend on other targets in this package, and on products in packages which this package depends on. + .target( + name: "CHTTPParser" + ), + .target( + name: "KituraNet", + dependencies: kituraNetDependencies + ), + .testTarget( + name: "KituraNetTests", + dependencies: ["KituraNet"] + ) + ] +) diff --git a/Package@swift-4.1.swift b/Package@swift-4.1.swift new file mode 100644 index 0000000..215b92a --- /dev/null +++ b/Package@swift-4.1.swift @@ -0,0 +1,74 @@ +// swift-tools-version:4.0 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +/** + * Copyright IBM Corporation 2016, 2017 + * + * 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 + +var dependencies: [Package.Dependency] = [ + .package(url: "https://github.com/IBM-Swift/LoggerAPI.git", from: "1.7.3"), + .package(url: "https://github.com/IBM-Swift/BlueSocket.git", from: "1.0.0"), + .package(url: "https://github.com/IBM-Swift/CCurl.git", from: "1.0.0"), + .package(url: "https://github.com/IBM-Swift/BlueSSLService.git", from: "1.0.0") +] + +var kituraNetDependencies: [Target.Dependency] = [ + .byNameItem(name: "CHTTPParser"), + .byNameItem(name: "LoggerAPI"), + .byNameItem(name: "Socket"), + .byNameItem(name: "CCurl"), + .byNameItem(name: "SSLService") +] + +#if os(Linux) +dependencies.append(contentsOf: [ + .package(url: "https://github.com/IBM-Swift/CEpoll.git", from: "1.0.0"), + .package(url: "https://github.com/IBM-Swift/BlueSignals.git", from: "1.0.0") + ]) + +kituraNetDependencies.append(contentsOf: [ + .byNameItem(name: "CEpoll"), + .byNameItem(name: "Signals") + ]) +#endif + +let package = Package( + name: "Kitura-net", + products: [ + // Products define the executables and libraries produced by a package, and make them visible to other packages. + .library( + name: "KituraNet", + targets: ["KituraNet"] + ) + ], + dependencies: dependencies, + targets: [ + // Targets are the basic building blocks of a package. A target can define a module or a test suite. + // Targets can depend on other targets in this package, and on products in packages which this package depends on. + .target( + name: "CHTTPParser" + ), + .target( + name: "KituraNet", + dependencies: kituraNetDependencies + ), + .testTarget( + name: "KituraNetTests", + dependencies: ["KituraNet"] + ) + ] +) diff --git a/Sources/CCurl/module.modulemap b/Sources/CCurl/module.modulemap new file mode 100644 index 0000000..aaed0c0 --- /dev/null +++ b/Sources/CCurl/module.modulemap @@ -0,0 +1,21 @@ +/** + * Copyright IBM Corporation 2016 + * + * 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. + **/ + +module CCurl [system] { + header "shim.h" + link "curl" + export * +} diff --git a/Sources/CCurl/shim.h b/Sources/CCurl/shim.h new file mode 100644 index 0000000..4b56b6f --- /dev/null +++ b/Sources/CCurl/shim.h @@ -0,0 +1,85 @@ +/** + * Copyright IBM Corporation 2016 + * + * 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. + **/ + +#ifndef CurlHelpers_h +#define CurlHelpers_h + +#import + +#define CURL_TRUE 1 +#define CURL_FALSE 0 + +static inline CURLcode curlHelperSetOptBool(CURL *curl, CURLoption option, int yesNo) { + return curl_easy_setopt(curl, option, yesNo == CURL_TRUE ? 1L : 0L); +} + +// set options list - CURLOPT_HTTPHEADER, CURLOPT_HTTP200ALIASES, CURLOPT_QUOTE, CURLOPT_TELNETOPTIONS, CURLOPT_MAIL_RCPT, etc. +static inline CURLcode curlHelperSetOptList(CURL *curl, CURLoption option, struct curl_slist *list) { + return curl_easy_setopt(curl, option, list); +} + +__attribute__((deprecated("curlHelperSetOptHeaders has been deprecated please use curlHelperSetOptList(curl, CURLOPT_HTTPHEADER, headers) instead"))) +static inline CURLcode curlHelperSetOptHeaders(CURL *curl, struct curl_slist *headers) { + return curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); +} + +static inline CURLcode curlHelperSetOptInt(CURL *curl, CURLoption option, long data) { + return curl_easy_setopt(curl, option, data); +} + +// const keyword is used so that Swift strings can be passed +static inline CURLcode curlHelperSetOptString(CURL *curl, CURLoption option, const char *data) { + return curl_easy_setopt(curl, option, data); +} + +static inline CURLcode curlHelperSetOptReadFunc(CURL *curl, void *userData, size_t (*read_cb) (char *buffer, size_t size, size_t nitems, void *userdata)) { + + CURLcode rc = curl_easy_setopt(curl, CURLOPT_READDATA, userData); + if (rc == CURLE_OK) { + rc = curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_cb); + } + return rc; +} + +static inline CURLcode curlHelperSetOptWriteFunc(CURL *curl, void *userData, size_t (*write_cb) (char *ptr, size_t size, size_t nmemb, void *userdata)) { + + CURLcode rc = curl_easy_setopt(curl, CURLOPT_WRITEDATA, userData); + if (rc == CURLE_OK) { + rc = curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_cb); + } + return rc; +} + +static inline CURLcode curlHelperSetOptHeaderFunc(CURL *curl, void *userData, size_t (*header_cb) (char *buffer, size_t size, size_t nmemb, void *userdata)) { + + CURLcode rc = curl_easy_setopt(curl, CURLOPT_HEADERDATA, userData); + if (rc == CURLE_OK) { + rc = curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, header_cb); + } + return rc; +} + +static inline CURLcode curlHelperGetInfoCString(CURL *curl, CURLINFO info, char **data) { + return curl_easy_getinfo(curl, info, data); +} + + +static inline CURLcode curlHelperGetInfoLong(CURL *curl, CURLINFO info, long *data) { + return curl_easy_getinfo(curl, info, data); +} + + +#endif /* CurlHelpers_h */ diff --git a/Sources/CEpoll/module.modulemap b/Sources/CEpoll/module.modulemap new file mode 100644 index 0000000..0dc2ac1 --- /dev/null +++ b/Sources/CEpoll/module.modulemap @@ -0,0 +1,20 @@ +/** + * Copyright IBM Corporation 2016 + * + * 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. + **/ + +module CEpoll { + header "shim.h" + export * +} diff --git a/Sources/CEpoll/shim.h b/Sources/CEpoll/shim.h new file mode 100755 index 0000000..b3bad3e --- /dev/null +++ b/Sources/CEpoll/shim.h @@ -0,0 +1,23 @@ +/** + * Copyright IBM Corporation 2016 + * + * 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. + **/ + +#ifndef SocketUtilities_h +#define SocketUtilities_h + +#include +#include + +#endif /* SelectUtilities_h */