ptx-builder 0.2.1

NVPTX build helper
Documentation

Rust PTX Builder

Build Status Current Version

Purpose

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.

Features

  1. Obviously, device crates building.
  2. Announcing device crates sources to cargo, so it can automatically rebuild after changes.
  3. 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'.

Prerequirements

The library depends on ptx-linker and xargo. Both can be installed from crates.io:

cargo install xargo
cargo install ptx-linker

Usage

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.2"

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 output = Builder::new("device/crate/path")?.build()?;

    // 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());
    }

    Ok(())
}