Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coq cannot find the cmxs file for transitive ocaml dependencies #11012

Open
rlepigre opened this issue Oct 15, 2024 · 6 comments
Open

Coq cannot find the cmxs file for transitive ocaml dependencies #11012

rlepigre opened this issue Oct 15, 2024 · 6 comments
Labels

Comments

@rlepigre
Copy link
Contributor

When building Coq theories with plugins depending on OCaml libraries (everything being in a dune workspace) it seems like dune sometimes fails to place .cmxs files for transitive dependencies where Coq expects to find them. Since Coq relies on findlib, it seems like all the OCaml libraries depended on transitively by plugins should be made available in the _build/install directory (or at least a META file for them?).

Here is a tarball with a minimal example of workspace that exhibits the problem: dune_bug_plugin_deps.tar.gz. It contains the following files:

dune_bug_plugin_deps
├── coqlib
│   ├── coqlib.opam
│   ├── coqlib-plugin.opam
│   ├── dune-project
│   ├── plugin
│   │   ├── coqlib_plugin.mlpack
│   │   ├── dune
│   │   └── main.ml
│   └── theories
│       ├── dune
│       └── plugin.v
├── dune-workspace
└── somelib
    ├── dune-project
    ├── somelib.opam
    └── src
        ├── dune
        └── version.ml

To reproduce the problem, simply run:

$ cd dune_bug_plugin_deps
$ dune build coqlib/theories/plugin.vo
File "./coqlib/theories/plugin.v", line 1, characters 0-41:
Error:
Dynlink error: error loading shared library: Failure("[...]/dune_bug_plugin_deps/_build/install/default/lib/somelib/somelib.cmxs: cannot open shared object file: No such file or directory")

This was tested with Coq 8.19, and dune 3.16.0.

@rlepigre
Copy link
Contributor Author

cc @ejgallego @Alizter

@rlepigre
Copy link
Contributor Author

Note also that the example provides a workaround in file dune_bug_plugin_deps/coqlib/theories/dune:

(coq.theory
 (name coqlib)
 (package coqlib)
 (plugins coqlib-plugin.plugin))

;(rule
; (targets dummy.v)
; (deps (package coqlib-plugin))
; (action (with-stdout-to %{targets} (echo "(* dummy file *)"))))

Removing the comments on the rule will fix the issue by forcing a dependency over the coqlib-plugin package (which is the reason to have a separate package for the plugin in the example, I think the problem is the same if it is in the same package as the theory).

@maiste maiste added the coq label Oct 15, 2024
@ejgallego
Copy link
Collaborator

Indeed, thanks for the report, I am hoping to look into this (finally) next week.

Seems like a case of missing transitive deps, the implementation of Coq plugin building didn't take into account this possibility due to technical reasons that no longer hold. But I need to look into this more carefully.

So indeed, let's try to fix this case soon; I think that for now a workaround that could work is to list all the libs.

@rlepigre
Copy link
Contributor Author

rlepigre commented Nov 4, 2024

@ejgallego is there anything I can help with here? I'm lacking context to look into this myself, but I could try if you provided some guidance for example.

@ejgallego
Copy link
Collaborator

ejgallego commented Nov 13, 2024

Hi @rlepigre , I hope I can allocate time to work on this soon, got hit by some unexpected stuff I had to take care of urgently :/ :/

If I am correct, the problem here is due to a missing dep for the installed .cmxs file, right?

In this case, the fix should be easy (and it shouldn't have a perf impact as we already depend on the direct .cmxs).

Actually we have code for both:

  • grabbing the transitive deps of ML libraries
  • depending on a "public" installed .cmxs

So I think we need to make the two parts cooperate in order to fix this issue.

Code here:

So indeed, before we used to depend on all libraries but in their build dir, for example this typically was -I _build/default/lib-foo/.library.objs/ and a dep on -I _build/default/lib-foo/.library.objs/foo.cmxs

But indeed, coq_rules:Util.include_paths seems not useful anymore, we don't need to pass any -I anymore to coqdep.

On the other hand, the bug comes because we rely on coqdep outputting the .cmxs deps. However coqdep doesn't output the transitive cmxs deps.

So I'm unsure what is the best rule approximation... We have two choices:

  • detect when coqdep adds a .cmxs dep, and then complete with the transitive closure
  • require the transitive closure of a theory OCaml deps to be build before the theory, however this will block building of files in that theory that don't depend on the plugin, and bloat the dep graph non trivially.

I suggest we continue discussion on Zulip or in a visio.

@rlepigre
Copy link
Contributor Author

I suggest we continue discussion on Zulip or in a visio.

OK thanks, sounds good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants