dune icon indicating copy to clipboard operation
dune copied to clipboard

repeat 'dune exec/build's are removing build artefacts (.cmt files)

Open progman1 opened this issue 3 years ago • 2 comments

using v2.9.1 running dune build x/y.exe twice, back to back and without altering the source, results in some .cmt files being removed but not all. other types of build artefact remain.

as I'm developing a tool that relies on the presence of .cmt files this behaviour is bad news. worse, it is confusing. assuming it isn't a bug, why is this happening?

progman1 avatar Feb 27 '22 01:02 progman1

why is this happening?

It is happening because of dune likes to delete stale artifacts. This is important to make sure that rules don't accidentally read files they're not supposed to. For example, some leftover .cmi file from a previous build should not interfere with the current build.

There's no way to disable this feature and it's unlikely we'll add such an option. What is producing these .cmt files that are being deleted? Usually this is an issue of a rule not declaring all the targets that it's producing. However, in the case of .cmt files, dune indeed declares .cmt files to be targets. So they shouldn't be deleted.

rgrinberg avatar Apr 28 '22 16:04 rgrinberg

What I'm seeing is, after a successful build, another 'dune build ...' will result in a .cmt being removed, even though there is nothing to be done as such.

Given that dune knows about .cmt files for rules purposes does the behaviour I'm describing not look odd? When nothing needs rebuilding what house-keeping is necessary? Build artefacts should rightly be cleared away in preparation for rules being run but what rules would need running after a clean build?

progman1 avatar Aug 04 '22 15:08 progman1

I was previously unable to anticipate when deletions would occur, but have noticed one invocation that does reliably demonstrate this is [dune build @install] You stated that .cmt are covered by the rules so disappearing .cmt files is a bug , no?

progman1 avatar Sep 28 '22 09:09 progman1

The behavior your describe indeed seems odd. Dune should not delete any cmt files because it knows they are targets.

Do you have a test case we could look at?

rgrinberg avatar Oct 03 '22 13:10 rgrinberg

could you first try this on any project you have at hand: o build afresh some library within the project directly dune build x/y/z.cma o find _build/default -name *.cmt o run dune build @install o re-run find and compare

it is happening generally unpredictably for non-install development (at least I haven't noticed the pattern yet) but the build @install always seems to cause removals.

progman1 avatar Oct 04 '22 11:10 progman1

I see that there is as yet not any bug tag on this issue. why not?

progman1 avatar Jan 28 '23 21:01 progman1

I just tried reproducing this and wasn't successful. You need to give us a minimal example that reproduces the issue you're observing before we can make progress.

rgrinberg avatar Jan 28 '23 23:01 rgrinberg

Closed until there are clean steps to reproduce this.

rgrinberg avatar Feb 21 '23 19:02 rgrinberg

a minimal example codeberg.org/progman/dunebug

dune build ./ok.cmxa find _build -name *.cm* _build/default/ok.cmxa _build/default/.ok.objs/native/ok.cmt _build/default/.ok.objs/native/ok.cmx _build/default/.ok.objs/byte/ok.cmo _build/default/.ok.objs/byte/ok.cmi _build/default/.ok.objs/byte/ok.cmt dune build ./ok.cmxa find _build -name *.cm* _build/default/ok.cmxa _build/default/.ok.objs/native/ok.cmx _build/default/.ok.objs/byte/ok.cmo _build/default/.ok.objs/byte/ok.cmi _build/default/.ok.objs/byte/ok.cmt

the native/ok.cmt file has disappeared

progman1 avatar Sep 18 '23 19:09 progman1

can this be re-opened now a minimal example has been stumbled across?

progman1 avatar Oct 02 '23 13:10 progman1

I am unable to reproduce the issue. The first dune build never gives me the first native/ok.cmt. What version of Dune/OCaml are you using?

Alizter avatar Oct 02 '23 13:10 Alizter

Here is my test case:

https://github.com/ocaml/dune/pull/8813

I'm reopening this until we get to the bottom of the issue.

Alizter avatar Oct 02 '23 13:10 Alizter

dune 3.10 ocaml 4.14.2

progman1 avatar Oct 02 '23 22:10 progman1

can this be re-opened now a minimal example has been stumbled across?

I'm unable to reproduce your example. The first command does not produce a native/ok.cmt. In fact, dune always produces bin annot files only with the bytecode

Did you muck about with OCAMLPARAM perhaps?

rgrinberg avatar Oct 03 '23 14:10 rgrinberg

yes! I have OCAMLPARAM=_,bin-annot=1 in my .bashrc. I didn't know dune was doing it anyway, let alone specifically for bytecode only. I suppose on the 2nd build cmd dune sees the native/ok.cmt as an unknown artefact and deletes it.

perhap dune ought to become aware of the various envars influencing the compilers. it already parses ocamlc_flags and friends, no?

progman1 avatar Oct 03 '23 18:10 progman1

I suppose we could. It's quite hard to do a thorough job here as quite a bit can be configured via OCAMLPARAM.

rgrinberg avatar Oct 03 '23 22:10 rgrinberg

copy the ocaml source? in any case thanks for sorting my problem. I'll remove my global OCAMLPARAM and rely on dune.

progman1 avatar Oct 05 '23 07:10 progman1