Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use pkg-config to discover libsodium #4

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions config/discover.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module C = Configurator.V1

let () =
C.main ~name:"sodium" (fun c ->
let default : C.Pkg_config.package_conf =
{ libs = [ "-lsodium" ]; cflags = [] }
in
let conf =
match C.Pkg_config.get c with
| None -> default
| Some pc -> (
match C.Pkg_config.query pc ~package:"libsodium" with
| None -> default
| Some deps -> deps)
in
C.Flags.write_sexp "c_flags.sexp" conf.cflags;
C.Flags.write_sexp "c_library_flags.sexp" conf.libs)
7 changes: 7 additions & 0 deletions config/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(executable
(name discover)
(libraries dune-configurator))

(rule
(targets c_flags.sexp c_library_flags.sexp)
(action (run ./discover.exe)))
2 changes: 1 addition & 1 deletion lib/dune
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(name sodium)
(public_name sodium)
(libraries ctypes sodium.storage sodium.generated)
(c_library_flags :standard -lsodium)
(c_library_flags (:include ../config/c_library_flags.sexp))
(modules :standard \ sodium_storage))

(library
Expand Down
5 changes: 3 additions & 2 deletions lib_gen/dune
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
(library
(name sodium_generated)
(public_name sodium.generated)
(c_library_flags :standard -lsodium)
(c_flags (:include ../config/c_flags.sexp))
(c_library_flags (:include ../config/c_library_flags.sexp))
(libraries ctypes.stubs sodium_bindings)
(modules sodium_generated)
(c_names sodium_stubs))
Expand Down Expand Up @@ -38,7 +39,7 @@
(rule
(deps sodium_types_detect.c)
(targets sodium_types_detect)
(action (bash "cc -I \"$(ocamlfind query ctypes)\" -I \"$(ocamlc -where)\" -o sodium_types_detect sodium_types_detect.c")))
(action (bash "cc -I \"$(ocamlfind query ctypes)\" -I \"$(ocamlc -where)\" $(pkg-config --cflags libsodium) -o sodium_types_detect sodium_types_detect.c")))

(rule
(deps sodium_types_detect)
Expand Down
Loading