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

[BUG] Mention std_exit in separate compilation instructions #1033

Closed
dbuenzli opened this issue Jul 12, 2020 · 2 comments · Fixed by #1039
Closed

[BUG] Mention std_exit in separate compilation instructions #1033

dbuenzli opened this issue Jul 12, 2020 · 2 comments · Fixed by #1039
Labels

Comments

@dbuenzli
Copy link
Contributor

Separate compilation instructions should mention that to get exactly the same results as what is done by whole program compilation one should add a compilation of std_exit at the end of the link instruction. Otherwise do_at_exit will not be called which means at_exit functions won't either.

This may not be a problem if you don't use Sys.at_exit handlers but it may lead to different visible program behaviour: in particular the Stdlib.flush_all funcction won't be called at program exit.

Whole program:

> echo "let () = print_string {|bla|}" > main.ml
> ocamlc -o main.byte main.ml 
> js_of_ocaml -o main.js main.byte 
> node main.js
bla
>

Separate compilation (according to current instructions):

> js_of_ocaml build-runtime -o ocaml-rt.js 
> js_of_ocaml compile -o stdlib.js $(opam var lib)/ocaml/stdlib.cma
> js_of_ocaml compile -o main.js main.cmo 
> js_of_ocaml link -o a.js ocaml-rt.js stdlib.js main.js 
> node a.js
> 

Adding a compilation of std_exit.cmo:

> js_of_ocaml compile -o std_exit.js $(opam var lib)/ocaml/std_exit.cmo 
> js_of_ocaml link -o a.js ocaml-rt.js stdlib.js main.js std_exit.js    
> node a.js
bla
@hhugo
Copy link
Member

hhugo commented Jul 12, 2020

One should also fix dune compilation rules

@dbuenzli
Copy link
Contributor Author

Yes I opened an issue there. See the cross refs.

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

Successfully merging a pull request may close this issue.

2 participants