shaderc-dyn-rs
==============
Rust bindings for the [shaderc][shaderc] library.
> **Note:** This is a fork of [google/shaderc-rs](https://github.com/google/shaderc-rs) that
> loads the shaderc shared library at runtime using `libloading`, instead of statically
> linking or building from source at compile time. A pre-built `libshaderc_shared` shared library is required to be available at runtime.
> Pls ping me if the fork is outdated.
Usage
-----
First add to your `Cargo.toml`:
```toml
[dependencies]
shaderc-dyn = "0.10"
```
Then add to your crate root:
```rust
extern crate shaderc_dyn;
```
Documentation
-------------
shaderc-dyn provides the [`Compiler`][doc-compiler] interface to compile GLSL/HLSL
source code into SPIR-V binary modules or assembly code. It can also assemble
SPIR-V assembly into binary module. Default compilation behavior can be
adjusted using [`CompileOptions`][doc-options]. Successful results are kept in
[`CompilationArtifact`][doc-artifact]s.
Example
-------
Compile a shader into SPIR-V binary module and assembly text:
```rust
use shaderc_dyn;
let source = "#version 310 es\n void EP() {}";
let mut compiler = shaderc_dyn::Compiler::new().unwrap();
let mut options = shaderc_dyn::CompileOptions::new().unwrap();
options.add_macro_definition("EP", Some("main"));
let binary_result = compiler.compile_into_spirv(
source, shaderc_dyn::ShaderKind::Vertex,
"shader.glsl", "main", Some(&options)).unwrap();
assert_eq!(Some(&0x07230203), binary_result.as_binary().first());
let text_result = compiler.compile_into_spirv_assembly(
source, shaderc_dyn::ShaderKind::Vertex,
"shader.glsl", "main", Some(&options)).unwrap();
assert!(text_result.as_text().starts_with("; SPIR-V\n"));
```
Setup
-----
This fork requires a pre-built **shaderc shared library** to be installed and
available on the system library search path at runtime.
### Required shared library
| Windows | `shaderc_shared.dll` |
| macOS | `libshaderc_shared.dylib` |
| Linux | `libshaderc_shared.so` |
### Environment variable
Set `SHADERC_LIB_PATH` to the full path of the shared library to override
automatic search:
```sh
export SHADERC_LIB_PATH=/path/to/libshaderc_shared.dylib
```
### Installation
The shared library is included in the [Vulkan SDK](https://www.lunarg.com/vulkan-sdk/)
or can be installed via package managers:
- **macOS** (Homebrew): `brew install shaderc`
- **Ubuntu/Debian**: `sudo apt install libshaderc-dev`
- **Arch Linux**: `pacman -S shaderc`
- **Windows**: Install the [Vulkan SDK](https://www.lunarg.com/vulkan-sdk/) and
ensure the SDK's `Bin` directory is on `PATH`
Contributions
-------------
This project is licensed under the [Apache 2](LICENSE) license. Please see
[CONTRIBUTING](CONTRIBUTING.md) before contributing.
### Authors
This project is initialized and mainly developed by Lei Zhang
([@antiagainst][me]).
[shaderc]: https://github.com/google/shaderc
[doc-compiler]: https://docs.rs/shaderc/0.7/shaderc/struct.Compiler.html
[doc-options]: https://docs.rs/shaderc/0.7/shaderc/struct.CompileOptions.html
[doc-artifact]: https://docs.rs/shaderc/0.7/shaderc/struct.CompilationArtifact.html
[me]: https://github.com/antiagainst