include_str
Saw your blog post on HN. Cool stuff! Just wanted to point out you could replace this:
https://github.com/janiorca/sphere_dance/blob/b9c10f31701a540230a028a8499a7fd3c432df8d/src/shaders.rs#L1-L5
With something like:
pub static frag_shader_src : &'static str = include_str("../shader_code.h");
include_str! evauates at build time, and is part of core, so it should just work (tm). Just wanted to point this out before you write a PR for shader_minifier 👍. There's also include_bytes! if you want a u8 array instead, or include! if you want rust code.
~~From my testing include_str! requires you to have the final shader file alongside the executable so that is not a good option for standalone executables.~~
Above is correct, I think I must have had a different issue in my program at the time.
I suspect you've confused include_str! with std::fs::read_to_string. include_str does not require you keep the file:
C:\local\example>echo fn main() { println!("{}", include_str!("test.txt")); } > main.rs
C:\local\example>echo Hello, world! > test.txt
C:\local\example>rustc main.rs -o main.exe
C:\local\example>del test.txt
C:\local\example>type test.txt
The system cannot find the file specified.
C:\local\example>type main.rs
fn main() { println!("{}", include_str!("test.txt")); }
C:\local\example>main.exe
Hello, world!
You can also see the resulting string inlined into your executable:
("Hello, world! \r\n")
You are correct, updated my comment above to avoid confusion.