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

How can I build the OCaml executable with bytecode? #762

Open
vthemelis opened this issue Jul 22, 2023 · 6 comments
Open

How can I build the OCaml executable with bytecode? #762

vthemelis opened this issue Jul 22, 2023 · 6 comments

Comments

@vthemelis
Copy link
Contributor

I tried by:

  • Changing the version of the dune language to 3.9
  • Adding
(executable
 (name main)
 (modules main)
 (modes byte exe)
 ...)

(ie the byte mode in the main executable stanza of the generated dune file)

Once I try to run the bytecode executable I get the following:

⨯ dune exec ./main.bc                                           16:09:16
File "dune", line 389, characters 7-11:
389 |  (name main)
             ^^^^
Error: File unavailable:
/Users/vas/.opam/4.14.0/lib/errpy/../stublibs/dllffi_ocaml.so
@vthemelis
Copy link
Contributor Author

vthemelis commented Jul 22, 2023

This may be due to an incomplete build of errpy. See: facebook/errpy#4

@stroxler
Copy link
Contributor

Interesting - I recently tried to get the debugger working, and I actually didn't run into this problem on the bytecode executable, but I did run into it if I tried to use ocamldebug.

At any rate I agree that a missing dynamically linked library from errpy is probably the root cause, we should try to get that working.

@vthemelis
Copy link
Contributor Author

vthemelis commented Jul 24, 2023

I added a first PR for this here: facebook/errpy#5

I'm not sure if this is the right approach for distribution of the binaries but it's a first step. It solves the first stage of the issue for me locally.

The next issue I get is:

◦ dune exec ./main.bc                                           21:20:35
File "dune", line 389, characters 7-11:  
389 |  (name main)
             ^^^^
ld: library not found for -llwt_unix_stubs
clang: error: linker command failed with exit code 1 (use -v to see invocation)
File "_none_", line 1:
Error: Error while building custom runtime system

but I haven't tried to fix this one yet.

I'm also interested in this so that we can eventually be able to run this under ocamldebug which requires a bytecode build.

@vthemelis
Copy link
Contributor Author

Added this issue to LWT for my second error: ocsigen/lwt#999

I'm not sure if this is macOS specific.

@vthemelis
Copy link
Contributor Author

The above was a red-herring.

I managed to build this library as bytecode and once grievejia/pyre-ast#7 and facebook/errpy#5 are done I will add a PR to fix this library as well.

I haven't tested how helpful the OCaml debugger is for this codebase yet but it will at least work.

@vthemelis
Copy link
Contributor Author

vthemelis commented Aug 11, 2023

Update on this, I managed to run the debugger and it's fairly useful. The issue that I have is that sometimes it might just crash with a segfault (probably related to the unix.fork code). The steps I've had to follow if anyone else is interested are:

This should allow debugging with ocamldebug. I used earlybird as my front-end in VSCode.

Also, note that even though you can get segfaults when breaking in program flow when running in forward mode, I didn't get any segfaults when running in the time-travelling mode of the debugger. (ie running the program until the end and then adding breakpoints and stepping back)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants