Dune build-info : how to use?

I am trying to display build info via using dune-build-info library. However, it always seems to be None. Looking at the documentation for Build_info.V1.Version.version, I can see it mentioned the following:

 (** The version at which the current executable was built. The version is
      [None] during development, it is only [Some _] once the executable is
      installed or promoted to the source tree. *)

What does promoted to the source tree mean?

I tried dune exec --profile release ./version.exe and also _build/default/version.exe. But both cases seem to give me None. The source is committed to a git repo. How does one get Some v?

B.

You need to install your program (dune install) or promote it by adding a (promote ..) field to your executable stanza, see Stanza Reference — dune documentation.

Cheers,
Nicolas

1 Like

Thanks this finally did the trick.

$ cat dune
(executable
 (name version)
 (promote (until-clean))
 (libraries dune-build-info))

and calling dune promote and finally ./version.exe.

I am bit curious how this works? I manually copied the exe from _build and put it in the same dir. However, in that case I still get None. What does dune promote do? Does it do some processing to the .exe file?

When dune installs or promotes the executable, it physically overwrites some magic strings inside the executable with the version information. See the details at dune/artifact_substitution.ml at 5df2221179ff67e51ab93334ab2f8e42cdffb95b · ocaml/dune · GitHub

Cheers,
Nicolas

1 Like

Interesting, the documentation for promote doesn’t mention this and I can’t figure out from the source how a promote might be doing artifact substitution. Any pointers on where to look?

It is mentioned in the docs for the dune-build-info library Dune Libraries — dune documentation.

Artifact substituion during promotion is done here: dune/target_promotion.ml at 7ce9e8eaf7b65645879c8974dc4f2c5e06876ffa · ocaml/dune · GitHub

Cheers,
Nicolas

1 Like