Dune. Modify (executable) based on cli arg or env var

I’d like to add (modes (byte exe)) to (executable) section of “dune” file if an environment variable is set or command line argument is provided.
However I couldn’t find anything related in the dune manual. Is it even possible?


dune build path/to/executable.bc

instead of

dune build path/to/executable.exe
1 Like

That’s not possible directly. Can you describe a bit more why you need to switch (modes) in this way?

By default we build native binary (for release, for ci and for development). But sometimes I need to switch to bytecode for interactive debugging.

dune knows about both types of executable without the need to change (modes): you can run dune build path/to/my_executable.bc to build a bytecode version (where you would put dune build path/to/my_executable.exe).

Would that work for your use case?

EDIT: bc not byte!

Unfortunately that doesn’t work for me. I get “Error: Don’t know how to build path/to/my_executable.byte” while “dune build path/to/my_executable.exe” is built successfully.

dune uses .bc not .byte

Gaëtan Gilbert

Yep, that works.
Thanks, @emillon and @SkySkimmer !

Hm. That seems to be different than specifying “(modes (byte exe))” in dune file.
With “dune build path/my_executable.bc” I get following error:

Error: Error on dynamically loaded library: ./libs/extc/dllextc_stubs.so: ./libs/extc/dllextc_stubs.so: undefined symbol: inflate

“extc” is a library with its own “dune” file defined like this:

(include_subdirs no)

	(name extc)
	(libraries extlib)
	(c_names extc_stubs)
	(modules extc)
	(wrapped false)

	(name extproc)
	(c_names process_stubs)
	(modules process)
	(wrapped false)

Yes, thanks! Too many years with ocamlbuild :slight_smile: