Skip to content

Commit

Permalink
Search and use libev **after** pthreads
Browse files Browse the repository at this point in the history
If we consider pthread as the default implementation needed by lwt, we
should prioritize the recognition of [pthread] before [libev] but more
concretely, due to the undeterministic behavior of [discover.exe] and
our usage of [C_library_flags.set_{c,link}_flags] to reset any flags
when we can link [pthread] from a cross-compiler, it seems that we reset
aggregate flags needed for [libev] (specially [-lev]) in the same time.

This patch aggregate flags needed for [pthread] first and let the
recognition of [libev] then. However, that mostly means that in the
context of the cross-compilation, the user must NOT install
[conf-libev] (otherwise, we will try to link with the host's [libev]
which is obviously incompatible with our cross-compiler). This patch
wants to keep, as much as we can, the same behavior - but it highlights
limits of [discover.exe].
  • Loading branch information
dinosaure committed Jun 15, 2022
1 parent 97a564d commit d45588c
Showing 1 changed file with 52 additions and 52 deletions.
104 changes: 52 additions & 52 deletions src/unix/config/discover.ml
Original file line number Diff line number Diff line change
Expand Up @@ -404,58 +404,6 @@ struct
| Some true -> None
| _ -> k ()

let () = feature {
pretty_name = "libev";
macro_name = "HAVE_LIBEV";
detect = fun context ->
let detect_esy_wants_libev () =
match Sys.getenv "cur__target_dir" with
| exception Not_found -> None
| _ ->
match Sys.getenv "LIBEV_CFLAGS", Sys.getenv "LIBEV_LIBS" with
| exception Not_found -> Some false
| "", "" -> Some false
| _ -> Some true
in

let should_look_for_libev =
match !Arguments.use_libev with
| Some argument ->
argument
| None ->
match detect_esy_wants_libev () with
| Some result ->
result
| None ->
(* we're not under esy *)
let os = Configurator.ocaml_config_var_exn context "os_type" in
os <> "Win32" && !Arguments.android_target <> Some true
in

if not should_look_for_libev then
None
else begin
let code = {|
#include <ev.h>

int main()
{
ev_default_loop(0);
return 0;
}
|}
in
match compiles context code ~link_flags:["-lev"] with
| Some true ->
C_library_flags.add_link_flags ["-lev"];
Some true
| _ ->
C_library_flags.add_link_flags ["-lev"];
C_library_flags.detect context ~library:"ev";
compiles context code
end
}

let () = feature {
pretty_name = "pthread";
macro_name = "HAVE_PTHREAD";
Expand Down Expand Up @@ -526,6 +474,58 @@ struct
end
}

let () = feature {
pretty_name = "libev";
macro_name = "HAVE_LIBEV";
detect = fun context ->
let detect_esy_wants_libev () =
match Sys.getenv "cur__target_dir" with
| exception Not_found -> None
| _ ->
match Sys.getenv "LIBEV_CFLAGS", Sys.getenv "LIBEV_LIBS" with
| exception Not_found -> Some false
| "", "" -> Some false
| _ -> Some true
in

let should_look_for_libev =
match !Arguments.use_libev with
| Some argument ->
argument
| None ->
match detect_esy_wants_libev () with
| Some result ->
result
| None ->
(* we're not under esy *)
let os = Configurator.ocaml_config_var_exn context "os_type" in
os <> "Win32" && !Arguments.android_target <> Some true
in

if not should_look_for_libev then
None
else begin
let code = {|
#include <ev.h>

int main()
{
ev_default_loop(0);
return 0;
}
|}
in
match compiles context code ~link_flags:("-lev" :: C_library_flags.link_flags ()) with
| Some true ->
C_library_flags.add_link_flags ["-lev"];
Some true
| _ ->
(* C_library_flags.add_link_flags ["-lev"]; *)
C_library_flags.detect context ~library:"ev";
compiles context code
end
}

let () = feature {
pretty_name = "eventfd";
macro_name = "HAVE_EVENTFD";
Expand Down

0 comments on commit d45588c

Please sign in to comment.