Skip to content

Commit 80d6996

Browse files
committed
Search and use libev **after** pthreads
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].
1 parent b492499 commit 80d6996

File tree

1 file changed

+52
-52
lines changed

1 file changed

+52
-52
lines changed

src/unix/config/discover.ml

+52-52
Original file line numberDiff line numberDiff line change
@@ -404,58 +404,6 @@ struct
404404
| Some true -> None
405405
| _ -> k ()
406406

407-
let () = feature {
408-
pretty_name = "libev";
409-
macro_name = "HAVE_LIBEV";
410-
detect = fun context ->
411-
let detect_esy_wants_libev () =
412-
match Sys.getenv "cur__target_dir" with
413-
| exception Not_found -> None
414-
| _ ->
415-
match Sys.getenv "LIBEV_CFLAGS", Sys.getenv "LIBEV_LIBS" with
416-
| exception Not_found -> Some false
417-
| "", "" -> Some false
418-
| _ -> Some true
419-
in
420-
421-
let should_look_for_libev =
422-
match !Arguments.use_libev with
423-
| Some argument ->
424-
argument
425-
| None ->
426-
match detect_esy_wants_libev () with
427-
| Some result ->
428-
result
429-
| None ->
430-
(* we're not under esy *)
431-
let os = Configurator.ocaml_config_var_exn context "os_type" in
432-
os <> "Win32" && !Arguments.android_target <> Some true
433-
in
434-
435-
if not should_look_for_libev then
436-
None
437-
else begin
438-
let code = {|
439-
#include <ev.h>
440-
441-
int main()
442-
{
443-
ev_default_loop(0);
444-
return 0;
445-
}
446-
|}
447-
in
448-
match compiles context code ~link_flags:["-lev"] with
449-
| Some true ->
450-
C_library_flags.add_link_flags ["-lev"];
451-
Some true
452-
| _ ->
453-
C_library_flags.add_link_flags ["-lev"];
454-
C_library_flags.detect context ~library:"ev";
455-
compiles context code
456-
end
457-
}
458-
459407
let () = feature {
460408
pretty_name = "pthread";
461409
macro_name = "HAVE_PTHREAD";
@@ -526,6 +474,58 @@ struct
526474
end
527475
}
528476

477+
let () = feature {
478+
pretty_name = "libev";
479+
macro_name = "HAVE_LIBEV";
480+
detect = fun context ->
481+
let detect_esy_wants_libev () =
482+
match Sys.getenv "cur__target_dir" with
483+
| exception Not_found -> None
484+
| _ ->
485+
match Sys.getenv "LIBEV_CFLAGS", Sys.getenv "LIBEV_LIBS" with
486+
| exception Not_found -> Some false
487+
| "", "" -> Some false
488+
| _ -> Some true
489+
in
490+
491+
let should_look_for_libev =
492+
match !Arguments.use_libev with
493+
| Some argument ->
494+
argument
495+
| None ->
496+
match detect_esy_wants_libev () with
497+
| Some result ->
498+
result
499+
| None ->
500+
(* we're not under esy *)
501+
let os = Configurator.ocaml_config_var_exn context "os_type" in
502+
os <> "Win32" && !Arguments.android_target <> Some true
503+
in
504+
505+
if not should_look_for_libev then
506+
None
507+
else begin
508+
let code = {|
509+
#include <ev.h>
510+
511+
int main()
512+
{
513+
ev_default_loop(0);
514+
return 0;
515+
}
516+
|}
517+
in
518+
match compiles context code ~link_flags:("-lev" :: C_library_flags.link_flags ()) with
519+
| Some true ->
520+
C_library_flags.add_link_flags ["-lev"];
521+
Some true
522+
| _ ->
523+
(* C_library_flags.add_link_flags ["-lev"]; *)
524+
C_library_flags.detect context ~library:"ev";
525+
compiles context code
526+
end
527+
}
528+
529529
let () = feature {
530530
pretty_name = "eventfd";
531531
macro_name = "HAVE_EVENTFD";

0 commit comments

Comments
 (0)