Skip to content

Commit

Permalink
Build outside of source dir (using cmake crate)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonhoo committed Jul 20, 2024
1 parent 856c5c8 commit ef41036
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
16 changes: 16 additions & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion ibverbs-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ibverbs-sys"
version = "0.2.0+52.0"
version = "0.2.1+52.0"
edition = "2021"

description = "Raw, FFI bindings for RDMA ibverbs through rdma-core"
Expand All @@ -24,6 +24,7 @@ exclude = ["vendor/rdma-core/build/"]

[build-dependencies]
bindgen = "0.69.2"
cmake = "0.1.50"

# to make -Zminimal-versions work
[target.'cfg(any())'.dependencies]
Expand Down
23 changes: 15 additions & 8 deletions ibverbs-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ fn main() {
println!("cargo:rustc-link-search=native={manifest_dir}/vendor/rdma-core/build/lib");
println!("cargo:rustc-link-lib=ibverbs");

// initialize and update submodules
if Path::new(".git").is_dir() {
if Path::new("vendor/rdma-core/CMakeLists.txt").exists() {
// don't touch source dir if not necessary
} else if Path::new(".git").is_dir() {
// initialize and update submodules
Command::new("git")
.args(["submodule", "update", "--init"])
.status()
Expand All @@ -22,16 +24,21 @@ fn main() {
}

// build vendor/rdma-core
Command::new("bash")
.current_dir("vendor/rdma-core/")
.args(["build.sh"])
.status()
.expect("Failed to build vendor/rdma-core using build.sh");
eprintln!("run cmake");
let built_in = cmake::Config::new("vendor/rdma-core")
.define("IN_PLACE", "1")
.define("NO_MAN_PAGES", "1")
.no_build_target(true)
.build();
let built_in = built_in
.to_str()
.expect("build directory path is not valid UTF-8");

// generate the bindings
eprintln!("run bindgen");
let bindings = bindgen::Builder::default()
.header("vendor/rdma-core/libibverbs/verbs.h")
.clang_arg("-Ivendor/rdma-core/build/include/")
.clang_arg(format!("-I{built_in}/include/"))
.allowlist_function("ibv_.*")
.allowlist_type("ibv_.*")
.bitfield_enum("ibv_access_flags")
Expand Down

0 comments on commit ef41036

Please sign in to comment.