ocaml-obuild / obuild

simple package build system for ocaml
BSD 2-Clause "Simplified" License
55 stars 20 forks source link

Compiler libs should not be linked when using ppx #161

Open benedictleejh opened 7 years ago

benedictleejh commented 7 years ago

As far as I understand from https://whitequark.org/blog/2014/04/16/a-guide-to-extension-points-in-ocaml/ and https://blogs.janestreet.com/extension-points-or-how-ocaml-is-becoming-more-like-lisp/, ppx is a pre-processing step in the compilation process. As such, once pre-processing is complete, the ppx libraries should no longer be needed.

However, obuild attempts to link in the ppx library and their dependencies into the final product. This should be unnecessary.

Edit: I've created a repo that shows the problem: https://github.com/benedictleejh/obuild-issue-161

If you compile using ocamlbuild (ocamlbuild -use-ocamlfind calc.{byte|native}) everything works out fine. But compiling with obuild causes it to throw the error:

File "_none_", line 1:
Error: Files dist/build/calc/Parser.cmx
       and ~/.opam/4.02.3/lib/ocaml/compiler-libs/ocamlcommon.cmxa
       both define a module named Parser

Which shows it attempting to link the compiler-libs into the final compilation product.

jeromemaloberti commented 7 years ago

Thank you, I will investigate. From a first look, though, obuild doesn't link with compiler-libs, it adds the directory to -I, so the linker is confused by your Parser and the one already there. compiler-libs is a dependency of ppx_tools, that is a dependency of ppx_conv. So, I need to understand how ocamlfind (through ocamlbuild) deals with that.