|
| 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