From d18bcbfa6885381f36f93dc819507c4d5e73e48d Mon Sep 17 00:00:00 2001 From: Jonah Beckford <71855677+jonahbeckford@users.noreply.github.com> Date: Fri, 21 Jul 2023 19:17:55 -0700 Subject: [PATCH] Support MSVC compiler - No assuming -lpthread and -O2 -fPIC are valid for all compilers - This commit/PR fixes the release profile only, and does not touch the -Wextra used in the dev profile that is invalid in MSVC --- CHANGES.md | 4 ++++ src/config/discover.ml | 16 +++++++++++++++- src/dune | 4 ++-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index e05d657..d06b465 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,7 @@ +### Pending + + * Don't use `-lpthread` and non-MSVC flags with MSVC compiler + ### 5.1.0 (2021-09-22) * Added let&-operator for implicit closing of an opened database. diff --git a/src/config/discover.ml b/src/config/discover.ml index df544bd..0976904 100644 --- a/src/config/discover.ml +++ b/src/config/discover.ml @@ -66,9 +66,23 @@ let split_ws str = done; List.rev !lst +let add_compiler_args ~is_msvc ~cflags ~libs = + let module C = Configurator.V1 in + match is_msvc with + | true -> { + C.Pkg_config.cflags = cflags @ ["/O2"]; + libs } + | false -> { + C.Pkg_config.cflags = cflags @ ["-O2"; "-fPIC"; "-DPIC"]; + libs = libs @ ["-lpthread"] } + let () = let module C = Configurator.V1 in C.main ~name:"sqlite3" (fun c -> + let is_msvc = + opt_map (C.ocaml_config_var c "ccomp_type") ~default:false + ~f:(function "msvc" -> true | _ -> false) + in let is_macosx = opt_map (C.ocaml_config_var c "system") ~default:false ~f:(function "macosx" -> true | _ -> false) @@ -92,6 +106,6 @@ let () = | [libs] -> split_ws libs | _ -> failwith "pkg-config failed to return libs" in - let conf = { C.Pkg_config.cflags; libs } in + let conf = add_compiler_args ~is_msvc ~cflags ~libs in C.Flags.write_sexp "c_flags.sexp" conf.cflags; C.Flags.write_sexp "c_library_flags.sexp" conf.libs) diff --git a/src/dune b/src/dune index 2b9a0d2..e821415 100644 --- a/src/dune +++ b/src/dune @@ -3,8 +3,8 @@ (foreign_stubs (language c) (names sqlite3_stubs) - (flags (:standard) (:include c_flags.sexp) -O2 -fPIC -DPIC)) - (c_library_flags (:include c_library_flags.sexp) -lpthread) + (flags (:standard) (:include c_flags.sexp))) + (c_library_flags (:include c_library_flags.sexp)) ) (rule