18 releases

0.3.13 Jan 15, 2019
0.3.12 Nov 11, 2018
0.3.11 Oct 8, 2018
0.3.7 Jul 14, 2018
0.2.0 Feb 7, 2017

#33 in Graphics APIs

Download history 59/week @ 2018-10-27 114/week @ 2018-11-03 185/week @ 2018-11-10 251/week @ 2018-11-17 204/week @ 2018-11-24 401/week @ 2018-12-01 238/week @ 2018-12-08 195/week @ 2018-12-15 180/week @ 2018-12-22 408/week @ 2018-12-29 256/week @ 2019-01-05 288/week @ 2019-01-12 412/week @ 2019-01-19

1,063 downloads per month
Used in 6 crates (4 directly)


334K SLoC

C++ 273K SLoC // 0.1% comments GLSL 34K SLoC // 0.1% comments Python 13K SLoC // 0.1% comments C# 4K SLoC // 0.0% comments Lua 3.5K SLoC // 0.0% comments Happy 3.5K SLoC Rust 1.5K SLoC // 0.2% comments D 1K SLoC // 0.0% comments Shell 612 SLoC // 0.5% comments Batch 127 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"));


To build the shaderc-rs crate, the following tools must be installed and available on PATH:

  • CMake
  • Python (works with both Python 2.x and 3.x)
  • a C++11 compiler

These requirements can be either installed with your favourite package manager or with installers from the projects' websites. Below are some example ways to get setup.

windows-msvc Example Setup

  1. rustup default stable-x86_64-pc-windows-msvc
  2. Install Build Tools for Visual Studio 2017. If you have already been using this toolchain then its probably already installed.
  3. Install msys2, following ALL of the instructions.
  4. Then in the msys2 terminal run: pacman --noconfirm -Syu mingw-w64-x86_64-cmake mingw-w64-x86_64-python3
  5. Add the msys2 mingw64 binary path to the PATH environment variable.

windows-gnu Example Setup

windows-gnu toolchain is not supported but you can instead cross-compile to windows-gnu from windows-msvc.

Steps 1 and 2 are to workaround https://github.com/rust-lang/rust/issues/49078 by using the same mingw that rust uses.

  1. Download and extract https://s3-us-west-1.amazonaws.com/rust-lang-ci2/rust-ci-mirror/x86_64-6.3.0-release-posix-seh-rt_v5-rev2.7z
  2. Add the absolute path to mingw64\bin to your PATH environment variable.
  3. Run the command: rustup default stable-x86_64-pc-windows-msvc
  4. Run the command: rustup target install x86_64-pc-windows-gnu
  5. Install Build Tools for Visual Studio 2017. If you have already been using this toolchain then its probably already installed.
  6. Install msys2, following ALL of the instructions.
  7. Then in the msys2 terminal run: pacman --noconfirm -Syu mingw-w64-x86_64-cmake mingw-w64-x86_64-make mingw-w64-x86_64-python3
  8. Add the msys2 mingw64 binary path to the PATH environment variable.
  9. Any cargo command that builds the project needs to include --target x86_64-pc-windows-gnu e.g. to run: cargo run --target x86_64-pc-windows-gnu

Linux Example Setup

Use your package manager to install the required dev-tools

For example on ubuntu:

sudo apt-get install build-essential git python cmake

macOS Example Setup

Assuming Homebrew:

brew install cmake


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).