Skip to content

feat: %{pkg:foo:lib:file} pforms for package install layouts - #14200

Merged
Alizter merged 1 commit into
ocaml:mainfrom
Alizter:push-yqyzlrlpmltq
Apr 27, 2026
Merged

Alizter merged 1 commit into
ocaml:mainfrom
Alizter:push-yqyzlrlpmltq

Conversation

@Alizter

@Alizter Alizter commented Apr 16, 2026 •

Copy link
Copy Markdown
Collaborator

We introduce %{pkg:foo:lib:file} macros similar to the %{pkg:foo:lib} macros for lock files. This allows users to inspect installed package contents directly. We support all the install sections that we understand in dune.

Depending on such a path automatically introduces dependencies on the package.

This works with ocamlfind packages, dune package management and workspace packages.

The goal is to ultimately hide _build/install as an implementation detail and allow users to properly depend on packages' installed contents without having to inspect them by hand.

@Alizter
Alizter force-pushed the push-yqyzlrlpmltq branch from d8cffa1 to 917dfbc Compare April 17, 2026 12:56
@Alizter
Alizter force-pushed the push-yqyzlrlpmltq branch from 917dfbc to 12bd59e Compare April 17, 2026 15:00
Alizter added a commit that referenced this pull request Apr 17, 2026
These fields can appear in opam files, however we haven't encountered
them yet. It might be worth supporting them since we use these install
sections in dune anyway.

This test simply checks how we are interpreting the fields, I will
motivate adding them in a later PR. This is related to #14200.
@Alizter
Alizter force-pushed the push-yqyzlrlpmltq branch from 12bd59e to 3600fb2 Compare April 17, 2026 16:11
@Alizter
Alizter force-pushed the push-yqyzlrlpmltq branch 2 times, most recently from 36db8d6 to 0e048e5 Compare April 17, 2026 17:02
@Alizter
Alizter requested a review from rgrinberg April 17, 2026 17:02
@Alizter
Alizter marked this pull request as ready for review April 17, 2026 17:02
@Alizter
Alizter force-pushed the push-yqyzlrlpmltq branch from 0e048e5 to 3a12c1b Compare April 17, 2026 17:10
Comment thread src/dune_rules/expander.ml Resolved
Comment thread src/dune_rules/package_db.ml Resolved
@rgrinberg

Copy link
Copy Markdown
Member

Thinking about this again, I think this form should take the actual file that it needs as another argument. Otherwise, we need to build everything in the install directory and that is going to cause incredibly inconvenient cycles for folks.

@Alizter

Alizter commented Apr 17, 2026 •

Copy link
Copy Markdown
Collaborator Author

I think making it be (package foo) is better because then later we can improve that to avoid cycles by materialising install directories with anonymous actions. Having the directory in the form is convenient because it allows users to create paths with it and we don't have to care about supplying the full install tree as syntax.

@rgrinberg

Copy link
Copy Markdown
Member

There are some advantages to both approaches. One advantage of allowing the user to specify a file is that it is actually solving the ticket we've been provided. That is analogous to %{lib:..} which does take a file. Another advantage is that it allows us to refer to installed paths from within the same package and the same section without cycles. There's no way you can workaround this with or without anonymous actions. Finally, it gives us validation to see if the path under the section actually exists.

So in summary, both approaches have their cons. But we should do the direct thing to solve the issue the user is asking for.

By the way, I'm not so hot about allowing the _build/install directory to be reachable via relative paths anymore. I think these paths (whether constructed through an anonymous action or not) should only be accessible through environment variables.

@Alizter
Alizter force-pushed the push-yqyzlrlpmltq branch 5 times, most recently from dda4a63 to b8dc435 Compare April 20, 2026 17:25
@Alizter
Alizter requested a review from rgrinberg April 20, 2026 22:50
Comment thread src/dune_rules/package_db.mli Resolved
Comment thread src/dune_rules/artifacts_db.ml Resolved
Comment thread src/dune_rules/artifacts_db.ml Resolved
Comment thread src/dune_rules/artifacts_db.ml Resolved
@Alizter
Alizter force-pushed the push-yqyzlrlpmltq branch from b8dc435 to afca697 Compare April 21, 2026 21:31
Comment thread src/dune_rules/expander.ml Resolved
@Alizter
Alizter force-pushed the push-yqyzlrlpmltq branch from d4912be to d77ec39 Compare April 26, 2026 10:16
@Alizter
Alizter requested a review from rgrinberg April 26, 2026 10:16
@Alizter
Alizter force-pushed the push-yqyzlrlpmltq branch from d77ec39 to 2306d60 Compare April 26, 2026 10:34
Comment thread src/dune_rules/expander.ml Resolved
@Alizter
Alizter force-pushed the push-yqyzlrlpmltq branch 3 times, most recently from 586fa5b to 5585563 Compare April 26, 2026 22:10
@Alizter
Alizter requested a review from rgrinberg April 26, 2026 22:18
@Alizter
Alizter force-pushed the push-yqyzlrlpmltq branch 2 times, most recently from 72f4154 to db08c0e Compare April 27, 2026 08:31
@Alizter
Alizter force-pushed the push-yqyzlrlpmltq branch from db08c0e to 9260640 Compare April 27, 2026 08:40
@Alizter
Alizter merged commit 5942abe into ocaml:main Apr 27, 2026
56 of 57 checks passed
@Alizter
Alizter deleted the push-yqyzlrlpmltq branch April 27, 2026 21:29
raphael-proust pushed a commit to ocaml/opam-repository that referenced this pull request Jun 30, 2026
CHANGES:

