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

dune show targets builds package dependencies before printing targets if a lockdir is present #11521

Open
gridbugs opened this issue Mar 10, 2025 · 1 comment

Comments

@gridbugs
Copy link
Collaborator

Expected Behavior

Running dune show targets should print the targets in the current directory and not build any dependencies. The command works as expected when no lockdir is present.

Actual Behavior

Dune builds some of the project's dependencies before printing targets. This can include the compiler and take several minutes.

Reproduction

Lock a project with dune pkg lock, then run dune show targets --verbose. The output will indicate that some dependencies are being built.

@gridbugs
Copy link
Collaborator Author

This happens due to how dune establishes its ocaml toolchain. For most dune commands, dune will look for the location of ocaml tools (like the compiler) on your system. When a lockdir is present, dune will instead attempt to install the ocaml toolchain implied by the project's dependencies.

An implication of this is that if you run dune show targets on a machine without ocamlc in your path, and with no lockdir, dune will fail as it can't find the ocamlc executable:

$ dune show targets
Error: Program ocamlc not found in the tree or in PATH
 (context: default)
-> required by loading the OCaml compiler for context "default"

This is also the error if you do have a lockdir, but the project doesn't depend on ocaml (rare but possible).

The reason dune needs access to an ocaml compiler is because it wants to run ocamlc -config to find out facts about the current machine. Some of these facts have implications for the targets of a project. For example the file extension of dynamic libraries is different on different OSes, (e.g. .so vs .dll), and ocamlc -config prints out the dynamic library extension for the current machine. The name of the target for a library will be different depending on the machine, and dune uses ocamlc to determine this name.

I think ideally dune would find out all the info it needs from the current machine without running ocamlc -config. We're trying to enable use cases for dune where it's the only ocaml tool globally installed on your system (instead of opam). If commands like dune show targets either cause the compiler to be installed (which can take several minutes) or fail due to a lack of ocamlc, then that's not really acceptable UX, especially because the relationship between the operation of listing targets and the compiler is not going to be obvious to most people.

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

No branches or pull requests

1 participant