Skip to content

feat(describe): include melange targets in describe workspace - #16300

Open
NatKarmios wants to merge 9 commits into
ocaml:mainfrom
NatKarmios:describe-workspace-melange
Open

NatKarmios wants to merge 9 commits into
ocaml:mainfrom
NatKarmios:describe-workspace-melange

Conversation

@NatKarmios

@NatKarmios NatKarmios commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Description

Include melange.emit items in dune describe workspace.
Also report libraries compiled in Melange mode as melange.library items, in the same form as the existing library items; if a library is used by both an OCaml and Melange target, then both a library and melange.library item is reported for it.

The origin of plain .ml modules are reported as Copy_of_source, to associate the true source file with the build-time copy under .melange_src.

As a drive-by, resolves a TODO comment in Obj_dir.all_cmis about passing mode.

Related Issue and Motivation

Fixes #16299

Checklist

  • Tests added, if applicable.
  • Change log entry added for any user-facing changes.
  • Documentation added for any user-facing changes.

dune describe workspace only describes the OCaml compilation of a
workspace: melange.emit stanzas are not described at all, and every
library is described once in OCaml mode even when it is only ever built
for Melange.

Add a cram test recording that behaviour ahead of the fix. It lives
under test-cases/melange/ rather than test-cases/describe/ because it
needs melc on PATH to resolve Melange libraries.

Signed-off-by: Nat Karmios <nat@karmios.com>
Melange.Emit.t is a resolved emit target (where an emit's artifacts
live), which is a different type from Melange_stanzas.Emit.t, the parsed
melange.emit stanza. Rename the former to remove the ambiguity.

Also drop the dead "module Melange = Melange" alias from bin/import.ml;
nothing in bin/ referenced it.

Signed-off-by: Nat Karmios <nat@karmios.com>
Crawl hardcoded a module-level "let for_ = Compilation_mode.Ocaml" and
used it for every library resolution. Make it a parameter of
Crawl.executables, Crawl.library and Crawl.workspace so that a later
change can crawl in Melange mode.

No behaviour change: the sole caller passes Compilation_mode.Ocaml.

Signed-off-by: Nat Karmios <nat@karmios.com>
dune describe workspace now emits a "melange.emit" item for each
melange.emit stanza, carrying its target, alias, module systems, target
directory, library dependencies, modules and include directories.

The item is crawled in Melange compilation mode, so its modules and
include directories point at the Melange object directories rather than
the OCaml ones.

Libraries are still described only in OCaml mode; a follow-up adds
melange.library items.

Signed-off-by: Nat Karmios <nat@karmios.com>
dune describe workspace now crawls libraries in both compilation modes.
A library reachable in Melange mode is described by a "melange.library"
item, and its uid is salted with the mode so that it does not collide
with the OCaml item for the same library. A referrer's requires names
the uid of its own mode.

Both crawls filter their project libraries by Lib_info.effective_modes,
so a Melange-only library is no longer described as an ordinary library
item, and an OCaml-only library gains no melange.library item.

Signed-off-by: Nat Karmios <nat@karmios.com>
melange.emit and melange.library items reported the OCaml object
directories, which are never built for a Melange target: .mobjs/byte and
.objs/byte rather than .mobjs/melange and .objs/melange.

Obj_dir.all_cmis now takes the compilation mode, resolving the TODO that
asked for it, and describe passes the mode down to the cmt and cmti
paths of each module. The OCaml output is unchanged.

Signed-off-by: Nat Karmios <nat@karmios.com>
@NatKarmios
NatKarmios force-pushed the describe-workspace-melange branch from ddacc03 to 13aa4c8 Compare September 2, 2026 13:03
Add changelog fragments for the new melange.emit and melange.library
items and for the Melange-only library behaviour change, and note both
in the dune describe workspace CLI reference.

Signed-off-by: Nat Karmios <nat@karmios.com>
Melange compiles a copy of each source file, made under .melange_src by
an internal rule. Describe attributed the copy to that rule, so every
module of a melange.emit or melange.library item was reported as
generated by the stanza's dune file rather than as the source file the
user wrote.

Add a copy_of_source origin naming the file a module was copied from,
and resolve a module's origin against that file, so a copy of a
generated file still reports how it was generated.

Signed-off-by: Nat Karmios <nat@karmios.com>
Melange copies every module it compiles, including ones that were
themselves generated. Cover a module produced by a rule, whose origin
reports that rule rather than copy_of_source, and one produced by
ocamllex, whose origin names the .mll file in the source tree rather
than the .melange_src copy of the generated .ml.

Signed-off-by: Nat Karmios <nat@karmios.com>
@NatKarmios
NatKarmios force-pushed the describe-workspace-melange branch from 13aa4c8 to 5b92f08 Compare September 2, 2026 13:04
@Alizter
Alizter requested a review from anmonteiro September 2, 2026 15:27

This branch has not been deployed

No deployments
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.

describe workspace should include melange targets

1 participant