Skip to content

Commit af8d281

Browse files
committed
Initial commit
0 parents  commit af8d281

File tree

15 files changed

+4240
-0
lines changed

15 files changed

+4240
-0
lines changed

.gitignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
bindings.rs
2+
Cargo.lock
3+
4+
# build
5+
build/
6+
# clangd
7+
.clangd/
8+
.cache/clangd/
9+
compile_commands.json
10+
11+
# vim session file
12+
Session.vim
13+
# vscode
14+
*.workspace
15+
*.code-workspace
16+
.vscode/
17+
18+
19+
# Added by cargo
20+
21+
/target

Cargo.toml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
[package]
2+
name = "rdma"
3+
version = "0.1.0"
4+
edition = "2021"
5+
links = "libibverbs"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
[build-dependencies]
9+
bindgen = "0.69.4"
10+
cc = "1.0.70"
11+
12+
[dependencies]
13+
phoenix-api = { git = "https://github.com/phoenix-dataplane/phoenix-api", tag = "v0.1.0", optional = true }
14+
mmap = { git = "https://github.com/phoenix-dataplane/mmap-rs", tag = "v0.1.0", optional = true }
15+
16+
thiserror = "1.0.29"
17+
log = "0.4.14"
18+
libc = "0.2.103"
19+
static_assertions = "1.1.0"
20+
socket2 = "0.4.7"
21+
memfd = "0.4.1"
22+
bincode = { version = "1.3.3", optional = true }
23+
serde = { version = "1.0.130", features = ["derive"], optional = true }
24+
spin = { version = "0.9.3", optional = true }
25+
lazy_static = { version = "1.4.0", optional = true }
26+
nix = { version = "0.25.0", default-features = false, features = ["socket", "net"] }
27+
28+
[features]
29+
phoenix = ["dep:phoenix-api", "dep:serde", "dep:bincode", "dep:mmap", "dep:spin", "dep:lazy_static"]

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 phoenix-dataplane
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# rdma-rs
2+
3+
Rust API wrapping the `ibverbs` and `rdmacm` Remote Direct Memory Access (RDMA) library.
4+
5+
TODO:
6+
- add docs to APIs
7+
- remove in function assertions and logs
8+
- add examples
9+
10+
To manually generate the binding, use this
11+
```
12+
~/.cargo/bin/bindgen \
13+
-o bindings.rs \
14+
--blocklist-type max_align_t \
15+
--blocklist-type ibv_wc \
16+
--no-prepend-enum-name \
17+
--bitfield-enum ibv_access_flags \
18+
--bitfield-enum ibv_qp_attr_mask \
19+
--bitfield-enum ibv_wc_flags \
20+
--bitfield-enum ibv_send_flags \
21+
--bitfield-enum ibv_port_cap_flags \
22+
--constified-enum-module ibv_qp_type \
23+
--constified-enum-module ibv_qp_state \
24+
--constified-enum-module ibv_port_state \
25+
--constified-enum-module ibv_wc_opcode \
26+
--constified-enum-module ibv_wr_opcode \
27+
--constified-enum-module ibv_wc_status \
28+
--constified-enum-module rdma_port_space \
29+
--constified-enum-module rdma_cm_event_type \
30+
src/rdma_verbs_wrapper.h -- -I/usr/include
31+
```
32+
33+
# Acknowledgement
34+
This crate is developed based on [rust-ibverbs](https://github.com/jonhoo/rust-ibverbs).

build.rs

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
extern crate bindgen;
2+
3+
use std::env;
4+
use std::path::PathBuf;
5+
6+
fn main() {
7+
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
8+
9+
println!("You need to have librdmacm and libibverbs installed in your system.");
10+
println!("cargo:rerun-if-changed=src/rdma_verbs_wrapper.c");
11+
12+
// let mut cc_command = cc::Build::new()
13+
// .warnings(true)
14+
// .opt_level(3)
15+
// .cargo_metadata(false)
16+
// .pic(true)
17+
// .use_plt(false)
18+
// .shared_flag(true)
19+
// .static_flag(true)
20+
// .get_compiler()
21+
// .to_command();
22+
23+
// // Compile dynamic library manually as cc-rs is not intended to create dynamic library.
24+
// cc_command.args([
25+
// "src/rdma_verbs_wrapper.c",
26+
// "-o",
27+
// &out_path.join("librdma_verbs_wrapper.so").to_string_lossy(),
28+
// ]);
29+
30+
// // COMMENT(cjr): Remove this comment to see the compiler command.
31+
// // println!("cargo:warning=compiler command: {:?}", cc_command);
32+
// cc_command
33+
// .spawn()
34+
// .expect("Failed to build the shared library");
35+
36+
cc::Build::new()
37+
.warnings(true)
38+
.opt_level(3)
39+
.cargo_metadata(false)
40+
.pic(true)
41+
.use_plt(false)
42+
.shared_flag(true)
43+
.static_flag(true)
44+
.file("src/rdma_verbs_wrapper.c")
45+
.compile("rdma_verbs_wrapper");
46+
47+
let bindings = bindgen::Builder::default()
48+
.header("src/rdma_verbs_wrapper.h")
49+
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
50+
.blocklist_type("max_align_t")
51+
.blocklist_type("ibv_wc")
52+
.bitfield_enum("ibv_access_flags")
53+
.bitfield_enum("ibv_qp_attr_mask")
54+
.bitfield_enum("ibv_wc_flags")
55+
.bitfield_enum("ibv_send_flags")
56+
.bitfield_enum("ibv_port_cap_flags")
57+
.constified_enum_module("ibv_qp_type")
58+
.constified_enum_module("ibv_qp_state")
59+
.constified_enum_module("ibv_port_state")
60+
.constified_enum_module("ibv_wc_opcode")
61+
.constified_enum_module("ibv_wr_opcode")
62+
.constified_enum_module("ibv_wc_status")
63+
.constified_enum_module("rdma_port_space")
64+
.constified_enum_module("rdma_cm_event_type")
65+
.derive_default(true)
66+
.derive_debug(true)
67+
.generate()
68+
.expect("Unable to generate bindings");
69+
70+
// Write the bindings to the $OUT_DIR/bindings.rs file.
71+
bindings
72+
.write_to_file(out_path.join("bindings.rs"))
73+
.expect("Couldn't write bindings!");
74+
75+
println!("cargo:rustc-link-search=native={}", out_path.display());
76+
println!("cargo:rustc-link-lib=static=rdma_verbs_wrapper");
77+
// println!("cargo:rustc-link-lib=dylib=rdma_verbs_wrapper");
78+
// println!("cargo:rustc-link-arg=-Wl,-rpath={}", out_path.display());
79+
// println!(
80+
// "cargo:rustc-cdylib-link-arg=-Wl,-rpath={}",
81+
// out_path.display()
82+
// );
83+
84+
println!("cargo:rustc-link-lib=ibverbs");
85+
println!("cargo:rustc-link-lib=rdmacm");
86+
}

0 commit comments

Comments
 (0)