Skip to content
This repository was archived by the owner on Mar 29, 2025. It is now read-only.
Closed
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
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ version: 2
name: Install Rust
command: |
apt update
apt install -y curl
apt install -y curl clang libclang-dev
curl https://sh.rustup.rs -sSf | sh -s -- -y
- run:
<<: *cargo
Expand All @@ -24,7 +24,7 @@ version: 2
- run:
name: Install Rust
command: |
yum install -y curl
yum install -y curl clang-devel clang
curl https://sh.rustup.rs -sSf | sh -s -- -y
- run:
<<: *cargo
Expand Down
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ keywords = ["GPGPU", "CUDA", "ffi"]
license = "MIT"
readme = "README.md"
categories = []

[build-dependencies]
bindgen = "~0.43"
97 changes: 97 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
extern crate bindgen;

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

fn find_library_paths() -> Vec<String> {
match env::var("CUDA_LIBRARY_PATH") {
Expand All @@ -12,6 +15,100 @@ fn find_library_paths() -> Vec<String> {
}

fn main() {
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());

bindgen::builder()
.header("wrapper/cuda.h")
.whitelist_recursively(false)
.whitelist_type("^CU.*")
.whitelist_type("^cuuint(32|64)_t")
.whitelist_type("^cudaError_enum")
.whitelist_type("^cudaMem.*")
.whitelist_var("^CU.*")
.whitelist_function("^CU.*")
.whitelist_function("^cu.*")
.default_enum_style(bindgen::EnumVariation::Rust)
.generate()
.expect("Unable to generate CUDA bindings")
.write_to_file(out_path.join("cuda_bindings.rs"))
.expect("Unable to write CUDA bindings");

bindgen::builder()
.header("wrapper/cublas.h")
.whitelist_recursively(false)
.whitelist_type("^cublas.*")
.whitelist_var("^cublas.*")
.whitelist_function("^cublas.*")
.default_enum_style(bindgen::EnumVariation::Rust)
.generate()
.expect("Unable to generate CUBLAS bindings")
.write_to_file(out_path.join("cublas_bindings.rs"))
.expect("Unable to write CUBLAS bindings");

bindgen::builder()
.header("wrapper/cucomplex.h")
.whitelist_recursively(false)
.whitelist_type("^cu.*Complex$")
.default_enum_style(bindgen::EnumVariation::Rust)
.generate()
.expect("Unable to generate CUComplex bindings")
.write_to_file(out_path.join("cucomplex_bindings.rs"))
.expect("Unable to write CUComplex bindings");

bindgen::builder()
.header("wrapper/cudart.h")
.whitelist_recursively(false)
.whitelist_type("^cuda.*")
.whitelist_type("^surfaceReference")
.whitelist_type("^textureReference")
.whitelist_var("^cuda.*")
.whitelist_function("^cuda.*")
.default_enum_style(bindgen::EnumVariation::Rust)
.generate()
.expect("Unable to generate CUDA RT bindings")
.write_to_file(out_path.join("cudart_bindings.rs"))
.expect("Unable to write CUDA RT bindings");

bindgen::builder()
.header("wrapper/driver_types.h")
.whitelist_recursively(false)
.whitelist_type("^CU.*")
.whitelist_type("^cuda.*")
.default_enum_style(bindgen::EnumVariation::Rust)
.generate()
.expect("Unable to generate driver types bindings")
.write_to_file(out_path.join("driver_types_bindings.rs"))
.expect("Unable to write driver types bindings");

bindgen::builder()
.header("wrapper/library_types.h")
.whitelist_recursively(false)
.whitelist_type("^cuda.*")
.whitelist_type("^libraryPropertyType.*")
.default_enum_style(bindgen::EnumVariation::Rust)
.generate()
.expect("Unable to generate library types bindings")
.write_to_file(out_path.join("library_types_bindings.rs"))
.expect("Unable to write library types bindings");

bindgen::builder()
.header("wrapper/vector_types.h")
// .whitelist_recursively(false)
.whitelist_type("^u?char[0-9]$")
.whitelist_type("^dim[0-9]$")
.whitelist_type("^double[0-9]$")
.whitelist_type("^float[0-9]$")
.whitelist_type("^u?int[0-9]$")
.whitelist_type("^u?long[0-9]$")
.whitelist_type("^u?longlong[0-9]$")
.whitelist_type("^u?short[0-9]$")
.default_enum_style(bindgen::EnumVariation::Rust)
.derive_copy(true)
.generate()
.expect("Unable to generate vector types bindings")
.write_to_file(out_path.join("vector_types_bindings.rs"))
.expect("Unable to write vector types bindings");

for p in find_library_paths() {
println!("cargo:rustc-link-search=native={}", p);
}
Expand Down
Loading