Skip to content

Conversation

@gridbugs
Copy link
Collaborator

If dune tools exec ocamllsp is executed while the watch server is running, dune will now build ocamllsp in the instance of dune where the watch server is running rather than failing due to the build directory being locked.

Copy link
Collaborator

@voodoos voodoos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exposing Build_cmd.build_via_rpc_server seems very useful !

However I think we should be a bit more ambitious than using it only for ocamllsp server: we also need it for ocamlformat and probably other tools. Why not make it generic for all calls to dune tools exec ?

In the future we probably also want dune build ... commands to be able to piggy-back on an existing rpc server. This would allow editors to request up-to-date indexes for example. But that's for another PR.

@gridbugs
Copy link
Collaborator Author

Exposing Build_cmd.build_via_rpc_server seems very useful !

However I think we should be a bit more ambitious than using it only for ocamllsp server: we also need it for ocamlformat and probably other tools. Why not make it generic for all calls to dune tools exec ?

In the future we probably also want dune build ... commands to be able to piggy-back on an existing rpc server. This would allow editors to request up-to-date indexes for example. But that's for another PR.

Yeh I definitely agree that there should be a more general mechanism for building via rpc rather than duplicating code between all the commands that build targets. I've intentionally not generalized the mechanism for the first few commands I've changed so I can get a better understanding of how to generalize it. This will come in a later PR, along with adding rpc support to the remaining commands that build targets.

@gridbugs gridbugs force-pushed the dev-tool-install-concurrent-with-watch-mode branch from 4a9335e to 0299d4e Compare May 19, 2025 00:28
@gridbugs
Copy link
Collaborator Author

This will come in a later PR

Actually I've changed my mind about this. I'll add a general mechanism for installing dev tools via rpc to this PR since it's quite simple. As I add support for other commands (dune exec, dune test) I'll see if it makes sense to generalize this even further.

@gridbugs gridbugs force-pushed the dev-tool-install-concurrent-with-watch-mode branch 2 times, most recently from faabe2f to e6ce36a Compare May 19, 2025 01:27
@gridbugs
Copy link
Collaborator Author

In the future we probably also want dune build ... commands to be able to piggy-back on an existing rpc server. This would allow editors to request up-to-date indexes for example. But that's for another PR.

This is already somewhat the case! Simple usage of dune build where no extra arguments are passed that affect the build (e.g. no auto promotion) already go via the rpc server if an rpc server is running.

@gridbugs gridbugs force-pushed the dev-tool-install-concurrent-with-watch-mode branch 2 times, most recently from fde0fac to de5aa34 Compare May 19, 2025 01:38
@gridbugs
Copy link
Collaborator Author

Applied feedback and added a test that I forgot to check in last week.

@gridbugs gridbugs force-pushed the dev-tool-install-concurrent-with-watch-mode branch 2 times, most recently from a092404 to d7e90c4 Compare May 22, 2025 06:09
@gridbugs gridbugs changed the title Allow ocamllsp to be installed while watch server runs Allow dev tools to be installed while watch server runs May 23, 2025
@gridbugs gridbugs force-pushed the dev-tool-install-concurrent-with-watch-mode branch from d7e90c4 to 53d9f6c Compare May 23, 2025 02:51
@gridbugs
Copy link
Collaborator Author

@voodoos let me know if you have any more feedback before I merge this

Copy link
Collaborator

@Leonidas-from-XIV Leonidas-from-XIV left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor comments only.

val lock_ocamlformat : unit -> unit Memo.t
val lock_odoc : unit -> unit Memo.t
val lock_ocamllsp : unit -> unit Memo.t
val lock_dev_tool : Dune_pkg.Dev_tool.t -> unit Memo.t
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would make sense to replace all the other lock_* functions at this point, to avoid having two different ways to do the same thing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call!


let build_dev_tool_directly common dev_tool =
let exe_path = dev_tool_exe_path dev_tool in
if Path.exists exe_path
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder whether it would make sense to make sure that this is the right version, otherwise updating dev tools might not be possible?

(That said, I don't have a good idea how to record a dependency from the version to the built binary and it's possibly good enough for now)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh good catch. The logic for building ocamllsp originally didn't have this check, and that's possibly why. I'll remove the check for now to prevent accidentally introducing a problem where ocamllsp isn't rebuilt when it should be. This will add a small amount of latency when invoking other dev tools I doubt it will be a big deal.

If `dune tools exec <tool>` is executed while the watch server is
running, dune will now build the tool in the instance of dune where the
watch server is running rather than failing due to the build directory
being locked.

This change also unifies some of the logic for building dev tools to
reduce duplication.

Signed-off-by: Stephen Sherratt <stephen@sherra.tt>
@gridbugs gridbugs force-pushed the dev-tool-install-concurrent-with-watch-mode branch from 53d9f6c to 9df61d9 Compare May 26, 2025 10:16
Copy link
Collaborator

@voodoos voodoos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @gridbugs !

@gridbugs gridbugs merged commit 923af84 into ocaml:main May 26, 2025
22 of 24 checks passed
Sudha247 pushed a commit to Sudha247/dune that referenced this pull request Jul 23, 2025
If `dune tools exec <tool>` is executed while the watch server is
running, dune will now build the tool in the instance of dune where the
watch server is running rather than failing due to the build directory
being locked.

This change also unifies some of the logic for building dev tools to
reduce duplication.

Signed-off-by: Stephen Sherratt <stephen@sherra.tt>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants