ocaml / dune

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

ppx is skipped when `(modes byte)` #9650

Open zbaylin opened 6 months ago

zbaylin commented 6 months ago

Expected Behavior

I define a ppx which is expected to compile only as a bytecode library:

(library
 (name my_ppx)
 ...
 (kind ppx_rewriter)
 (modes byte))

I expect this to be applied to my code which depends on my_ppx as a preprocessor

...
  (preprocessor (pps my_ppx))
...

Actual Behavior

The ppx is not applied to the code and extension points remain. This is not the case if I remove the (modes byte).

Reproduction

See above

Specifications

rgrinberg commented 6 months ago

Thanks for the report. I reproduced the bug here https://github.com/ocaml/dune/pull/9653

What would be the behavior that you would expect?

  1. An error telling the user that a native driver could not be built
  2. Transparently switch to a bytecode driver. This might create a preprocessor that is slower.
zbaylin commented 6 months ago

Hi @rgrinberg, thanks for helping reproduce the bug.

In my opinion, dune should switch to a bytecode-based driver, or maybe even provide a way of specifying which ppxs to run under bytecode/native mode in the preprocessing atom.

The ppx I'm running depends on being run under the bytecode runtime, and I'm willing to accept the performance trade off to run it.

rgrinberg commented 6 months ago

Okay, switching to bytecode sounds reasonable enough. Do you want to try implementing this?

zbaylin commented 6 months ago

Sure, I can look into it. Do you have any pointers as to where I should look for code regarding ppx building/execution?