commit 1830bca8c4e3b551180608ae09173215fe2389be Author: panicbit Date: Tue Nov 14 22:35:59 2017 +0100 Init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..143b1ca --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ + +/target/ +**/*.rs.bk +Cargo.lock diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..07392f4 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,8 @@ +[package] +authors = ["panicbit "] +name = "picasso" +version = "0.1.0" + +[dependencies] +failure = { git = "https://github.com/withoutboats/failure" } +failure_derive = { git = "https://github.com/withoutboats/failure_derive" } diff --git a/README.md b/README.md new file mode 100644 index 0000000..43731d1 --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +This is a convenience wrapper around the `picasso` CLI +and is primarily intended to be used in build scripts. + +Here is an example `build.rs`: + +```rust +extern crate picasso; + +use std::env; +use std::path::PathBuf; + +fn main() { + let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); + + picasso::assemble(&["vshader.v.pica"], out_dir.join("vshader.v.shbin")) + .unwrap_or_else(|e| panic!("{}", e)); +} +``` + +To embed the assembled shaders in your binary you can do the following: + +```rust +static VSHADER_SHBIN: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/vshader.v.shbin")); +``` diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..47e1955 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,35 @@ +extern crate failure; +#[macro_use] extern crate failure_derive; + +use std::io; +use std::ffi::OsStr; +use std::process::Command; + +pub fn assemble(source_paths: &[I], out_path: O) -> Result<()> where + I: AsRef, + O: AsRef, +{ + let output = Command::new("picasso") + .arg("-o").arg(out_path) + .arg("--") + .args(source_paths) + .output() + .map_err(Error::Exec)?; + + if !output.status.success() { + let msg = String::from_utf8_lossy(&output.stderr).into_owned(); + return Err(Error::Msg(msg)); + } + + Ok(()) +} + +pub type Result = ::std::result::Result; + +#[derive(Debug,Fail)] +pub enum Error { + #[fail(display="Failed to run `picasso` ({})", _0)] + Exec(io::Error), + #[fail(display="`picasso` exited with errors:\n{}", _0)] + Msg(String), +}