Jbuilder: how to build a single exe or library?

Hello,

Let’s say my project has libraries lib1, lib2 and lib3
and executables exe1, exe2 and exe3.

How do I tell jbuilder to build only exe1?

How do I tell jbuilder to build only lib3?

With my previous ocaml build tool of choice:
obuild build exe-exe1
obuild build lib-lib3

Thanks!

1 Like

If your libraries are all in their respective folders, like ./lib1 ./lib2 etc. You need to call something like

jbuilder build lib1/lib1.cma

or

jbuilder build bin/exe1.exe (yes, even on unix you need to append the .exe file extension)
jbuilder build bin/exe1.bc (to build bytecode executable)
jbuilder build bin/exe1.bc.js (if you want to compile to javascript using js_of_ocaml)

you can even directly execute them if you want to, like this

jbuilder exec bin/exe1.exe command_line_params - it will build it if needed

Currently, I have to issue the much less convenient:

jbuilder build _build/default/src/<myprogram>.exe

And I am thinking

jbuilder build myprogram.exe

would be way more convenient … :frowning:

Also,

jbuilder build exe-myprogram

would be more classy.

I’m pretty sure you just have to write jbuilder src/myprogram.exe instead of all that. If you also want to run it easily you can also use a (public_name myprogram) option in the jbuild file, which will let you run it with jbuilder exec myprogram.

4 Likes

Thanks,

jbuilder build src/my_program.exe

does work.