Skip to content

feat(bindings/ocaml): generate Capability from core - #9128

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

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

Conversation

@chitralverma

@chitralverma chitralverma commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Part of #9122.

Rationale for this change

The OCaml Capability module was hand-copied from core across the Rust FFI accessors (src/operator/capability.rs) and the public Capability module in lib/operator.ml{,i}. It exposed only 16 of the 98 core fields. This PR generates it from core/core/src/types/capability.rs, as Java (#8644) and .NET (#8146) already do.

What changes are included in this PR?

  • dev/src/generate/ocaml.rs + dev/src/generate/ocaml/*.j2: new generate -l ocaml target that renders:
    • bindings/ocaml/src/operator/capability.rs: one #[ocaml::func] accessor per core field.
    • bindings/ocaml/lib/capability.ml{,i}: the public Capability module, with odoc taken from core. The module doc notes that the flags describe the core operator, so a flag can be true even when the binding has no matching function (for example restore).
  • src/operator.ml{,i}: the external declarations, regenerated from the Rust accessors by ocaml-build during the build.
  • lib/operator.ml{,i}: operator.ml aliases the generated module (module Capability = Capability), and operator.mli exposes it structurally (module Capability : module type of Capability). Operator.Capability.* keeps working, and downstream wrappers that re-include Capability still match module type of Opendal.Operator. test/test.ml adds a compile-time check for such a wrapper.
  • .ocamlformat-ignore: ignores the generated lib/capability.ml{,i}, like the existing src/** entry.
  • CI drift checks:
    • ci_odev.yml (check_generated): runs generate -l ocaml and cargo fmt for OCaml.
    • ci_bindings_ocaml.yml: after dune runtest, which also rebuilds src/operator.ml{,i}, regenerates and runs git diff --exit-code. The workflow also triggers on dev/src/generate/** and core capability.rs.

Are there any user-facing changes?

Yes, additions only. Operator.Capability now exposes every core capability. Size limits (for example write_multi_max_size) are int64 option, as Metadata already does for last_modified. Existing accessors keep their names and types.

Breaking changes

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: xhigh, then medium | Role: Rebased onto current main and regenerated the files for the new core fields (read_with_checksum, write_with_checksum), followed up on review, ran the OCaml checks after the rebase, and updated this description.

@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:XXL This PR changes 1000+ lines, ignoring generated files. labels Nov 26, 2026
@chitralverma
chitralverma marked this pull request as ready for review November 26, 2026 06:29

@Xuanwo Xuanwo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

AI-generated review of 0e4aab0f3f.

Please expose Capability structurally in bindings/ocaml/lib/operator.mli. The public module alias requires downstream wrappers to preserve module identity. For example, this wrapper compiles against the base and fails with a signature mismatch on this head.

module Wrapped : module type of Opendal.Operator = struct
  include Opendal.Operator
  module Capability = struct
    include Opendal.Operator.Capability
  end
end

Changing the interface declaration fixes the wrapper. The implementation alias in operator.ml can stay as it is.

-module Capability = Capability
+module Capability : module type of Capability

With this change, all 96 accessor declarations are preserved. The wrapper, native and bytecode consumers, and the 23 binding tests pass.

@chitralverma

Copy link
Copy Markdown
Contributor Author

Thanks, adopted in 46fa975. operator.mli now declares module Capability : module type of Capability, and operator.ml keeps the alias.

I added your wrapper as a compile-time check in test/test.ml (Wrapped_operator : module type of Opendal.Operator), along with a small runtime test that uses it. Reverting the .mli line makes dune build @runtest fail with Signature mismatch.

Verified locally: dune build, dune build @fmt, dune runtest (24 tests), dune build @run_examples, and cargo clippy -D warnings.

chitralverma added a commit to chitralverma/opendal that referenced this pull request Nov 26, 2026
Same as Capability in apache#9128: a module alias in the interface forces
downstream wrappers to keep module identity. Add a compile-time regression
test for such a wrapper.

Signed-off-by: Chitral Verma <chitralverma@gmail.com>
@chitralverma
chitralverma requested a review from Xuanwo November 26, 2026 13:02
@chitralverma
chitralverma force-pushed the feat/generate-ocaml-capability branch from aedc77c to 13c6d96 Compare November 27, 2026 08:30
@chitralverma

Copy link
Copy Markdown
Contributor Author

(AI-generated reply) The branch is rebased onto main and squashed into 13c6d96. The fix for the review above (module Capability : module type of Capability in lib/operator.mli, plus the Wrapped_operator compile-time check in test/test.ml) is unchanged in that commit; 46fa97562 no longer exists. The generated files now also include the new core fields read_with_checksum and write_with_checksum, which caused the check_generated and test failures.

Generate the OCaml Capability FFI accessors and public module from
core/core/src/types/capability.rs, and check for drift in CI.

Part of apache#9122.

Signed-off-by: Chitral Verma <chitralverma@gmail.com>
@chitralverma
chitralverma force-pushed the feat/generate-ocaml-capability branch from 13c6d96 to 4b6051a Compare November 27, 2026 09:07

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:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants