I can compile this simple test.ml:
let () = at_exit (fun () -> print_endline "Exiting.") ; let _ = Sys.(signal sigint (Signal_handle (fun _ -> print_endline "Received SIGINT." ; exit 100))) in Unix.sleep 100
by hand on the command line with the same options used by dune:
ocamlopt -o test -strict-sequence -strict-formats -short-paths -keep-locs -g ~/.opam/default/lib/ocaml/unix.cmxa test.ml
and it worked as expected. However if I build with dune the executable is immediately killed by zsh. And weirdly enough once this happens even after changing the code to a simple “hello world” it still dies (and “hello world” works again after
dune clean – ADD: not super sure that this flip-flop behavior is reliably reproducible).
Originally I had this problem with a much larger code base so I had variously thought it is a problem with Lwt or Unix module. And it is very sensitive to certain code change (like adding a Sys.signal call or adding print_endline to an at_exit function would cause the exe to be killed but otherwise it worked). However after some sleuthing it now appears to be related to how dune builds the artifacts. But all my opam installed code appeared to be working fine so that would be weird too.
I am on macOS 11.1 ARM64. Ocaml is installed through opam 2.0.7 native. Ocaml is at version 4.10.2. And dune is 2.8.1.
dune is minimal:
(executable (name test) (promote (until-clean)) (libraries unix))
Any idea on how to proceed from here?