Skip to content

feat(bindings/cpp): generate Capability from core - #9127

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

chitralverma wants to merge 1 commit into
apache:mainfrom
chitralverma:feat/generate-cpp-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 C++ opendal::Capability was hand-copied from core in four places: the cxx bridge struct, the Rust conversion, the public C++ class, and the field-by-field copy in Operator::Info(). It exposed only 32 of the 98 core fields. This PR generates all four 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/cpp.rs + dev/src/generate/cpp/*.j2: new generate -l cpp target that renders:
    • bindings/cpp/src/capability.rs: a dedicated #[cxx::bridge] holding the shared ffi::Capability struct, plus From<opendal::Capability>. Limits map None to 0, as before.
    • bindings/cpp/include/capability.hpp: the public opendal::Capability class with docs from core. Members are now default-initialized. The 32 members that existed before (stat through shared) come first in their original order, so positional brace-initialization keeps its meaning. New members follow in core order. The cxx bridge stays in core order, because the converter copies by name. Doc comments are wrapped to the 80-column clang-format limit, so formatting the header leaves it unchanged.
    • bindings/cpp/src/utils/capability_converter.cpp: the ffi::Capability to opendal::Capability copy.
  • src/lib.rs uses the generated struct through an extern "C++" type alias, and Operator::info becomes a one-line .into(). build.rs and CMakeLists.txt compile and export the new bridge, and data_structure.hpp includes capability.hpp.
  • The C++ keyword delete keeps its existing spelling, delete_feature.
  • ci_odev.yml: check_generated now runs generate -l cpp and cargo fmt for C++, so drift from core fails CI.
  • ci_bindings_cpp.yml: regenerates and runs git diff --exit-code, and also triggers on dev/src/generate/** and core capability.rs.
  • Class docs note that the flags describe the core operator, so a flag can be true even when the binding has no matching method (for example restore).
  • Tests:
    • tests/capability_test.cpp (C++17): opendal::Capability caps{false, false, false, true} sets caps.read, a longer positional initializer reaches the historical size limits and create_dir, and a memory operator reports its capability. Against the previous core-order header, this file fails to compile (the size limits in the second test would narrow into bool members).
    • dev/src/generate/cpp.rs unit tests (run by test_dev) check the historical public prefix, that the appended fields keep core order, that every core field appears exactly once, and that the rendered bridge, From conversion, and converter map every core field.
  • bindings/cpp/upgrade.md (new, linked from the README): an Unreleased note about the layout change.

Are there any user-facing changes?

Yes. opendal::Capability now exposes every core capability (for example stat_with_version, write_with_if_not_exists, delete_with_recursive, list_with_versions, compose, restore). Existing member names, types, and declaration order are unchanged, and new members are appended after shared.

The object layout changes: on 64-bit targets sizeof(opendal::Capability) grows from 56 to 152 bytes (measured with Apple clang on arm64). See Breaking changes.

Breaking changes

Affected packages: bindings/cpp

Migration:

  • Rebuild every C++ object that includes OpenDAL headers against the headers and library from the same OpenDAL source version. Mixing objects compiled against the old headers with the new library is unsupported. Source code that uses member names or positional initialization of the historical members does not need changes. See bindings/cpp/upgrade.md under Unreleased.

AI Usage Statement

  • Harness: Jcode | Model: Claude Opus 5.5 | Effort: medium | Role: Implemented the generator, templates, and CI drift check, ran the C++ tests (sync and async) and the examples build, 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 as a single commit, regenerated the output for core's new read_with_checksum and write_with_checksum fields, re-ran the dev and C++ checks, re-measured sizeof(opendal::Capability), wrapped the header's generated doc comments to the clang-format column limit, and synced this description.

@github-actions github-actions Bot added bindings/cpp 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:26

@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 8efee5952f.

Please preserve the order of the 32 existing public opendal::Capability members. This C++17 initializer compiles against both headers, but changes what the caller asks for when recompiled.

opendal::Capability caps{false, false, false, true};

On 2ea4e3899a, the fourth initializer sets caps.read. On this head it sets caps.stat_with_if_version_match and leaves caps.read false.

Please generate the public class with its historical members first (stat through shared), then append the new fields in core order. The internal CXX bridge can keep core order because the converter copies fields by name.

Please add a C++17 regression test that checks caps.read for this initializer. The generator checks in CI should also cover the historical public prefix, the order of the appended fields, and the bridge mapping for every core field.

On Linux x86-64, sizeof(opendal::Capability) grew from 56 bytes to 144 on this head. Please measure the revised generated class and add an upgrade note telling consumers to rebuild their C++ objects against the matching headers and library.

@chitralverma

Copy link
Copy Markdown
Contributor Author

Thanks, adopted in 7c60ca4.

  • The 32 historical members (stat through shared) are now emitted first in their original order, and the 64 new fields are appended in core order. The cxx bridge keeps core order, since parse_capability copies by name.
  • tests/capability_test.cpp (C++17) checks that opendal::Capability caps{false, false, false, true} sets caps.read. A second positional initializer reaches write_multi_max_size / write_multi_min_size / write_total_max_size / create_dir. Built against the previous header, the file fails to compile.
  • New dev/src/generate/cpp.rs tests check the historical prefix, that the appended fields stay in core order, that each core field appears exactly once, and that the rendered bridge, From conversion, and converter map all 96 core fields.
  • sizeof(opendal::Capability) is now 152 bytes (Apple clang, arm64; it was 56 before). I added bindings/cpp/upgrade.md, linked from the README, with a rebuild note, plus a Breaking changes declaration and the breaking-changes label. The declaration passes scripts/release_impact.py's parser.

Verified locally on this head: dev cargo test (50) and clippy, CMake suite with services-memory (sync 97, async 109), and the examples/cpp build.

@chitralverma
chitralverma requested a review from Xuanwo November 26, 2026 13:01
@chitralverma
chitralverma force-pushed the feat/generate-cpp-capability branch from 073fcb1 to f835963 Compare November 27, 2026 08:32
@chitralverma

Copy link
Copy Markdown
Contributor Author

(AI-generated reply) Rebased onto main and squashed into f835963. The changes from 7c60ca4 (historical member order, C++17 regression test, generator order/mapping tests, upgrade note) carry over unchanged. Regenerating picked up core's new read_with_checksum and write_with_checksum, which were the cause of the check_generated / test drift failures. Both are appended after shared. sizeof(opendal::Capability) is still 152 bytes (Apple clang, arm64), so upgrade.md stays accurate.

@chitralverma
chitralverma force-pushed the feat/generate-cpp-capability branch from f835963 to 6565b1b Compare November 27, 2026 08:52
Generate the cxx bridge struct, its conversion from core, the public
opendal::Capability class, and the converter between them from
core/core/src/types/capability.rs, and fail CI when they drift.

The 32 historical public members keep their names, types, and declaration
order, so positional brace-initialization keeps its meaning. New members
are appended in core order. The cxx bridge stays in core order because the
converter copies by name.

Add a C++17 regression test for positional initialization, generator
tests for the public order and the bridge mapping, and an upgrade note
for the layout change.

Part of apache#9122.

Signed-off-by: Chitral Verma <chitralverma@gmail.com>
@chitralverma
chitralverma force-pushed the feat/generate-cpp-capability branch from 6565b1b to b295815 Compare November 27, 2026 09:21

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/cpp breaking-changes 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