Skip to content

feat(bindings/ocaml): generate Metadata from core - #9132

Draft
chitralverma wants to merge 1 commit into
apache:mainfrom
chitralverma:feat/generate-ocaml-metadata
Draft

chitralverma wants to merge 1 commit into
apache:mainfrom
chitralverma:feat/generate-ocaml-metadata

Conversation

@chitralverma

@chitralverma chitralverma commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Part of #9129.

Rationale for this change

The OCaml Metadata module was hand-copied from core across the Rust FFI accessors (src/operator/metadata.rs) and the public module in lib/operator.ml{,i}. It exposed 8 accessors, so newer core fields such as version, is_deleted, and user_metadata were missing. This PR generates it from core/core/src/types/metadata.rs using the shared parser in dev/src/generate/metadata.rs.

What changes are included in this PR?

  • dev/src/generate/ocaml.rs + dev/src/generate/ocaml/metadata_*.j2: new generate -l ocaml target that renders:
    • bindings/ocaml/src/operator/metadata.rs: one #[ocaml::func] accessor per core accessor, plus the entry_mode variant.
    • bindings/ocaml/lib/metadata.ml{,i}: the public Metadata module, with odoc taken from core.
  • checksum is not exposed: the shared parser skips it until bindings mirror Checksum.
  • is_file and is_dir are skipped by the shared parser because core derives them from mode. The OCaml generator adds them back after mode so the existing API stays.
  • lib/operator.ml{,i}: operator.ml aliases the generated module (module Metadata = Metadata), and operator.mli exposes it structurally (module Metadata : module type of Metadata), so Operator.Metadata.* keeps working and downstream wrappers that re-include Metadata still match module type of Opendal.Operator (the same fix as feat(bindings/ocaml): generate Capability from core #9128). test/test.ml adds a compile-time regression check for such a wrapper.
  • src/operator.ml{,i}: the external declarations are regenerated by ocaml-build during dune build.
  • .ocamlformat-ignore: ignores the generated lib/metadata.ml{,i}, the same as the existing src/** entry.
  • CI: ci_odev.yml runs generate -l ocaml and cargo fmt for OCaml in check_generated. ci_bindings_ocaml.yml also runs when core metadata or the generator changes, and checks for generated-code drift after dune runtest.
  • test/test.ml: asserts mode and is_deleted for a file and a directory.

This overlaps with #9128 (OCaml Capability), which adds dev/src/generate/ocaml.rs, registers ocaml in mod.rs, and makes the same CI changes. Whichever lands second will need a small rebase to merge the two generate functions.

Are there any user-facing changes?

Yes, additions only. Operator.Metadata gains:

  • mode : metadata -> entry_mode, where entry_mode = File | Dir | Unknown mirrors core EntryMode. A variant fits OCaml better than a string and is easy to match on.
  • is_current : metadata -> bool option and is_deleted : metadata -> bool.
  • cache_control, content_encoding, content_language, and version, all string option.
  • user_metadata : metadata -> (string * string) list option, an association list copied from core.

Existing accessors keep their names, types, and behavior. last_modified is still int64 option in seconds. Docs now come from core, so some doc strings changed wording.

Breaking changes

None.

AI Usage Statement

  • Harness: Jcode | Model: Claude Opus 5.5 | Effort: medium | Role: Implemented the generator, templates, and CI drift check, ran the OCaml checks and tests, and drafted this description. I reviewed the changes.
  • Harness: Claude Code via T3 Code | Model: Claude Opus 5.5 | Effort: medium, low | Role: Rebased onto main, resolved conflicts with the Ruby generator, re-ran the OCaml checks, and updated this description. I reviewed the changes.

@github-actions github-actions Bot added bindings/ocaml releases-note/feat The PR implements a new feature or has a title that begins with "feat" size:XL This PR changes 500-999 lines, ignoring generated files. labels Nov 26, 2026
@chitralverma
chitralverma force-pushed the feat/generate-ocaml-metadata branch from e0459a9 to ae02bb1 Compare November 27, 2026 08:23
Part of apache#9129.

Signed-off-by: Chitral Verma <chitralverma@gmail.com>
@chitralverma
chitralverma force-pushed the feat/generate-ocaml-metadata branch from ae02bb1 to ac7ef02 Compare November 27, 2026 09:06

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

bindings/ocaml releases-note/feat The PR implements a new feature or has a title that begins with "feat" size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant