Skip to content

Generate jsoo library archive rules on demand - #13611

Merged
rgrinberg merged 1 commit into
ocaml:mainfrom
vouillon:jsoo-on-demand
Feb 18, 2026
Merged

rgrinberg merged 1 commit into
ocaml:mainfrom
vouillon:jsoo-on-demand

Conversation

@vouillon

@vouillon vouillon commented Feb 11, 2026 •

Copy link
Copy Markdown
Member

Refactor jsoo archive generation to use a demand-driven approach. Previously, rules for all configuration variants were generated upfront whenever a library was built. This logic is now decoupled from general library rules; instead, the build system intercepts requests for specific configuration directories and generates the necessary rules dynamically.

This will enable the following improvements:

@vouillon

Copy link
Copy Markdown
Member Author

@hhugo Can you have a look?

@hhugo

hhugo commented Feb 11, 2026

Copy link
Copy Markdown
Contributor

Looks promising, should we move all cm{a,o}.js artifacts under a $config subdirectory ? I think we currently don't have this for compilation units part of an executable ?

Do you think we should change both rules generation logic AND the separate compilation granularity in the same PR ? Could we move the incremental generation of cma.js files to a smaller sub PR ?

@hhugo

hhugo commented Feb 11, 2026

Copy link
Copy Markdown
Contributor

You should explain in the PR description where we're going with this, where we move config details out of dune into jsoo.

@vouillon
vouillon force-pushed the jsoo-on-demand branch 2 times, most recently from a74caa3 to 98f3d34 Compare February 11, 2026 16:19
Move js_of_ocaml library archive rule generation (*.cma.js) out of
Lib_rules.setup_build_archives and into a new Jsoo_archive_rules
module that generates rules lazily, only for the specific
configuration actually requested.

Previously, building a library eagerly generated archive rules for
every jsoo configuration variant. Now, jsoo archive directories
(`.foo.objs/jsoo/<config>`) are intercepted in gen_rules and the rules
are produced on demand via dedicated memos.

To support this, Lib_rules.compile_context is exposed so that
Jsoo_archive_rules can obtain a Compilation_context.t without
triggering full library rule generation. Internally, compile_context
and rules share an intermediate helper (compile_context_data) that
computes lib_id, compile_info, modes, source_modules, and parameters
once, while keeping cctx creation inside with_lib_deps in rules to
preserve the merlin prefix on generated rules.

Signed-off-by: Jérôme Vouillon <[email protected]>
@vouillon

Copy link
Copy Markdown
Member Author

Looks promising, should we move all cm{a,o}.js artifacts under a $config subdirectory ? I think we currently don't have this for compilation units part of an executable ?

I guess we could but we don't really need that.

Do you think we should change both rules generation logic AND the separate compilation granularity in the same PR ? Could we move the incremental generation of cma.js files to a smaller sub PR ?

I'm going to split this PR in two.

vouillon added a commit to vouillon/dune that referenced this pull request Feb 11, 2026
Dune had to know about all possible Jsoo config to create rules upfront. This is no
longer necessary with ocaml#13611.
@hhugo

hhugo commented Feb 11, 2026

Copy link
Copy Markdown
Contributor

I guess we could but we don't really need that.

My hunch is that it could make the code a bit clearer by having a single place for compilation of cm* files and be less surprising when looking at the _build directory, but it's a weak preference

vouillon added a commit to vouillon/dune that referenced this pull request Feb 12, 2026
Dune had to know about all possible Jsoo config to create rules upfront. This is no
longer necessary with ocaml#13611.

Signed-off-by: Jérôme Vouillon <[email protected]>
@hhugo

hhugo commented Feb 13, 2026

Copy link
Copy Markdown
Contributor

I guess we could but we don't really need that.

My hunch is that it could make the code a bit clearer by having a single place for compilation of cm* files and be less surprising when looking at the _build directory, but it's a weak preference

I looked a this a bit more, I'm no longer sure it makes the code clearer.

@hhugo

hhugo commented Feb 13, 2026

Copy link
Copy Markdown
Contributor

Maybe add a test that would exhibit the effect of the PR ? dune show rules maybe ?

@vouillon

Copy link
Copy Markdown
Member Author

Maybe add a test that would exhibit the effect of the PR ? dune show rules maybe ?

I'm not sure what I can do. dune show rules does not seem to list all the rules.

@rgrinberg
rgrinberg merged commit 77bf40d into ocaml:main Feb 18, 2026
52 of 53 checks passed
vouillon added a commit to vouillon/dune that referenced this pull request Feb 26, 2026
Dune had to know about all possible Jsoo config to create rules upfront. This is no
longer necessary with ocaml#13611.

Signed-off-by: Jérôme Vouillon <[email protected]>
vouillon added a commit to vouillon/dune that referenced this pull request Feb 26, 2026
Dune had to know about all possible Jsoo config to create rules upfront. This is no
longer necessary with ocaml#13611.

Signed-off-by: Jérôme Vouillon <[email protected]>
vouillon added a commit to vouillon/dune that referenced this pull request Feb 26, 2026
Dune had to know about all possible Jsoo config to create rules upfront. This is no
longer necessary with ocaml#13611.

Signed-off-by: Jérôme Vouillon <[email protected]>
rgrinberg pushed a commit that referenced this pull request Mar 14, 2026
Dune had to know about all possible Jsoo config to create rules upfront.
This is no longer necessary with
#13611.

The corresponding Js_of_ocaml changes are in
ocsigen/js_of_ocaml#2177.

Signed-off-by: Jérôme Vouillon <[email protected]>
Alizter pushed a commit that referenced this pull request Jun 3, 2026
Reproduce an internal error introduced by the demand-driven jsoo
archive rules (#13611): when two libraries with the same name are
distinguished by mutually exclusive enabled_if clauses, the rules
are generated for the first stanza by position even when it is
disabled, leading to a failed module lookup.

Signed-off-by: Jérôme Vouillon <[email protected]>
@Alizter Alizter added this to the 3.22.0 milestone Jul 8, 2026
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.

4 participants