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

Add dune tools env to configure PATH #11408

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

art-w
Copy link
Contributor

@art-w art-w commented Jan 29, 2025

This is a proposal for #10964 to solve the following issues:

  • Allow users to configure their environment with eval $(dune tools env) to update their PATH with the local dune dev tools binaries
  • dune tools exec ocamllsp starts ocamllsp with that same PATH env, such that dune's ocamlformat can be found by LSP

I'm not entirely sure if my solution is acceptable: it create a new _build/_private/default/.dev-tool/bin folder, which contains executable shell scripts which calls dune tools exec $tool. This avoids polluting the PATH with each .dev-tool/$tool/$tool/target/bin and also enables ocamllsp to call ocamlformat even when it's not yet installed (as dune tools exec will handle it).

This PR does not however cover the "run arbitrary executables with dune tools exec foo" described in the issue, but I'm planning to work on that soon.

@Leonidas-from-XIV
Copy link
Collaborator

Wouldn't it be simpler to launch commands with dune tools exec <TOOLS> with their PATH expanded with the tools that are installed? This can even be a single virtual bin folder with symlinks as you propose.

I personally find eval $(...) mess really brittle and a source of constant issues. More often than not it leads to capture of wrong PATHs, mismatched artifacts ending up in wrong places because some wrong ocamlc was executed etc. There is no good way to scope extensions to PATH, thus with eval you're one cd away from using the wrong tools in the wrong folder.

The issue with Dune installing not-yet installed tools is that the caller has no input on how this is done. So if ocamllsp calls ocamlformat and the latter is not installed, this command might stall for an undetermined amount of time to install it without any way to determine whether it will or not before executing it. I think this was one of the reasons why a Dune LSP was proposed, such that editors can inquire the status and interact with the package management using a modern API (which could also be used by command line tools if they just want to install a tool by supplying an CLI DuneLSP client).

@maiste maiste added the cli Command line related label Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli Command line related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants