Skip to content

Upstream OxCaml#1399

Open
art-w wants to merge 22 commits intoocaml:masterfrom
art-w:upstream-oxcaml
Open

Upstream OxCaml#1399
art-w wants to merge 22 commits intoocaml:masterfrom
art-w:upstream-oxcaml

Conversation

@art-w
Copy link
Copy Markdown
Contributor

@art-w art-w commented Jan 28, 2026

(builds on top of #1398 which provides ocaml-config:ox to detect OxCaml)

This PR is a rebase of @lukemaurer 's patches from oxcaml/odoc (+ small fixes from #22). I hope this will make it easier to keep everything uptodate, and that it isn't too much of a stretch as Odoc already supports multiple versions of the OCaml AST using cppo. (Note that the preprocessor was originally using OCAML_VERSION=(5,2,0) as a heuristic to check for OxCaml, but since dune 3.21 we can be exact.)

(chdir
%{workspace_root}
(run %{bin:cppo} -V OCAML:%{ocaml_version} -D "OXCAML" %{x} -o %{targets}))))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The rules duplication, here and in src/loader/dune, are rather inconvenient but I didn't find how to avoid it: cppo only accepts variables with integer values in conditionals, but dune %{ocaml-config:ox} is a boolean with no way to cast it to an int (?). I tried cppo -D "OXCAML %{ocaml-config:ox} but then the variable can't be used in #if. Please let me know if you know a better way!

@art-w art-w marked this pull request as draft January 28, 2026 14:55
@art-w art-w force-pushed the upstream-oxcaml branch 2 times, most recently from f36c8b9 to cd3629c Compare February 18, 2026 11:37
jonnyfiveisonline pushed a commit to jonnyfiveisonline/odoc that referenced this pull request Feb 18, 2026
Add support for building js_top_worker and odoc with both the standard
OCaml 5.4 compiler and the OxCaml 5.2.0+ox compiler using cppo
conditional compilation and dual dune stanzas.

js_top_worker changes:
- Bump dune-project to 3.21 for %{ocaml-config:ox} support
- Add dual library stanzas gated by (enabled_if %{ocaml-config:ox})
- Add cppo guards for OxCaml API differences:
  - Compilation_unit.Name.t vs string for persistent loader
  - Env.report_error ~level:0 (extra parameter)
  - Language_extension.set_universe_and_enable_all (oxcaml-only)
  - Unit_info.make ~for_pack_prefix (extra parameter)
  - Typemod.type_implementation (extra Compilation_unit arg)
- Gate ppx_deriving_rpc with (not %{ocaml-config:ox})

odoc changes:
- Apply upstream oxcaml PR ocaml#1399 (art-w/upstream-oxcaml)
- Bump dune-project to 3.21
- Add dual stanzas in loader, model, xref2, odoc, syntax_highlighter
- Add cppo OXCAML guards for compiler API differences
- Support OxCaml features: modes, layouts, labeled tuples, iarray,
  unboxed records, module type strengthening, polymorphic arguments,
  call position arguments, Import_info.t, Compilation_unit.t

Verified end-to-end: scrollycode demos generate HTML and the
interactive playground evaluates OCaml code in the browser with
both compiler switches.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@art-w art-w force-pushed the upstream-oxcaml branch from 8fa44a8 to 745c7eb Compare March 17, 2026 09:17
@art-w art-w force-pushed the upstream-oxcaml branch from 745c7eb to 0c0d345 Compare March 17, 2026 09:20
@art-w art-w force-pushed the upstream-oxcaml branch from 8e3ea13 to bdb6f2e Compare March 17, 2026 10:15
@art-w art-w force-pushed the upstream-oxcaml branch from 06b3c16 to a3a6c22 Compare March 17, 2026 10:40
@art-w art-w marked this pull request as ready for review March 19, 2026 07:59

- name: Install dependencies
run: |
sed -i '/bisect_ppx/d' odoc.opam
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

bisect_ppx is currently incompatible with OxCaml, bringing the coverage down

@art-w
Copy link
Copy Markdown
Contributor Author

art-w commented Mar 19, 2026

@jonludlam If you have time, I think this PR is in good shape for a review!

This is only the first step to integrate oxcaml/odoc in this repo, so currently I've left out a small patch "Support OxCaml polymorphic arguments (#4)" from @lukemaurer as it was breaking the OCaml 4.08 regression tests. The polymorphic arguments require a bit more work and testing so I'll open another PR for them.

The other useful patches from @lukemaurer in oxcaml/odoc are not directly related to OxCaml support, so I've left them out to ease the review as we can cherry-pick them later:

  • 7770657 - CSS fix for layout when there is no global ToC (#12) has "FIXME: This will probably get a better fix upstream"
  • 8213d44 - Add source locations to more places (#14) uses an alternative source_loc_jane to point at file locations
  • 4b8f988 - Print source information in implementations (#13) is also useful but not OxCaml specific
  • 328ae6f - Support compiling against 'result' library (#19) conflicts with 8478ff4 Remove dependency on the 'result' package by @Julow
  • 0e57a5b - Update integration test (#21) is a fix of a test output, not required for this PR

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.

2 participants