14 releases

0.3.9 Sep 7, 2018
0.3.7 Jul 14, 2018
0.3.6 Mar 30, 2018
0.3.3 Dec 1, 2017
0.2.0 Feb 7, 2017

#14 in Rendering

Download history 81/week @ 2018-06-15 20/week @ 2018-06-22 38/week @ 2018-06-29 96/week @ 2018-07-06 12/week @ 2018-07-13 60/week @ 2018-07-20 29/week @ 2018-07-27 131/week @ 2018-08-03 122/week @ 2018-08-10 21/week @ 2018-08-17 34/week @ 2018-08-24 17/week @ 2018-08-31 124/week @ 2018-09-07

261 downloads per month
Used in 2 crates


298K SLoC

C++ 244K SLoC // 0.1% comments GLSL 32K SLoC // 0.1% comments Python 12K SLoC // 0.1% comments Lua 3.5K SLoC // 0.0% comments Happy 3.5K SLoC Rust 1.5K SLoC // 0.2% comments Shell 600 SLoC // 0.5% comments Batch 121 SLoC // 0.6% comments C 30 SLoC // 0.3% comments Emacs Lisp 9 SLoC // 0.7% comments


Version Documentation Build Status Build status

Rust bindings for the shaderc library.


This is not an official Google product (experimental or otherwise), it is just code that happens to be owned by Google.


This library uses build.rs to automatically check out and compile a copy of native C++ shaderc and link to the generated artifacts, which requires git, cmake, and python existing in the PATH. To turn off this feature, specify --no-default-features when building. But then you will need to place a copy of the shaderc_combined library (on Windows) or the shaderc_shared library (on Linux and macOS) to a location that is scanned by the linker (e.g., the deps directory within the target directory).

First add to your Cargo.toml:

shaderc = "0.3"

Then add to your crate root:

extern crate shaderc;


shaderc provides the 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. Successful results are kept in CompilationArtifacts.

Please see Documentation for detailed documentation.


Compile a shader into SPIR-V binary module and assembly text:

use shaderc;

let source = "#version 310 es\n void EP() {}";

let mut compiler = shaderc::Compiler::new().unwrap();
let mut options = shaderc::CompileOptions::new().unwrap();
options.add_macro_definition("EP", Some("main"));
let binary_result = compiler.compile_into_spirv(
    source, shaderc::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::ShaderKind::Vertex,
    "shader.glsl", "main", Some(&options)).unwrap();

assert!(text_result.as_text().starts_with("; SPIR-V\n"));


This project is licensed under the Apache 2 license. Please see CONTRIBUTING before contributing.


This project is initialized and mainly developed by Lei Zhang (@antiagainst).