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

Replace bash use with dune-configurator #168

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
19 changes: 19 additions & 0 deletions config/discover.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module C = Configurator.V1

let extra_libs c =
match C.ocaml_config_var_exn c "system" with
| "mingw64" -> ["-ldbghelp"; "-liphlpapi"; "-lole32"; "-lpsapi"; "-luserenv"]
| _ -> []


let compiler_output_flag c =
match C.ocaml_config_var_exn c "ccomp_type" with
| "msvc" -> "-Fe:"
| _ -> "-o"


let () =
C.main ~name:"luv" (fun c ->
C.Flags.write_sexp "extra_libs.sexp" (extra_libs c);
C.Flags.write_lines "compiler_output_flag" [compiler_output_flag c];
)
8 changes: 8 additions & 0 deletions config/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(executable
(name discover)
(libraries dune.configurator))

(rule
(targets extra_libs.sexp compiler_output_flag)
(action
(run ./discover.exe)))
1 change: 1 addition & 0 deletions luv.opam
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ depends: [
"base-unix" {build}
"ctypes" {>= "0.14.0"}
"dune" {>= "2.7.0"}
"dune-configurator"
"integers" {>= "0.3.0"}
"ocaml" {>= "4.03.0"}

Expand Down
1 change: 1 addition & 0 deletions luv_unix.opam
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ depends: [
"base-unix"
"ctypes" {>= "0.14.0"} # Ctypes.CArray.of_string.
"dune" {>= "2.0.0"}
"dune-configurator"
"luv" {>= "0.5.8"} # uv.h.
"ocaml" {>= "4.03.0"}
]
Expand Down
29 changes: 7 additions & 22 deletions src/c/dune
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ let () = Jbuild_plugin.V1.send @@ {|
(names c_generated_functions helpers)
|}^ include_dirs ^{|)
|}^ foreign_archives ^{|
(c_library_flags |}^ uv_library_flag ^{| (:include extra_libs.sexp)))
(c_library_flags |}^ uv_library_flag ^{| (:include ../../config/extra_libs.sexp)))

|}^ (if not install_h then "" else {|

Expand Down Expand Up @@ -96,15 +96,6 @@ let () = Jbuild_plugin.V1.send @@ {|
cp vendor/libuv/libuv.1.dylib dlluv.so || \
cp vendor/bin/libuv-1.dll dlluv.dll")))))

(rule
(targets extra_libs.sexp)
(action (ignore-outputs (bash "\
if ocamlc -config | grep mingw; then \
echo '(-ldbghelp -liphlpapi -lole32 -lpsapi -luserenv)' > extra_libs.sexp; \
else \
echo '()' > extra_libs.sexp; \
fi"))))



; Everything below is the bindings generation process using ctypes. It produces
Expand All @@ -131,18 +122,12 @@ let () = Jbuild_plugin.V1.send @@ {|
(rule
(targets generate_types_step_2.exe)
(deps (:c generate_types_step_2.c) helpers.h shims.h)
(action (bash "\
if [ '%{ocaml-config:ccomp_type}' = 'msvc' ]; then \
%{cc} %{c} \
-I '%{lib:ctypes:.}' \
-I '%{ocaml_where}' \
|}^ i_option ^{| /Fe\"%{targets}\"; \
else \
%{cc} %{c} \
-I '%{lib:ctypes:.}' \
-I '%{ocaml_where}' \
|}^ i_option ^{| -o %{targets}; \
fi")))
(action (run
%{cc} %{c}
-I "%{lib:ctypes:.}"
-I "%{ocaml_where}"
|}^ i_option ^{| %{read-lines:../../config/compiler_output_flag} %{targets}
)))

(rule
(with-stdout-to luv_c_generated_types.ml
Expand Down