|
| 1 | +#[cfg(feature = "regenerate-bindings")] |
| 2 | +use std::path::PathBuf; |
| 3 | + |
| 4 | +fn main() { |
| 5 | + println!("cargo:rustc-link-lib=dylib=graphblas"); |
| 6 | + println!("cargo:rustc-link-search=native=/usr/local/lib"); |
| 7 | + println!("cargo:rustc-link-lib=dylib=lagraph"); |
| 8 | + println!("cargo:rustc-link-search=native=deps/LAGraph/build/src"); |
| 9 | + println!("cargo:rustc-link-lib=dylib=lagraphx"); |
| 10 | + println!("cargo:rustc-link-search=native=deps/LAGraph/build/experimental"); |
| 11 | + |
| 12 | + // ---- Bindgen (only with `regenerate-bindings` feature) ---- |
| 13 | + #[cfg(feature = "regenerate-bindings")] |
| 14 | + regenerate_bindings(); |
| 15 | + |
| 16 | + println!("cargo:rerun-if-changed=build.rs"); |
| 17 | +} |
| 18 | + |
| 19 | +#[cfg(feature = "regenerate-bindings")] |
| 20 | +fn regenerate_bindings() { |
| 21 | + let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")); |
| 22 | + |
| 23 | + let lagraph_include = manifest_dir.join("deps/LAGraph/include"); |
| 24 | + assert!( |
| 25 | + lagraph_include.join("LAGraph.h").exists(), |
| 26 | + "LAGraph.h not found at {}.\n\ |
| 27 | + Fetch the submodule:\n git submodule update --init --recursive", |
| 28 | + lagraph_include.display() |
| 29 | + ); |
| 30 | + |
| 31 | + let graphblas_include = [ |
| 32 | + PathBuf::from("/usr/local/include/suitesparse"), |
| 33 | + PathBuf::from("/usr/include/suitesparse"), |
| 34 | + ] |
| 35 | + .into_iter() |
| 36 | + .find(|p| p.join("GraphBLAS.h").exists()) |
| 37 | + .unwrap_or_else(|| { |
| 38 | + panic!( |
| 39 | + "GraphBLAS.h not found.\n\ |
| 40 | + Install SuiteSparse:GraphBLAS so headers are in /usr/local/include/suitesparse." |
| 41 | + ) |
| 42 | + }); |
| 43 | + |
| 44 | + let bindings = bindgen::Builder::default() |
| 45 | + .header( |
| 46 | + lagraph_include |
| 47 | + .join("LAGraph.h") |
| 48 | + .to_str() |
| 49 | + .expect("non-utf8 header path"), |
| 50 | + ) |
| 51 | + .header( |
| 52 | + lagraph_include |
| 53 | + .join("LAGraphX.h") |
| 54 | + .to_str() |
| 55 | + .expect("non-utf8 header path"), |
| 56 | + ) |
| 57 | + .clang_arg(format!("-I{}", graphblas_include.display())) |
| 58 | + .clang_arg(format!("-I{}", lagraph_include.display())) |
| 59 | + .allowlist_type("GrB_Index") |
| 60 | + .allowlist_type("GrB_Matrix") |
| 61 | + .allowlist_type("GrB_Vector") |
| 62 | + .allowlist_item("GrB_BOOL") |
| 63 | + .allowlist_item("GrB_LOR") |
| 64 | + .allowlist_item("GrB_LOR_LAND_SEMIRING_BOOL") |
| 65 | + .allowlist_item("GrB_Info") |
| 66 | + .allowlist_function("GrB_Matrix_new") |
| 67 | + .allowlist_function("GrB_Matrix_nvals") |
| 68 | + .allowlist_function("GrB_Matrix_free") |
| 69 | + .allowlist_function("GrB_Matrix_build_BOOL") |
| 70 | + .allowlist_function("GrB_Vector_new") |
| 71 | + .allowlist_function("GrB_Vector_free") |
| 72 | + .allowlist_function("GrB_Vector_setElement_BOOL") |
| 73 | + .allowlist_function("GrB_Vector_nvals") |
| 74 | + .allowlist_function("GrB_Vector_extractTuples_BOOL") |
| 75 | + .allowlist_function("GrB_vxm") |
| 76 | + .allowlist_type("LAGraph_Graph") |
| 77 | + .allowlist_type("LAGraph_Kind") |
| 78 | + .allowlist_function("LAGraph_Init") |
| 79 | + .allowlist_function("LAGraph_Finalize") |
| 80 | + .allowlist_function("LAGraph_New") |
| 81 | + .allowlist_function("LAGraph_Delete") |
| 82 | + .allowlist_function("LAGraph_Cached_AT") |
| 83 | + .allowlist_function("LAGraph_MMRead") |
| 84 | + .default_enum_style(bindgen::EnumVariation::Rust { |
| 85 | + non_exhaustive: false, |
| 86 | + }) |
| 87 | + .derive_debug(true) |
| 88 | + .derive_copy(true) |
| 89 | + .layout_tests(false) |
| 90 | + // Suppress C-language doc comments so rustdoc does not attempt to |
| 91 | + // compile them as Rust doctests. |
| 92 | + .generate_comments(false) |
| 93 | + .generate() |
| 94 | + .expect("bindgen failed to generate bindings"); |
| 95 | + |
| 96 | + bindings |
| 97 | + .write_to_file(manifest_dir.join("src/lagraph_sys_generated.rs")) |
| 98 | + .expect("failed to write bindgen output to src/lagraph_sys_generated.rs"); |
| 99 | +} |
0 commit comments