sqlite3-ocaml
sqlite3-ocaml copied to clipboard
Windows support
Here are my efforts to fix https://github.com/mmottl/sqlite3-ocaml/issues/35. I had to build sqlite3 from sources that was much easier that fighting against pkg-config on different platforms. @mmottl, do you think it's acceptable?
Thanks @db4, I have cherry-picked the first two patches in this PR. Questions on how to handle SQLite3 installations on Windows will still need to be resolved, possibly by improving OPAM on Windows. Please feel free to submit any other patches that make life easier for Windows developers.
Two brief comments:
- One solution to the lack of
extra-sources
filtering is to put the URL in another package and depend on it (see the way theocaml-config
package is used in opam-repository) - Various things in motion for improving depext and C dependency story in general - @dbuenzli's suggestion of a variant of the
conf-sqlite3
package would be compatible with it - i.e. have conf-sqlite3 which uses pkg-config and orsqlite3-from-sources
or something which builds it and depend on one or the other.
@dra27 I've looked into depext
sources - it's relatively easy to adapt it for conan
, but the latter needs arch
, compiler
, compiler-version
to fetch or build the necessary C library. Unfortunately this info is not stored in OPAM (except arch
). I can find compiler
in ocamlc -config
but not its version. How do you think what is the best way to detect it inside depext
?
The current state of master
does not compile on my Windows environment. Here is the patch that I had to apply
diff --git a/src/dune b/src/dune
index 01bf123..f36bc09 100644
--- a/src/dune
+++ b/src/dune
@@ -6,7 +6,7 @@
; NOTE: for debugging before releases
; -Wall -pedantic -Wextra -Wunused -Wno-long-long -Wno-keyword-macro
))
- (c_library_flags (:include c_library_flags.sexp) -lpthread)
+ (c_library_flags (:include c_library_flags.sexp))
)
(rule
diff --git a/src/sqlite3_stubs.c b/src/sqlite3_stubs.c
index 0146298..dec8305 100644
--- a/src/sqlite3_stubs.c
+++ b/src/sqlite3_stubs.c
@@ -79,7 +79,7 @@
#include <windows.h>
typedef DWORD pthread_key_t;
-void destroy_user_exception(void *user_exc_);
+static void destroy_user_exception(void *user_exc_);
static int pthread_key_create(pthread_key_t *key, void (*destructor)(void*))
{
The first hunk is self-explanatory. For the second one, this is the error I was getting
sqlite3_stubs.c:162:20: error: static declaration of 'destroy_user_exception' follows non-static declaration
static inline void destroy_user_exception(void *user_exc_)
^~~~~~~~~~~~~~~~~~~~~~
sqlite3_stubs.c:82:6: note: previous declaration of 'destroy_user_exception' was here
void destroy_user_exception(void *user_exc_);
^~~~~~~~~~~~~~~~~~~~~~
@yakobowski your compiler must be gcc/mingw? I use MSVC 2017 and it doesn't throw an error. But you are right, the second problem should be fixed that way.
As for the first chunk, it's enough for gcc/mingw but not enough for MSVC (compiler-dependent flags -g -fPIC -DPIC
are still hard-coded). And doing so you break Unix build that requires -lpthread
. So I would fix it changing src/config/discover.ml
that should detect compiler/os and write correct c_flags.sexp
and c_library_flags.sexp
Yes I'm compiling with Mingw. And you're right of course, the change in the dune file must be conditional. I will try to refine it.
Thanks @yakobowski, I've added the missing static
declaration and will wait for any other patches that improve the build process on Windows without breaking it for other platforms.
@yakobowski Are you still working on any Windows build process improvements? If not, please let me know whether I can close this pull request, since the contained changes should be in the tree already.
Hi @mmottl. Sorry, I completely missed that one at the time. I'm not detection savvy enough to propose a correct patch, so I suggest to leave things as is for now.