Skip to content

Commit

Permalink
Merge pull request #4 from apeschar/pkg-config
Browse files Browse the repository at this point in the history
Use pkg-config to discover libsodium
  • Loading branch information
rr0gi authored Oct 31, 2023
2 parents 565694d + 658ec98 commit 734eccb
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
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

0 comments on commit 734eccb

Please sign in to comment.