Include .cmx file in Jbuilder executable

We’re using a custom OCaml compiler to restrict the language features and provide a limited standard library for a portion of our project. We need to also link this code into an executable which is built using jbuilder. Currently, I can build the custom compiler, run it on the files, build our other libraries, and a version of our executable that does not include the cmx files the custom compiler generated. Is there a way to specify that these files should be included in the executable without resorting to running the OCaml compiler directly?

Have you seen this page? I’ve never needed anything like this, but using (flags <flags>) and and the information from the manual should give you what you want.

I have, though none of the available flags seem to apply to this situation. If you can tell me which one I should use, that would be extremely helpful.

Not sure I can help. I would probably move everything to the same build context and use -link-all. That should force the inclusion of non referenced modules, which seemes to be the case.

I believe -I only helps if you are already referencing those modules in your project.

Just out of curiosity, which kind of language features are you trying to keep users from using? Was it not something that could be done with a module to shadow the undesired bits?

1 Like

We need to embed a compiler so that new modules can be built and initialized at runtime, so we need to package a compiler within our project regardless. The compiler builds and instantiates a functor with a restricted standard library as well as adding code to register the module into the rest of the codebase.

Apparently, there are two ways to use linkall in jbuilder: for executables, you can use (link_flags (-linkall)). And for libraries: (library_flags (-linkall)).

You can find more information if you search “linkall” in jbuilder docs.

This did not work when I tried it because the .cmx file itself is not being directly referenced.

Did you move these files to the build context before testing linkall? Maybe the flag is only applicable for the current building context.