You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by "silver-ymz (via GitHub)" <gi...@apache.org> on 2023/08/30 15:49:02 UTC
[GitHub] [incubator-opendal] silver-ymz opened a new pull request, #2980: Cpp binding
silver-ymz opened a new pull request, #2980:
URL: https://github.com/apache/incubator-opendal/pull/2980
## A demo for cpp binding
We use [`cxx`](https://cxx.rs/) to interop between Rust and C++.
About build system, rust side still use `cargo`. For better integration with google test, we use [`cmake`](https://cmake.org/) and [`ninja`](https://ninja-build.org/) to build c++ code. All build scripts are written in `cmake`, so `ninja` can be replaced by [`make`](https://www.gnu.org/software/make/manual/make.html) or [`bazel`](https://bazel.build/). I choose it just because it looks like faster.
### Example
```cpp
#include "opendal.hpp"
#include <vector>
int main() {
auto op = opendal::Operator("memory");
std::vector<uint8_t> data = {1, 2, 3, 4, 5};
op.write("test", data);
auto result = op.read("test"); // result == data
}
```
### Exist Problem
Now I can only build static library, failed to build dynamic library.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-opendal] Xuanwo merged pull request #2980: feat(bindings/cpp): init cpp binding
Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo merged PR #2980:
URL: https://github.com/apache/incubator-opendal/pull/2980
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(bindings/cpp): init cpp binding [opendal]
Posted by "XinyuZeng (via GitHub)" <gi...@apache.org>.
XinyuZeng commented on PR #2980:
URL: https://github.com/apache/opendal/pull/2980#issuecomment-3043928137
Hi, I was wondering why at the beginning you guys did not wrap the C++ binding using the exising C binding? I guess it is more likely because of safety and ergonomics benefit of cxx, but having separate C and C++ bindings on the other hand may introduce code duplication and has less control over the code. We are discussing similar issues here: https://github.com/vortex-data/vortex/issues/3720 Would be really helpful if you can provide some lessons/insights. Thanks!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-opendal] Xuanwo commented on a diff in pull request #2980: feat(bindings/cpp): init cpp binding
Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #2980:
URL: https://github.com/apache/incubator-opendal/pull/2980#discussion_r1310994175
##########
bindings/cpp/README.md:
##########
@@ -0,0 +1,36 @@
+# OpenDAL CPP Binding (WIP)
+
+
+
+## Example
+
+```cpp
+#include "opendal.hpp"
+#include <vector>
+
+int main() {
+ auto op = opendal::Operator("memory");
+ std::vector<uint8_t> data = {1, 2, 3, 4, 5};
+ op.write("test", data);
+ auto result = op.read("test"); // result == data
+}
+```
+
+## Build
+
+```bash
+mkdir build
Review Comment:
This dir seems not exist?
##########
bindings/cpp/src/lib.rs:
##########
@@ -0,0 +1,62 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use anyhow::Result;
+use opendal as od;
+use std::collections::HashMap;
+use std::str::FromStr;
+
+#[cxx::bridge(namespace = "opendal::ffi")]
+mod ffi {
+ struct HashMapValue {
+ key: String,
+ value: String,
+ }
+
+ extern "Rust" {
+ type Operator;
+
+ fn new_operator(scheme: &str, configs: Vec<HashMapValue>) -> Result<Box<Operator>>;
+ fn read(&self, path: &str) -> Result<Vec<u8>>;
+ fn write(&self, path: &str, bs: &[u8]) -> Result<()>;
+ }
+}
+
+struct Operator(od::BlockingOperator);
+
+fn new_operator(scheme: &str, configs: Vec<ffi::HashMapValue>) -> Result<Box<Operator>> {
Review Comment:
We can't pass `Operator` directly?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-opendal] silver-ymz commented on a diff in pull request #2980: feat(bindings/cpp): init cpp binding
Posted by "silver-ymz (via GitHub)" <gi...@apache.org>.
silver-ymz commented on code in PR #2980:
URL: https://github.com/apache/incubator-opendal/pull/2980#discussion_r1311006854
##########
bindings/cpp/src/lib.rs:
##########
@@ -0,0 +1,62 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use anyhow::Result;
+use opendal as od;
+use std::collections::HashMap;
+use std::str::FromStr;
+
+#[cxx::bridge(namespace = "opendal::ffi")]
+mod ffi {
+ struct HashMapValue {
+ key: String,
+ value: String,
+ }
+
+ extern "Rust" {
+ type Operator;
+
+ fn new_operator(scheme: &str, configs: Vec<HashMapValue>) -> Result<Box<Operator>>;
+ fn read(&self, path: &str) -> Result<Vec<u8>>;
+ fn write(&self, path: &str, bs: &[u8]) -> Result<()>;
+ }
+}
+
+struct Operator(od::BlockingOperator);
+
+fn new_operator(scheme: &str, configs: Vec<ffi::HashMapValue>) -> Result<Box<Operator>> {
Review Comment:
cxx doesn't support pass opaque type by value. Its suggestion is to use pointers for returned types and references for parameters.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-opendal] silver-ymz commented on a diff in pull request #2980: feat(bindings/cpp): init cpp binding
Posted by "silver-ymz (via GitHub)" <gi...@apache.org>.
silver-ymz commented on code in PR #2980:
URL: https://github.com/apache/incubator-opendal/pull/2980#discussion_r1311007712
##########
bindings/cpp/README.md:
##########
@@ -0,0 +1,36 @@
+# OpenDAL CPP Binding (WIP)
+
+
+
+## Example
+
+```cpp
+#include "opendal.hpp"
+#include <vector>
+
+int main() {
+ auto op = opendal::Operator("memory");
+ std::vector<uint8_t> data = {1, 2, 3, 4, 5};
+ op.write("test", data);
+ auto result = op.read("test"); // result == data
+}
+```
+
+## Build
+
+```bash
+mkdir build
Review Comment:
I forget to add `cd build`. This will save all cmake caches in the `build` directory.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org