Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bindings/cpp): init the async support of C++ binding #5195

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

PragmaTwice
Copy link
Member

@PragmaTwice PragmaTwice commented Oct 17, 2024

Which issue does this PR close?

Part of #5194.

Rationale for this change

This PR initializes the async version of C++ binding.

What changes are included in this PR?

  • build system support for async C++ API (cmake and build.rs)
  • an initial version of async Operator including write and read methods
  • a test case for async C++ API with cppcoro as a C++ coroutine runtime

Are there any user-facing changes?

Since OPENDAL_ENABLE_ASYNC is off by default, so current users shouldn't feel the difference.

bindings/cpp/CMakeLists.txt Show resolved Hide resolved
@@ -34,6 +34,8 @@ crate-type = ["staticlib"]
anyhow = "1.0"
chrono = "0.4"
cxx = "1.0"
# cxx-async v0.1.1 in crates.io has build problems, so we use git repo directly
cxx-async = { git = "https://github.com/pcwalton/cxx-async", rev = "961dd106b8eb2a86991728e1a18948e597426c1a", optional = true }
Copy link
Member

Choose a reason for hiding this comment

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

It appears that cxx-async is no longer maintained. Should we consider forking it and maintaining it ourselves?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I also noticed that. Good to folk it so that we don't need to wait maintainers response while contributing.

Copy link
Member

Choose a reason for hiding this comment

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

This may prevent us from merging this PR. OpenDAL does not permit dependencies on a git version crate, as this could disrupt our release process.

I'm trying to contact with @pcwalton at pcwalton/cxx-async#6

Copy link
Member Author

Choose a reason for hiding this comment

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

I see. Hope the author can respond so we don't need to folk.

bindings/cpp/build.rs Outdated Show resolved Hide resolved
bindings/cpp/build.rs Outdated Show resolved Hide resolved
bindings/cpp/src/async.rs Outdated Show resolved Hide resolved
@PragmaTwice PragmaTwice marked this pull request as ready for review October 17, 2024 15:30
@PragmaTwice
Copy link
Member Author

PragmaTwice commented Oct 17, 2024

It's ready for review now : )

Comment on lines +46 to +58
auto path = "test_path";
std::vector<uint8_t> data{1, 2, 3, 4, 5};
cppcoro::sync_wait(op->write(path, data));
auto res = cppcoro::sync_wait(op->read(path));
for (size_t i = 0; i < data.size(); ++i) EXPECT_EQ(data[i], res[i]);

path = "test_path2";
cppcoro::sync_wait([&]() -> cppcoro::task<void> {
co_await op->write(path, data);
auto res = co_await op->read(path);
for (size_t i = 0; i < data.size(); ++i) EXPECT_EQ(data[i], res[i]);
co_return;
}());
Copy link
Member Author

Choose a reason for hiding this comment

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

A quick demo of async C++ binding.

Copy link
Member

Choose a reason for hiding this comment

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

So cool!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants