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

Add: Rust bindings generate using bindgen #243

Merged
merged 7 commits into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ CMakeCache.txt
cmake_install.cmake
CMakeFiles
build/
target/
build_debug/
build_release/
tmp/
Expand Down
6 changes: 5 additions & 1 deletion .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
"configurations": [
{
"name": "Linux",
"configurationProvider": "ms-vscode.cmake-tools"
"configurationProvider": "ms-vscode.cmake-tools",
"includePath": [
"${default}",
"${workspaceFolder}/include"
]
}
],
"version": 4
Expand Down
6 changes: 6 additions & 0 deletions rust/.clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Right now we just use the defaults. This file exists should we
# want to change that, and to indicate to contributors that they
# might want to run clippy.
#
# See https://rust-lang.github.io/rust-clippy/master/index.html for
# the complete list of lints.
20 changes: 20 additions & 0 deletions rust/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# EditorConfig coding styles definitions. For more information about the
# properties used in this file, please see the EditorConfig documentation:
# http://editorconfig.org/

root = true

[*]
charset = utf-8
end_of_line = LF
indent_size = 4
indent_style = tab
insert_final_newline = true
trim_trailing_whitespace = true

[*.{yml,json}]
indent_size = 2
indent_style = space

[*.{md,diff}]
trim_trailing_whitespace = false
25 changes: 25 additions & 0 deletions rust/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# CHANGELOG

## 26-01-2023

### Contributors

- chungquantin

### Added

- Database structure

```rs
struct Database {
db: UkvDatabaseInitType
}
```

- Build bindings to `cpp` header file in `include/ukv`. To generate bindings code stored, use `cargo build`. `build.rs` includes code to build bindings using `bindgen`
- Support two APIs: `ukv_database_init` and `ukv_database_free`
- Add clippy, rust-fmt and editor config file for formatting and linting

### Issues

- Can't generate bindings on file with linked source header. For example, generate on file `blobs.h` which includes `ukv/db.h` would throw error `No header file found`.
263 changes: 263 additions & 0 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "ukv"
version = "0.0.1"
publish = true
edition = "2021"
readme = "CARGO.md"
homepage = "https://github.com/unum-cloud/ukv"
repository = "https://github.com/unum-cloud/ukv"
documentation = "https://unum.cloud/ukv/rust/index.html"

[build-dependencies]
bindgen = "0.63.0"

[lib]
name = "ukv"

[dependencies]
thiserror = "1.0.38"
10 changes: 6 additions & 4 deletions rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

Rust implementation is designed to support:

* Named Collections
* ACID Transactions
* Single & Batch Operations
* [Apache DataFusion](https://arrow.apache.org/datafusion/) `TableProvider` for SQL
- Named Collections
- ACID Transactions
- Single & Batch Operations
- [Apache DataFusion](https://arrow.apache.org/datafusion/) `TableProvider` for SQL
- Tabular operation with [Polars](https://www.pola.rs/) and integration with [`Apache Arrow`](https://pola-rs.github.io/polars-book/user-guide/howcani/interop/arrow.html)
- NetworkX compatibility using [RustworkX](https://github.com/Qiskit/rustworkx)

Using it should be, again, familiar, as it mimics [`std::collections`](https://doc.rust-lang.org/std/collections/hash_map/struct.HashMap.html):

Expand Down
20 changes: 20 additions & 0 deletions rust/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
extern crate bindgen;

use std::env::var;
use std::path::PathBuf;

fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("cargo:rerun-if-changed=wrapper.h");
// println!("cargo:rustc-link-search=../include");

let bindings = bindgen::Builder::default()
.header("./wrapper.h")
.clang_args(&["-I../include", "-I../include/ukv"])
.detect_include_paths(true)
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.generate()?;

let out_path = PathBuf::from(var("OUT_DIR")?);
bindings.write_to_file(out_path.join("bindings.rs"))?;
Ok(())
}
Loading