ocaml / ocaml/dune

OCAMLPATH value when ocamlfind is vendored

Open
#4,196 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

build mdx
Dominant language
OCaml
Stars
1.9k
Forks
500
Avg merge
15h 21m
Merged PRs (30d)
277

Description

Hi,

While testing #3956 we noticed some strange behavior when ocamlfind is part of the workspace. The exact issue is described at
https://github.com/NathanReb/test-new-mdx-stanza.

After debugging with @NathanReb, it seems that the core of the issue is how OCAMLPATH is set by dune. This variable defines where ocamlfind looks for packages (or something related to that question). In a pure opam context, opam-switch/lib seems to be correct. dune sets it to _build/install/default/lib which corresponds to the "compiled version of the dune workspace".

https://github.com/ocaml/dune/blob/6095f6fbf58ea44248703a612f0de9edff092150/src/dune_rules/context.ml#L578

The question is how can an ocamlfind that is part of the workspace access packages installed in a local opam switch?

In https://github.com/realworldocaml/book, we were not seeing any issues because the mdx stanzas have a dependency on (package mdx) and so everything was copied under _build/install/default/lib. In the minimum working example above, it is possible to "fix" the test by adding (deps (package findlib)) which copies all the findlib definitions at the place where findlib will look for them, but it seems that it should not be necessary.

I tried adding default_ocamlpath (as defined above - in the opam2 situation it's opam-switch/lib) to OCAMLPATH:

https://github.com/ocaml/dune/blob/6095f6fbf58ea44248703a612f0de9edff092150/src/dune_rules/context.ml#L528

This fixes the mdx situation but I'm not sure it's the right one.

What do you think @jeremiedimino @rgrinberg @bobot ?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the behavior with the linked test-new-mdx-stanza workspace, then inspect src/dune_rules/context.ml around lines 528 and 578 where default_ocamlpath and OCAMLPATH are set. Compare the vendored ocamlfind case with a local opam switch and the workaround using (deps (package findlib)). Done means the intended OCAMLPATH behavior is established and the reported workspace scenario works without that workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
ocaml
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.