From 8cdd9984eede06464850664bb6cafbf7977a3d1b Mon Sep 17 00:00:00 2001 From: Collin Hundley Date: Mon, 8 Aug 2016 15:07:53 -0600 Subject: [PATCH 1/5] Add compiler flag for MariaDB compatibility --- module.modulemap | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/module.modulemap b/module.modulemap index 0c2f759..d3d5613 100644 --- a/module.modulemap +++ b/module.modulemap @@ -1,8 +1,16 @@ +#if MARIADB +module CMySQLLinux [system] { + header "/usr/include/mariadb/mysql.h" + link "mariadb" + export * +} +#else module CMySQLLinux [system] { header "/usr/include/mysql/mysql.h" link "mysqlclient" export * } +#endif module CMySQLMac [system] { header "/usr/local/include/mysql/mysql.h" From 21a954cf9c0cef52c9e7f1ab57a54e887b311815 Mon Sep 17 00:00:00 2001 From: Collin Hundley Date: Mon, 8 Aug 2016 15:13:15 -0600 Subject: [PATCH 2/5] Update README.md --- README.md | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 8bb1db6..c527d38 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,31 @@ -# Qutheory - CMySQL - (Not Tested) +# CMySQL +C module for MySQL -## Install MySQL via Brew (OS X) -follow link to download page http://dev.mysql.com/downloads/mysql/ +## Building -You may need to use the following command to build if you experience errors. +**To build on macOS:** ```sh -swift build -Xswiftc -I -Xswiftc /usr/local/mysql/include/ -Xlinker -L -Xlinker /usr/local/mysql/lib/ +swift build -Xlinker -L/usr/local/lib ``` -## Install MySQL via APT-GET (Linux) +**To build on Linux:** -* Update your system (you may need ```sudo```): -``` -apt-get update -apt-get upgrade +```sh +swift build -Xswiftc -I/usr/include/mariadb -Xlinker -L/usr/lib/x86_64-linux-gnu ``` -* To install MySQL ... +- `-I` tells the compiler where to find the MariaDB header file `mysql.h` +- `-L` tells the linker where to find MariaDB library. + - On macOS the library is called `libmysqlclient`, and on Linux the library is `libmariadb`. + +## MariaDB -``` -apt-get install mysql-server +To use MariaDB instead of MySQL, add the following compiler flag when building: + +```sh +-Xswiftc -DMYSQL ``` +- This tells the compiler to link the MariaDB library instead of the MySQL library. From bbf7e00b7e8d8eb487bba906529ef1ca16b727f2 Mon Sep 17 00:00:00 2001 From: Collin Hundley Date: Mon, 8 Aug 2016 15:13:42 -0600 Subject: [PATCH 3/5] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c527d38..568dbf4 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ swift build -Xswiftc -I/usr/include/mariadb -Xlinker -L/usr/lib/x86_64-linux-gnu To use MariaDB instead of MySQL, add the following compiler flag when building: ```sh --Xswiftc -DMYSQL +-Xswiftc -DMARIADB ``` - This tells the compiler to link the MariaDB library instead of the MySQL library. From b860291faa4333f85508e041f06f6522ce84d832 Mon Sep 17 00:00:00 2001 From: Collin Hundley Date: Mon, 8 Aug 2016 15:55:58 -0600 Subject: [PATCH 4/5] Update module.modulemap --- module.modulemap | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/module.modulemap b/module.modulemap index d3d5613..22165c1 100644 --- a/module.modulemap +++ b/module.modulemap @@ -1,16 +1,14 @@ -#if MARIADB -module CMySQLLinux [system] { - header "/usr/include/mariadb/mysql.h" - link "mariadb" - export * -} -#else module CMySQLLinux [system] { header "/usr/include/mysql/mysql.h" link "mysqlclient" export * } -#endif + +module CMariaDBLinux [system] { + header "/usr/include/mariadb/mysql.h" + link "mariadb" + export * +} module CMySQLMac [system] { header "/usr/local/include/mysql/mysql.h" From 57367fbe29bb5033351575a31ca11c638dce896a Mon Sep 17 00:00:00 2001 From: Collin Hundley Date: Fri, 12 Aug 2016 13:34:26 -0600 Subject: [PATCH 5/5] Fix build instructions for MySQL vs MariaDB --- README.md | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 568dbf4..022fe10 100644 --- a/README.md +++ b/README.md @@ -6,26 +6,35 @@ C module for MySQL **To build on macOS:** ```sh -swift build -Xlinker -L/usr/local/lib +swift build -Xswiftc -I/usr/local/include/mysql -Xlinker -L/usr/local/lib ``` +- `-I` tells the compiler where to find the MySQL header file `mysql.h`. +- `-L` tells the linker where to find MySQL library `libmysqlclient`. + **To build on Linux:** +`swift build` should work normally. + +## MariaDB + +To use MariaDB instead of MySQL, you just need to change a couple of the compiler flags. + +**macOS:** + ```sh -swift build -Xswiftc -I/usr/include/mariadb -Xlinker -L/usr/lib/x86_64-linux-gnu +swift build -Xlinker -L/usr/local/lib -Xswiftc -DMARIADB -Xswiftc -DNOJSON ``` -- `-I` tells the compiler where to find the MariaDB header file `mysql.h` -- `-L` tells the linker where to find MariaDB library. - - On macOS the library is called `libmysqlclient`, and on Linux the library is `libmariadb`. - -## MariaDB +- `-DMARIADB` tells the compiler to link the MariaDB library instead of the MySQL library. +- `-DNOJSON` tells the package to ignore the `JSON` type (not supported as of MariaDB 10.1.16). -To use MariaDB instead of MySQL, add the following compiler flag when building: +**Linux:** ```sh --Xswiftc -DMARIADB +swift build -Xswiftc -I/usr/include/mariadb -Xlinker -L/usr/lib/x86_64-linux-gnu -Xswiftc -DMARIADB -Xswiftc -DNOJSON ``` -- This tells the compiler to link the MariaDB library instead of the MySQL library. +- This simply changes the library/header paths and sets the same compatibility options shown above. +- Note that on macOS the library is called `libmysqlclient`, while on Linux the library is called `libmariadb`.