Best way to tweak environment variables in jbuilder/dune?

I’m in a situation where I need to extend the LD_LIBRARY_PATH environment variable in order to run my test executable. I’d like the equivalent of the following bash command:

LD_LIBRARY_PATH=$(print-some-path):$LD_LIBRARY_PATH run_tests.exe

We could achieve this by writing a shell script that contains the above but it would be nicer to specify this in the jbuild file. Another way is a configure pass of some kind that writes an include-able jbuild file.

Is there a way of achieving this directly from the handwritten jbuild file that builds and runs a test program?

The jbuild file currently looks like this:

(jbuild_version 1)

(executable
 ((name run_tests)
  (libraries (my-library))))

(alias
 ((name runtest)
  (package my-library)
  (deps (run_tests.exe))
  (action (run ${<}))))

You can make your action (setenv LD_LIBRARY_PATH foo (run ${<}) to do what you want. Unless the value of that path is somehow dynamic (in which case it would be more complicated).

2 Likes