Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework optix_stubs.c #174

Merged
merged 3 commits into from
Mar 21, 2025
Merged
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
17 changes: 2 additions & 15 deletions crates/optix/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use find_cuda_helper::{find_cuda_root, find_optix_root};
use std::env;
use std::path::{Path, PathBuf};

// OptiX is a bit exotic in how it provides its functions. It uses a function table
Expand All @@ -8,7 +7,6 @@ use std::path::{Path, PathBuf};
// OptiX provides this logic inside optix_stubs.h in the include dir, so we need to compile that
// to a lib and link it in so that we have the initialization and C function logic.
fn main() {
let out_dir = env::var("OUT_DIR").unwrap();
let mut optix_include = find_optix_root().expect(
"Unable to find the OptiX SDK, make sure you installed it and
that OPTIX_ROOT or OPTIX_ROOT_DIR are set",
Expand All @@ -23,32 +21,21 @@ fn main() {

bindgen_optix(&optix_include, &cuda_include);

println!("cargo:rerun-if-changed=optix_stubs.c");
cc::Build::new()
.file("./optix_stubs.c")
.include(optix_include)
.include(cuda_include)
.cpp(false)
.compile("optix_stubs");

println!("cargo:rustc-link-search=native={}", out_dir);
println!("cargo:rustc-link-lib=static=optix_stubs");
}

fn bindgen_optix(optix_include: &Path, cuda_include: &Path) {
let out_path = PathBuf::from(std::env::var("OUT_DIR").unwrap()).join("optix_wrapper.rs");

let header_path = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap())
.join("src")
.join("optix_wrapper.h");

let this_path =
std::path::PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap()).join("build.rs");

println!("cargo:rerun-if-changed={}", header_path.display());
println!("cargo:rerun-if-changed={}", this_path.display());

let bindings = bindgen::Builder::default()
.header("src/optix_wrapper.h")
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
.clang_arg(format!("-I{}", optix_include.display()))
.clang_arg(format!("-I{}", cuda_include.display()))
.allowlist_recursively(false)
Expand Down
Loading