From cc3035e12c4ea02361a42169613766c947991827 Mon Sep 17 00:00:00 2001 From: Yusuke Ito Date: Sun, 9 Jun 2019 19:51:02 +0900 Subject: [PATCH 1/4] fix warning add Package manifesto for Swift 5 --- .circleci/config.yml | 31 ++++++++++++++++++++++++- Package.resolved | 16 ------------- Package@swift-5.swift | 41 +++++++++++++++++++++++++++++++++ README.md | 1 - Sources/MySQL/IDType.swift | 6 +++++ Sources/cmysql/macos.pc | 9 ++++++++ Sources/cmysql/module.modulemap | 5 ++++ Sources/cmysql/shim.h | 6 +++++ 8 files changed, 97 insertions(+), 18 deletions(-) delete mode 100644 Package.resolved create mode 100644 Package@swift-5.swift create mode 100644 Sources/cmysql/macos.pc create mode 100644 Sources/cmysql/module.modulemap create mode 100644 Sources/cmysql/shim.h diff --git a/.circleci/config.yml b/.circleci/config.yml index 481a3dc..1e03329 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -12,6 +12,18 @@ jobs: - run: mysql -u root -e "create database IF NOT EXISTS test;" - run: swift build - run: swift test + mac-swift5.0: + macos: + xcode: "10.2.0" + steps: + - checkout + - run: brew update + - run: brew install https://gist.github.com/novi/dd21d48d260379e8919d9490bf5cfaec/raw/6ea4daa02d93f4ab0110ad30d87ea2b497a71cd0/cmysqlmariadb.rb #cmysql + - run: mkdir -p /usr/local/etc/my.cnf.d #workaround + - run: mysql.server start + - run: mysql -u root -e "create database IF NOT EXISTS test;" + - run: swift build + - run: swift test linux-swift4.1: docker: - image: yusukeito/swift-basic:swift4.1 @@ -42,11 +54,28 @@ jobs: - run: sleep 5 #wait for mysql - run: swift build - run: swift test + linux-swift5.0: + docker: + - image: yusukeito/swift-basic:swift5 + - image: mariadb:10.3 + environment: + MYSQL_USER: root + MYSQL_DATABASE: "test" + MYSQL_ALLOW_EMPTY_PASSWORD: yes + MYSQL_ROOT_HOST: "%" + DATABASE_HOST: "%" + steps: + - checkout + - run: sleep 5 #wait for mysql + - run: swift build + - run: swift test workflows: version: 2 build_and_test: jobs: - mac-swift4.2 + - mac-swift5.0 - linux-swift4.1 - - linux-swift4.2 \ No newline at end of file + - linux-swift4.2 + - linux-swift5.0 \ No newline at end of file diff --git a/Package.resolved b/Package.resolved deleted file mode 100644 index 669e9dd..0000000 --- a/Package.resolved +++ /dev/null @@ -1,16 +0,0 @@ -{ - "object": { - "pins": [ - { - "package": "CMySQL", - "repositoryURL": "https://github.com/novi/cmysql.git", - "state": { - "branch": null, - "revision": "dee1732e79a4e49cb4433804983eccb262e2e5d8", - "version": "2.0.4" - } - } - ] - }, - "version": 1 -} diff --git a/Package@swift-5.swift b/Package@swift-5.swift new file mode 100644 index 0000000..59d200f --- /dev/null +++ b/Package@swift-5.swift @@ -0,0 +1,41 @@ +// swift-tools-version:5.0 +import PackageDescription + +let package = Package( + name: "MySQL", + products: [ + .library(name: "MySQL", targets: ["MySQL"]) + ], + targets: [ + .systemLibrary( + name: "CMySQL", + pkgConfig: "cmysql", + providers: [ + .brew(["mysql"]), + .apt(["libmysqlclient"]) + ] + ), + .target( + name: "SQLFormatter" + ), + .target( + name: "MySQL", + dependencies: [ + "CMySQL", + "SQLFormatter", + ] + ), + .testTarget( + name: "MySQLTests", + dependencies: [ + "MySQL" + ] + ), + .testTarget( + name: "SQLFormatterTests", + dependencies: [ + "MySQL" + ] + ) + ] +) diff --git a/README.md b/README.md index ab83b31..d5f2b41 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ mysql-swift =========== -[![Swift 4.1](https://img.shields.io/badge/Swift-4.1-orange.svg)](https://swift.org) ![Platform Linux, macOS](https://img.shields.io/badge/Platforms-Linux%2C%20macOS-lightgray.svg) [![CircleCI](https://circleci.com/gh/novi/mysql-swift.svg?style=svg)](https://circleci.com/gh/novi/mysql-swift) diff --git a/Sources/MySQL/IDType.swift b/Sources/MySQL/IDType.swift index cdb066c..b5bfa6f 100644 --- a/Sources/MySQL/IDType.swift +++ b/Sources/MySQL/IDType.swift @@ -19,9 +19,15 @@ public extension IDType { func queryParameter(option: QueryParameterOption) throws -> QueryParameterType { return try id.queryParameter(option: option) } + #if swift(>=4.2) + func hash(into hasher: inout Hasher) { + hasher.combine(id) + } + #else var hashValue: Int { return id.hashValue } + #endif } extension IDType where Self: SQLRawStringDecodable, Self.T: SQLRawStringDecodable { diff --git a/Sources/cmysql/macos.pc b/Sources/cmysql/macos.pc new file mode 100644 index 0000000..055b192 --- /dev/null +++ b/Sources/cmysql/macos.pc @@ -0,0 +1,9 @@ +prefix=/usr/local/opt/mysql +exec_prefix=${prefix} +libdir=${exec_prefix}/lib +includedir=${prefix}/include +Name: MySQL +Description: MySQL client library +Version: 2.0 +Cflags: -I${includedir} +Libs: -L${libdir} -lmysqlclient diff --git a/Sources/cmysql/module.modulemap b/Sources/cmysql/module.modulemap new file mode 100644 index 0000000..849eb6b --- /dev/null +++ b/Sources/cmysql/module.modulemap @@ -0,0 +1,5 @@ +module CMySQL [system] { + header "shim.h" + link "mysqlclient" + export * +} diff --git a/Sources/cmysql/shim.h b/Sources/cmysql/shim.h new file mode 100644 index 0000000..645252d --- /dev/null +++ b/Sources/cmysql/shim.h @@ -0,0 +1,6 @@ +#ifndef __CMYSQL_SHIM_H__ +#define __CMYSQL_SHIM_H__ + +#include + +#endif From 920e551e7aa856df56f4d8f2380467387c3c4c32 Mon Sep 17 00:00:00 2001 From: Yusuke Ito Date: Sun, 9 Jun 2019 20:01:57 +0900 Subject: [PATCH 2/4] update Swift image for CI --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 1e03329..3ed1295 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -56,7 +56,7 @@ jobs: - run: swift test linux-swift5.0: docker: - - image: yusukeito/swift-basic:swift5 + - image: yusukeito/swift-basic:swift5.0 - image: mariadb:10.3 environment: MYSQL_USER: root From 9ae8f0487fbeb6e25a6ba4a3652612b7f69fba67 Mon Sep 17 00:00:00 2001 From: Yusuke Ito Date: Sun, 9 Jun 2019 22:02:49 +0900 Subject: [PATCH 3/4] update Package.swift --- Package@swift-5.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Package@swift-5.swift b/Package@swift-5.swift index 59d200f..97362ff 100644 --- a/Package@swift-5.swift +++ b/Package@swift-5.swift @@ -9,10 +9,11 @@ let package = Package( targets: [ .systemLibrary( name: "CMySQL", + path: "Sources/cmysql", pkgConfig: "cmysql", providers: [ - .brew(["mysql"]), - .apt(["libmysqlclient"]) + .brew(["cmysql"]), + .apt(["libmysqlclient-dev"]) ] ), .target( From aac1cbb4d34f3880f2e43d4724f228ea4004b044 Mon Sep 17 00:00:00 2001 From: Yusuke Ito Date: Sun, 9 Jun 2019 22:46:43 +0900 Subject: [PATCH 4/4] Support MySQL8 on macOS --- .circleci/config.yml | 12 ++++++++++++ README.md | 4 ++-- Sources/cmysql/shim.h | 5 +++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 3ed1295..0e0b6c0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -24,6 +24,17 @@ jobs: - run: mysql -u root -e "create database IF NOT EXISTS test;" - run: swift build - run: swift test + mac-swift5.0-mysql: + macos: + xcode: "10.2.0" + steps: + - checkout + - run: brew update + - run: brew install https://gist.githubusercontent.com/novi/c6d4afa6e9f9cc9c426e3ccd140c3c74/raw/7130ad1d5062cdb2f7492d42e8d5574b864f3e18/cmysql.rb + - run: mysql.server start + - run: mysql -u root -e "create database IF NOT EXISTS test;" + - run: swift build + - run: swift test linux-swift4.1: docker: - image: yusukeito/swift-basic:swift4.1 @@ -76,6 +87,7 @@ workflows: jobs: - mac-swift4.2 - mac-swift5.0 + - mac-swift5.0-mysql - linux-swift4.1 - linux-swift4.2 - linux-swift5.0 \ No newline at end of file diff --git a/README.md b/README.md index d5f2b41..0bcccde 100644 --- a/README.md +++ b/README.md @@ -70,9 +70,9 @@ Install pkg-config `.pc` file in [cmysql](https://github.com/vapor-community/cmy ```sh # cmysql -$ brew tap vapor/homebrew-tap && brew install cmysql +$ brew install https://gist.githubusercontent.com/novi/c6d4afa6e9f9cc9c426e3ccd140c3c74/raw/7130ad1d5062cdb2f7492d42e8d5574b864f3e18/cmysql.rb # cmysql-mariadb -$ brew install https://gist.github.com/novi/dd21d48d260379e8919d9490bf5cfaec/raw/6ea4daa02d93f4ab0110ad30d87ea2b497a71cd0/cmysqlmariadb.rb +$ brew install https://gist.githubusercontent.com/novi/dd21d48d260379e8919d9490bf5cfaec/raw/6ea4daa02d93f4ab0110ad30d87ea2b497a71cd0/cmysqlmariadb.rb ``` ## Ubuntu diff --git a/Sources/cmysql/shim.h b/Sources/cmysql/shim.h index 645252d..290fc66 100644 --- a/Sources/cmysql/shim.h +++ b/Sources/cmysql/shim.h @@ -3,4 +3,9 @@ #include +#if LIBMYSQL_VERSION_ID >= 80000 +typedef int my_bool; #endif + +#endif +