From 3582118b7c7a823798a68463f851db59fa5eacb4 Mon Sep 17 00:00:00 2001 From: youyuanwu <48816116+youyuanwu@users.noreply.github.com> Date: Mon, 7 Jun 2021 04:02:15 -0700 Subject: [PATCH] mssql: support windows (#10336) --- thirdparty/mssql/include/.gitignore | 4 ++++ thirdparty/mssql/include/mssql.h | 20 ++++++++++++++++++ vlib/mssql/README.md | 32 ++++++++++++++++++++++++----- vlib/mssql/_cdef_windows.c.v | 13 +++++++++--- 4 files changed, 61 insertions(+), 8 deletions(-) create mode 100644 thirdparty/mssql/include/.gitignore create mode 100644 thirdparty/mssql/include/mssql.h diff --git a/thirdparty/mssql/include/.gitignore b/thirdparty/mssql/include/.gitignore new file mode 100644 index 000000000..773ce2768 --- /dev/null +++ b/thirdparty/mssql/include/.gitignore @@ -0,0 +1,4 @@ +* + +!.gitignore +!mssql.h \ No newline at end of file diff --git a/thirdparty/mssql/include/mssql.h b/thirdparty/mssql/include/mssql.h new file mode 100644 index 000000000..d38768c8a --- /dev/null +++ b/thirdparty/mssql/include/mssql.h @@ -0,0 +1,20 @@ +// Hacking some headers in windows. +// sql headers using UNICODE to change function signatures. +// Currently Linux bindings do not use unicode SQL C bindings, +// So we turn off the UNICODE to make it compile on windows. +// For future Unicode support, please raise a issue. + +#include +#include + +#ifdef UNICODE +// Turn off unicode macro and turn back on, so it only affects sql headers +#undef UNICODE +#include +#include +#define UNICODE + +#else +#include +#include +#endif \ No newline at end of file diff --git a/vlib/mssql/README.md b/vlib/mssql/README.md index 088d6c5eb..ff4fefc22 100644 --- a/vlib/mssql/README.md +++ b/vlib/mssql/README.md @@ -4,14 +4,36 @@ ## Dependencies * ODBC C/C++ library - * Linux Install: https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server - * `msodbcsql17` and `unixodbc-dev` packages needed - * Windows Install: https://docs.microsoft.com/en-us/sql/connect/odbc/microsoft-odbc-driver-for-sql-server + * Linux Install: + * Details: https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server + * `msodbcsql17` and `unixodbc-dev` packages are needed + * Windows Install: + * `odbc` lib is included in windows sdk for most of distributions, + so there is no need to install it separately + * Details: https://docs.microsoft.com/en-us/sql/connect/odbc/microsoft-odbc-driver-for-sql-server + +## Windows Notes +### Using `msvc` +* Make sure `cl.exe` of `msvc` is accessible from command line. +You can run `v` commands in `Visual Studio 2019 Developer Command Prompt` to be safe. +* C Headers and dlls can be automatically resolved by `msvc`. +### Using `tcc` +* Copy those headers to `@VEXEROOT\thirdparty\mssql\include`. +The version number `10.0.18362.0` might differ on your system. +Command Prompt commands: +```cmd +copy "C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\sql.h" thirdparty\mssql\include +copy "C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\sqlext.h" thirdparty\mssql\include +copy "C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\sqltypes.h" thirdparty\mssql\include +copy "C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\sqlucode.h" thirdparty\mssql\include +copy "C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\shared\sal.h" thirdparty\mssql\include +copy "C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\shared\concurrencysal.h" thirdparty\mssql\include +``` +* dlls can be automatically resolved by `tcc` ## TODO -* Support Windows * Support Mac -* ORM +* Support ORM ## Usage ```v ignore diff --git a/vlib/mssql/_cdef_windows.c.v b/vlib/mssql/_cdef_windows.c.v index 5e81e6d5b..61724eecc 100644 --- a/vlib/mssql/_cdef_windows.c.v +++ b/vlib/mssql/_cdef_windows.c.v @@ -1,5 +1,12 @@ module mssql -// TODO: implement windows -// #flag windows -I@VEXEROOT/thirdparty/msodbcsql17 -// #flag windows @VEXEROOT/thirdparty/msodbcsql17/lib64 +// mssql module does not support tcc on windows + +// odbc32 lib comes with windows sdk and does not need to be installed separately. +// v builder for msvc can resolve the sdk includes search path, so no need to repeat here. +#flag windows -lodbc32 + +// Special handling of sql headers on windows. +// Source is in v third party folder. +#flag windows -I@VEXEROOT/thirdparty/mssql/include +#include -- 2.30.2