Skip to content

Generate jsoo library archive rules on demand#13611

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

Generate jsoo library archive rules on demand#13611
rgrinberg merged 1 commit intoocaml:mainfrom
vouillon:jsoo-on-demand

Conversation

@vouillon
Copy link
Member

@vouillon vouillon commented Feb 11, 2026

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
Member Author

@hhugo Can you have a look?

@hhugo
Copy link
Collaborator

hhugo commented Feb 11, 2026

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
Copy link
Collaborator

hhugo commented Feb 11, 2026

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 <jerome.vouillon@gmail.com>
@vouillon
Copy link
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
Copy link
Collaborator

hhugo commented Feb 11, 2026

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 <jerome.vouillon@gmail.com>
@hhugo
Copy link
Collaborator

hhugo commented Feb 13, 2026

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
Copy link
Collaborator

hhugo commented Feb 13, 2026

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

@vouillon
Copy link
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
54 of 55 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 <jerome.vouillon@gmail.com>
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 <jerome.vouillon@gmail.com>
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 <jerome.vouillon@gmail.com>
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