-
Notifications
You must be signed in to change notification settings - Fork 470
Executable built with dune killed by zsh on macOS #4135
Description
Expected Behavior
Executable should run the same way as command line build.
Actual Behavior
Command line build with the same options runs fine but executable built with dune is killed by zsh on macOS. To match command line build I have to manually do codesign -s - test.exe on the executable.
Reproduction
- PR with a reproducing test:
I can compile the following 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. After keying ctrl-c:
ocaml % ./test
^CReceived SIGINT.
Exiting.
However if I build with dune using the following minimal dune file the executable is immediately killed by zsh:
(executable
(name test)
(promote (until-clean))
(libraries unix))
The problem with dune built exe:
ocaml % ./test.exe
zsh: killed ./test.exe
Note the killing by zsh is immediate (so something is wrong) and there is no keyboard input.
Specifications
- Version of
dune(output ofdune --version): 2.8.1 - Version of
ocaml(output ofocamlc --version) 4.10.2 - Operating system (distribution and version): macOS 11.1 ARM64
Additional information
And weirdly enough there seems to be some hysteresis in the behavior related to dune build. Starting with the above example and after building an executable that is always killed, the killing persists even if I hand edit the code to only contain print_endline "Hello world". This "Hello world" from editing only works correctly after I do a dune clean. However if I cp or mv the same code from another existing file then it works right away without need to dune clean. Does dune decide on how/when to build certain artifacts based on more than just time stamps?
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.