MantisBT - OCaml
View Issue Details
0005548OCaml-for ocamlbuild use 11:072017-03-03 15:26
0005548: ocamlbuild's ocamlfind integration doesn't support syntax extensions
OCamlbuild's ocamlfind integration includes -I-options and stuff from ocamlfind in the "compile" and "link" ocamlbuild steps but, to my knowledge, does not include them during preprocessing ("pp"). This means that while ocamlfind libraries can be used, I don't know how to use their attached syntax extensions (ocamlfind's predicate "syntax"). It would be nice if that was fixed.
With some ocamlfind package "foo.syntax" that enables syntax extensions, and some file "" using the extension,

  ocamlfind ocamlc -syntax camlp4o -package foo.syntax

does not raise a syntax error, while for instance

  ocamlbuild -use-ocamlfind -tag "package(foo.syntax)"

does (because neither ocamlfind's -I-option nor the camlp4 extension archive name are included in the camlp4o invocation).
I have discussed this with Anil Madhavapeddy which mentioned a related need on the mailing list:!topic/fa.caml/y6VsobyJV0s/discussion [^]
No tags attached.
related to 0006102acknowledged  ocaml{c,opt}: Provide command-line options to stop compilation after any stage 
Issue History
2012-03-20 11:07gascheNew Issue
2012-03-20 11:09gascheNote Added: 0007112
2012-03-20 11:09gascheStatusnew => acknowledged
2012-07-10 11:27doligezTarget Version => 4.01.0+dev
2012-07-31 13:36doligezTarget Version4.01.0+dev => 4.00.1+dev
2012-09-10 05:16meyerNote Added: 0008042
2012-09-10 05:16meyerAssigned To => meyer
2012-09-10 05:16meyerStatusacknowledged => assigned
2012-09-21 13:50doligezTarget Version4.00.1+dev => 4.01.0+dev
2013-06-16 19:38gascheNote Added: 0009518
2013-06-16 19:38gascheAssigned Tomeyer => gasche
2013-06-16 19:38gascheTarget Version4.01.0+dev => 4.02.0+dev
2013-06-16 21:26gascheSeverityminor => feature
2013-07-12 18:15doligezTarget Version4.02.0+dev => 4.01.1+dev
2013-07-29 18:36gascheRelationship addedrelated to 0006102
2014-05-25 20:24doligezTarget Version4.01.1+dev => 4.02.0+dev
2014-08-21 11:52doligezTarget Version4.02.0+dev =>
2017-02-23 16:34doligezCategoryOCamlbuild (the tool) => for ocamlbuild use [^]
2017-02-23 16:44doligezCategoryfor ocamlbuild use [^] => -for ocamlbuild use [^]
2017-03-03 15:26doligezNote Added: 0017544
2017-03-03 15:26doligezStatusassigned => resolved
2017-03-03 15:26doligezResolutionopen => suspended

2012-03-20 11:09   
I discussed this with xclerc and therefore mark this as "acknowledged".

If someone in the respected audience has a patch, please submit it! (Sane) contributions to fix ocamlbuild deficiencies are always welcome.
2012-09-10 05:16   
So ocamlbuild just does not use ocamlfind in this case. This definetely needs fixing.
2013-06-16 19:38   
This PR has in fact seen invisible progress: in the SVN commit 13262, Wojciech implemented a "-syntax <foo>" command-line option for ocamlbuild, meant to be used exactly as for ocamlfind. It is equivalent to passing the tag "syntax(foo)".

You can therefore use

    ocamlbuild -use-ocamlfind -syntax camlp4o -package foo.syntax test.byte

to compile into test.byte.

For example for as such:
  IFDEF BLAH THEN print_endline "foo" END

You can use the two equivalent commands:

  ocamlbuild -use-ocamlfind -tag "syntax(camlp4o -DBLAH)" -package camlp4.macro test.byte
  ocamlbuild -use-ocamlfind -syntax "camlp4o -DBLAH" -package camlp4.macro test.byte

However, the target still does not work as expected. I know of no easy way to call ocamlfind for only the preprocessing phase, and get source code as a result (in particular there is no "ocamlfind camlp4* -package ..." invocation possible.

Options for implementing this would be to:

(1) re-implement the build-camlp4-invocation-command logic in ocamlbuild (reusing the ocamlfind-like logic that was present before -use-ocamlfind was implemented), by calling "ocamlfind query" to get the right option to pass to the preprocessor; painful and probably not the best solution

(2) work-around the issue the issue by internally calling "ocamlfind ocamlc -syntax camlp4o ... -dsource" to convince ocamlfind that he's invoking a compiler, but actually get the postprocessed source code from ocaml. Not satisfying right now as there is no "-stop-after-parsing" flag to feed to the compiler, and it would still e.g. fail on ill-typed files. It's still a credible option, and in particular could be the best one if we want to also perform -ppx rewritings.

(3) implement the "ocamlfind camlp4*" command. I have not contacted Gerd to know whether that would be possible, but I would suspect that if this (rather natural) feature is not present, he possibly has already considered that and has good reason not to do it.

In any case, none of those options are realistic during a feature freeze, so I'm moving the part of this bug (the rest I consider solved) to 4.02+dev.
2017-03-03 15:26   
ocamlbuild is now a separate project that lives on GitHub.
PR transferred to [^]