Which means the directives must also be comments?
That’s right, the plan is to eventually upstream Astlib. This will allow to build the ppx ecosystem with the development version of OCaml at all time, making it easier to test development versions of OCaml.
Except for the development version of OCaml, ppx should already be tenable across OCaml versions.
You can also put the function that requires 4.12 in a separate module with two implementations. One using the new stdlib function and one using a shim for older versions of the compiler, and choose the implementation of the module at compile time. This is very low-tech, but we used it in Base and in ppxlib in the past and it works well in practice.
First of all, I personally like the idea of having the conditional extension proposed here in the compiler! But to come to the things said about ppxlib (even though just briefly, since that’s not what this thread is about):
(…) which should hopefully make ppx tenable across OCaml versions.
@BikalGurung
Yes, exactly. Having PPXs tenable across versions is the purpose of ppxlib (and formerly of OMP).
The new Astlib module you’ve mentioned, once upstreamed to the compiler, will furthermore directly make ppxlib compatible with any new compiler version. Currently, that’s given by coordinating between the compiler releases and the ecosystem packages such as ppxlib.
note that Ppxlib versions 0.15.0 and above (released 2020-08-04) do not depend on
base.
@CraigFe
Yes, thanks for pointing that out! I think we should announce that, since that doesn’t seem to be well-known. There’s also a PR dropping base from ppx_optcomp.
(…) you don’t need worry about how to build the ppxlib or your other ppx dependencies on Windows
@bobzhang
I’m not very familiar with that topic. Are there issues getting ppxlib built on windows?
Amusing, we also do that in containers to have some level of conditional
compilation:
in this case though, it’s only small modules that are conditional, and
included in larger ones. It’s been very useful to handle let-operators
conditionally for example.
I know these work arounds, the beauty of my solutions
- no dependencies
- no need config in build
- can be backported to old versions
- lightning fast - not that important though