### Fixed

- Fix promotion failure when a target changes from a directory to a file
  between builds, causing "Is a directory" errors.
  (ocaml/dune#14371, fixes ocaml/dune#5647, fixes ocaml/dune#6575, @Alizter)

- Make `dune build @doc` pick up an odoc installed via `dune tools install
  odoc` even without `DUNE_CONFIG__LOCK_DEV_TOOL=enabled`, mirroring how
  `dune fmt` consumes a locked ocamlformat (ocaml/dune#14426, fixes ocaml/dune#14235, @mt-caret)

- Reject `(package ...)` inside a named dependency binding
  (`(deps (:name (package foo)))`). Previously this was silently accepted but
  `%{name}` would resolve to an empty path list. (ocaml/dune#14499, @Alizter)

- Fix incorrect dependency in the `.cmxs` build for libraries with
  mode-dependent foreign stubs: the rule depended on the byte stubs archive
  instead of the native one, so parallel builds could fail to find
  `-l<lib>_stubs_native`. (ocaml/dune#14500, fixes ocaml/dune#12964, @Alizter)

- Fix `dune build` failing with "No rule found" when `lock_dir` paths in
  `dune-workspace` contain a subdirectory (e.g. `(path sub/dune.lock)`).
  (ocaml/dune#14524, fixes ocaml/dune#14523, @Alizter)

- Artifact substitution repairs executable bit if it's not set correctly in the workspace
  (ocaml/dune#14556, @rgrinberg)

- Ignore `EINVAL` when accepting sockets on MacOS (ocaml/dune#14612, fixes ocaml/dune#12660, @rgrinberg)

- Validate profile names. Profile names must be non-empty and can only contain
  letters, digits, `_` and `-`. The name `_` is reserved as a wildcard in
  `(env ...)` stanzas. (ocaml/dune#14657, fixes ocaml/dune#14630, @rlepigre)

### Added

- Add `%{pkg:<package>:<section>:<path>}` pform for resolving package install
  files. Works with workspace packages, lock-file packages, and installed
  packages. (ocaml/dune#14200, fixes ocaml/dune#14193, fixes ocaml/dune#3378, @Alizter)

- Enable the relocatable compiler by default for package management (ocaml/dune#14357,
  fixes ocaml/dune#14012, @Alizter)

- Add changed source files to the `build-start` trace event for watch-mode
  restarts, showing the paths that triggered the rebuild (ocaml/dune#14396, @rgrinberg)

- Add dune's rusage information in start/finish build trace events (ocaml/dune#14402, @rgrinberg)

- Add a status message for RPC clients that manage to connect (ocaml/dune#14424, @rgrinberg)

- Allow blang expressions in the `runtest_alias` field in the `cram` stanza (ocaml/dune#14425, @rgrinberg)

- Extend the stat based cache to cache the contents of directories and not just
  source files (ocaml/dune#14469, @rgrinberg).

- Show the number of connected RPC clients in the watch mode status line
  (ocaml/dune#14489, @rgrinberg)

- Promote directory targets from experimental to generally available in 3.24
  (ocaml/dune#14579, @rgrinberg)

### Changed

- Use `/` as directory separator when appending local paths to external paths,
  making path construction consistent across platforms. (ocaml/dune#14278, @Alizter)
- On Windows, normalise process paths to `\` before passing them to
  `CreateProcessW` so that programs which scan `argv[0]` (notably `cmd.exe`)
  do not misparse mixed separators. (ocaml/dune#14278, @Alizter)

- `%{bin:NAME}` now resolves to the build artifact path rather than
  the install staging path. Rules with `%{bin:NAME}` deps additionally
  get a per-rule `.binaries` directory prepended to the action's
  `PATH`, containing correctly-named symlinks for each declared bin
  pform dep. (ocaml/dune#14432, fixes ocaml/dune#3324, @Alizter)

- Replace the Rocq language field `(stdlib ...)` with the presence-only field
  `(no_corelib)` in Rocq language 0.14. (ocaml/dune#14452, fixes ocaml/dune#14358, @Durbatuluk1701)

- Throttle sandbox creation to 250 concurrent sandboxes. (ocaml/dune#14464, @rgrinberg)

- The package solver now uses cached revision store lookups for improved
  performance. (ocaml/dune#14494, fixes ocaml/dune#12637, @Alizter, @rgrinberg)

- Remove the deprecated `(lang coq)` Coq Build Language. Use the
  Rocq Build Language (`(using rocq <version>)`) instead. Projects that
  still declare `(using coq <version>)` now get an error pointing them
  at Rocq. (ocaml/dune#14525, fixes ocaml/dune#12788, @Alizter)
@Alizter Alizter added this to the 3.24.0 milestone Jul 8, 2026
craff pushed a commit to craff/opam-repository that referenced this pull request Jul 25, 2026
CHANGES:

### Fixed

- Fix promotion failure when a target changes from a directory to a file
  between builds, causing "Is a directory" errors.
  (ocaml/dune#14371, fixes ocaml/dune#5647, fixes ocaml/dune#6575, @Alizter)

- Make `dune build @doc` pick up an odoc installed via `dune tools install
  odoc` even without `DUNE_CONFIG__LOCK_DEV_TOOL=enabled`, mirroring how
  `dune fmt` consumes a locked ocamlformat (ocaml/dune#14426, fixes ocaml/dune#14235, @mt-caret)

- Reject `(package ...)` inside a named dependency binding
  (`(deps (:name (package foo)))`). Previously this was silently accepted but
  `%{name}` would resolve to an empty path list. (ocaml/dune#14499, @Alizter)

- Fix incorrect dependency in the `.cmxs` build for libraries with
  mode-dependent foreign stubs: the rule depended on the byte stubs archive
  instead of the native one, so parallel builds could fail to find
  `-l<lib>_stubs_native`. (ocaml/dune#14500, fixes ocaml/dune#12964, @Alizter)

- Fix `dune build` failing with "No rule found" when `lock_dir` paths in
  `dune-workspace` contain a subdirectory (e.g. `(path sub/dune.lock)`).
  (ocaml/dune#14524, fixes ocaml/dune#14523, @Alizter)

- Artifact substitution repairs executable bit if it's not set correctly in the workspace
  (ocaml/dune#14556, @rgrinberg)

- Ignore `EINVAL` when accepting sockets on MacOS (ocaml/dune#14612, fixes ocaml/dune#12660, @rgrinberg)

- Validate profile names. Profile names must be non-empty and can only contain
  letters, digits, `_` and `-`. The name `_` is reserved as a wildcard in
  `(env ...)` stanzas. (ocaml/dune#14657, fixes ocaml/dune#14630, @rlepigre)

### Added

- Add `%{pkg:<package>:<section>:<path>}` pform for resolving package install
  files. Works with workspace packages, lock-file packages, and installed
  packages. (ocaml/dune#14200, fixes ocaml/dune#14193, fixes ocaml/dune#3378, @Alizter)

- Enable the relocatable compiler by default for package management (ocaml/dune#14357,
  fixes ocaml/dune#14012, @Alizter)

- Add changed source files to the `build-start` trace event for watch-mode
  restarts, showing the paths that triggered the rebuild (ocaml/dune#14396, @rgrinberg)

- Add dune's rusage information in start/finish build trace events (ocaml/dune#14402, @rgrinberg)

- Add a status message for RPC clients that manage to connect (ocaml/dune#14424, @rgrinberg)

- Allow blang expressions in the `runtest_alias` field in the `cram` stanza (ocaml/dune#14425, @rgrinberg)

- Extend the stat based cache to cache the contents of directories and not just
  source files (ocaml/dune#14469, @rgrinberg).

- Show the number of connected RPC clients in the watch mode status line
  (ocaml/dune#14489, @rgrinberg)

- Promote directory targets from experimental to generally available in 3.24
  (ocaml/dune#14579, @rgrinberg)

### Changed

- Use `/` as directory separator when appending local paths to external paths,
  making path construction consistent across platforms. (ocaml/dune#14278, @Alizter)
- On Windows, normalise process paths to `\` before passing them to
  `CreateProcessW` so that programs which scan `argv[0]` (notably `cmd.exe`)
  do not misparse mixed separators. (ocaml/dune#14278, @Alizter)

- `%{bin:NAME}` now resolves to the build artifact path rather than
  the install staging path. Rules with `%{bin:NAME}` deps additionally
  get a per-rule `.binaries` directory prepended to the action's
  `PATH`, containing correctly-named symlinks for each declared bin
  pform dep. (ocaml/dune#14432, fixes ocaml/dune#3324, @Alizter)

- Replace the Rocq language field `(stdlib ...)` with the presence-only field
  `(no_corelib)` in Rocq language 0.14. (ocaml/dune#14452, fixes ocaml/dune#14358, @Durbatuluk1701)

- Throttle sandbox creation to 250 concurrent sandboxes. (ocaml/dune#14464, @rgrinberg)

- The package solver now uses cached revision store lookups for improved
  performance. (ocaml/dune#14494, fixes ocaml/dune#12637, @Alizter, @rgrinberg)

- Remove the deprecated `(lang coq)` Coq Build Language. Use the
  Rocq Build Language (`(using rocq <version>)`) instead. Projects that
  still declare `(using coq <version>)` now get an error pointing them
  at Rocq. (ocaml/dune#14525, fixes ocaml/dune#12788, @Alizter)
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.

Support %{pkg:foo:lib} variables more generally Library variable expansion needs a library installed to work

3 participants