panicbit 7 years ago
commit
1830bca8c4
  1. 4
      .gitignore
  2. 8
      Cargo.toml
  3. 24
      README.md
  4. 35
      src/lib.rs

4
.gitignore vendored

@ -0,0 +1,4 @@ @@ -0,0 +1,4 @@
/target/
**/*.rs.bk
Cargo.lock

8
Cargo.toml

@ -0,0 +1,8 @@ @@ -0,0 +1,8 @@
[package]
authors = ["panicbit <panicbit.dev@gmail.com>"]
name = "picasso"
version = "0.1.0"
[dependencies]
failure = { git = "https://github.com/withoutboats/failure" }
failure_derive = { git = "https://github.com/withoutboats/failure_derive" }

24
README.md

@ -0,0 +1,24 @@ @@ -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"));
```

35
src/lib.rs

@ -0,0 +1,35 @@ @@ -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<I, O>(source_paths: &[I], out_path: O) -> Result<()> where
I: AsRef<OsStr>,
O: AsRef<OsStr>,
{
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<T> = ::std::result::Result<T, Error>;
#[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),
}
Loading…
Cancel
Save