The library should facilitate CUDA development with Rust. It can be used in a cargo build script of a host crate, and take responsibility for building device crates.
- Obviously, device crates building.
- Announcing device crates sources to cargo, so it can automatically rebuild after changes.
- Reporting about missing tools, for example:
[PTX] Unable to get target details
[PTX]
[PTX] caused by:
[PTX] Command not found in PATH: 'ptx-linker'. You can install it with: 'cargo install ptx-linker'.
The library depends on ptx-linker and xargo. Both can be installed from crates.io:
cargo install xargo
cargo install ptx-linker
First, you need to specify a build script in host crate's Cargo.toml
and declare the library as a build-dependency:
[package]
build = "build.rs"
[build-dependencies]
ptx-builder = "0.3"
Then, typical build.rs
might look like:
extern crate ptx_builder;
use std::process::exit;
use ptx_builder::prelude::*;
fn main() {
if let Err(error) = build() {
eprintln!("{}", BuildReporter::report(error));
exit(1);
}
}
fn build() -> Result<()> {
let status = Builder::new(".")?.build()?;
match status {
BuildStatus::Success(output) => {
// Provide the PTX Assembly location via env variable
println!(
"cargo:rustc-env=KERNEL_PTX_PATH={}",
output.get_assembly_path().to_str().unwrap()
);
// Observe changes in kernel sources
for path in output.source_files()? {
println!("cargo:rerun-if-changed={}", path.to_str().unwrap());
}
}
BuildStatus::NotNeeded => {
println!("cargo:rustc-env=KERNEL_PTX_PATH=/dev/null");
}
};
Ok(())
}