Repository navigation
feat(bindings/cpp): generate Capability from core - #9127
chitralverma wants to merge 1 commit into
Conversation
Xuanwo
left a comment
There was a problem hiding this comment.
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.
|
Thanks, adopted in 7c60ca4.
Verified locally on this head: dev |
073fcb1 to
f835963
Compare
|
(AI-generated reply) Rebased onto |
f835963 to
6565b1b
Compare
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>
6565b1b to
b295815
Compare
Which issue does this PR close?
Part of #9122.
Rationale for this change
The C++
opendal::Capabilitywas hand-copied from core in four places: the cxx bridge struct, the Rust conversion, the public C++ class, and the field-by-field copy inOperator::Info(). It exposed only 32 of the 98 core fields. This PR generates all four fromcore/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: newgenerate -l cpptarget that renders:bindings/cpp/src/capability.rs: a dedicated#[cxx::bridge]holding the sharedffi::Capabilitystruct, plusFrom<opendal::Capability>. Limits mapNoneto0, as before.bindings/cpp/include/capability.hpp: the publicopendal::Capabilityclass with docs from core. Members are now default-initialized. The 32 members that existed before (statthroughshared) 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: theffi::Capabilitytoopendal::Capabilitycopy.src/lib.rsuses the generated struct through anextern "C++"type alias, andOperator::infobecomes a one-line.into().build.rsandCMakeLists.txtcompile and export the new bridge, anddata_structure.hppincludescapability.hpp.deletekeeps its existing spelling,delete_feature.ci_odev.yml:check_generatednow runsgenerate -l cppandcargo fmtfor C++, so drift from core fails CI.ci_bindings_cpp.yml: regenerates and runsgit diff --exit-code, and also triggers ondev/src/generate/**and corecapability.rs.restore).tests/capability_test.cpp(C++17):opendal::Capability caps{false, false, false, true}setscaps.read, a longer positional initializer reaches the historical size limits andcreate_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 intoboolmembers).dev/src/generate/cpp.rsunit tests (run bytest_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,Fromconversion, 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::Capabilitynow exposes every core capability (for examplestat_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 aftershared.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:
bindings/cpp/upgrade.mdunder Unreleased.AI Usage Statement
mainas a single commit, regenerated the output for core's newread_with_checksumandwrite_with_checksumfields, re-ran the dev and C++ checks, re-measuredsizeof(opendal::Capability), wrapped the header's generated doc comments to the clang-format column limit, and synced this description.