ocaml / dune

A composable build system for OCaml.
https://dune.build/
MIT License
1.63k stars 404 forks source link

Combine future_syntax with other preprocessors? #1934

Open rdavison opened 5 years ago

rdavison commented 5 years ago

Is there some way to specify (preprocess future_syntax) in combination with other preprocessors? None of the following seem to work:

(library
  (name foo)
  (libraries core)
  (preprocess future_syntax (pps ppx_jane)))
(library
  (name foo)
  (libraries core)
  (preprocess (pps future_syntax ppx_jane)))
(library
  (name foo)
  (libraries core)
  (preprocess future_syntax)
  (preprocess (pps ppx_jane)))
ghost commented 5 years ago

No, it is not possible. I suppose the easiest way to make that work would be to add the same hack in ppxlib directly.

Dean177 commented 5 years ago

@rdavidson see #2262 for a solution

Alizter commented 1 year ago

Appears that there is a viable work around.

aantron commented 1 year ago

What is the syntax for the workaround currently? I tried

(preprocess (pps ppxlib.metaquot -- -pp %{bin:ocaml-syntax-shims}))

but the result is that the ASTs in my project appear to be empty.

  1. I am working in Bisect_ppx.
  2. If src/ppx/dune is
(ocamllex exclude_lexer)
(ocamlyacc exclude_parser)

(library
 (name bisect_ppx)
 (public_name bisect_ppx)
 (kind ppx_rewriter)
 (instrumentation.backend (ppx bisect_ppx))
 (synopsis "Code coverage for OCaml")
 (ppx_runtime_libraries bisect_ppx.runtime)
 (preprocess (pps ppxlib.metaquot -- -pp %{bin:ocaml-syntax-shims}))
 (flags (:standard -open Ocaml_shadow))
 (libraries bisect_ppx.common ppxlib str))

Note the -- -pp %{bin:ocaml-syntax-shims}.

I then run

$ ocamlc _build/default/src/ppx/instrument.pp.ml -dparsetree 2>&1 | wc -l

The result is 87, way too few lines for the expected AST from instrument.ml. By comparison, without ocaml-syntax-shims,

$ ocamlc _build/default/src/ppx/instrument.pp.ml -dparsetree 2>&1 | wc -l

shows 19611 lines.

It does not appear that this issue has been fixed, or I am not able to understand how to use the workaround. cc @aalekseyev @Dean117, is this workaround working for you today in some way?

It appears I am able to reopen this issue. Not sure if that's appropriate -- please just close again if not!

aantron commented 1 year ago

This was Dune 3.7.1, OCaml 4.13.1, ocaml-syntax-shims 1.0.0.

Alizter commented 1 year ago

@aantron The issue is that %{bin:...} is not being expanded correctly in the preprocess field. To get around this you can copy the binary and directly mention the copy instead.

https://github.com/ocaml/dune/issues/2262#issuecomment-500422366

It might be worth keeping this open actually as it might be something that @anmonteiro can support with https://github.com/ocaml/dune/pull/7373.

aantron commented 1 year ago

We couldn't get copy to work either. I don't have the exact error message immediately available right now.