shaderc_sys/
lib.rs

1// Copyright 2016 Google Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//      http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Shaderc system library FFI, building, and linking
16//!
17//! This crate contains the lower-level C interface for the Shaderc library.
18//! For the higher-level Rust-friendly interface, please see the
19//! [shaderc](https://docs.rs/shaderc) crate.
20//!
21//! The [Shaderc](https://github.com/google/shaderc) library provides an API
22//! for compiling GLSL/HLSL source code to SPIRV modules. It has been shipping
23//! in the Android NDK since version r12b.
24//!
25//! This crate contains Rust FFI inteface to the Shaderc library. It also
26//! handles system library detection and building from source if no system
27//! library installed via `build.rs`.
28//!
29//! The order of preference in which the build script will attempt to obtain
30//! Shaderc can be controlled by several options:
31//!
32//! 1. The option `--features build-from-source` will prevent automatic library
33//!    detection and force building from source.
34//! 2. If the `SHADERC_LIB_DIR` environment variable is set to
35//!    `/path/to/shaderc/libs/`, it will take precedence and
36//!    `libshaderc_combined.a` (and the glslang and SPIRV libraries on Linux)
37//!    will be searched in the `/path/to/shaderc/libs/` directory.
38//! 3. On Linux, `/usr/lib/` will be automatically searched for system libraries
39//!    if none of the above were given.
40//! 4. If no other option was set or succeeded, shaderc-sys will fall back to
41//!    checking out and compiling a copy of Shaderc.  This procedure is quite
42//!    slow.
43//!
44//! The build script also tries to check whether [Ninja](https://ninja-build.org/)
45//! is available on `PATH`. Ninja is required to build with Visual Studio because
46//! MSBuild does not support paths longer than MAX_PATH. On other platforms,
47//! Ninja is optional but is generally faster than the default build tool.
48
49#![allow(non_camel_case_types)]
50
51extern crate libc;
52use libc::{c_char, c_int, c_void, size_t};
53
54pub enum ShadercCompiler {}
55pub enum ShadercCompileOptions {}
56pub enum ShadercCompilationResult {}
57
58#[repr(C)]
59pub struct shaderc_include_result {
60    pub source_name: *const c_char,
61    pub source_name_length: size_t,
62    pub content: *const c_char,
63    pub content_length: size_t,
64    pub user_data: *mut c_void,
65}
66
67type shaderc_include_resolve_fn = extern "C" fn(
68    user_data: *mut c_void,
69    requested_source: *const c_char,
70    type_: c_int,
71    requesting_source: *const c_char,
72    include_depth: size_t,
73) -> *mut shaderc_include_result;
74
75type shaderc_include_result_release_fn =
76    extern "C" fn(user_data: *mut c_void, include_result: *mut shaderc_include_result);
77
78extern "C" {
79    pub fn shaderc_compiler_initialize() -> *mut ShadercCompiler;
80    pub fn shaderc_compiler_release(compiler: *mut ShadercCompiler);
81
82    pub fn shaderc_compile_into_spv(
83        compiler: *const ShadercCompiler,
84        source_text: *const c_char,
85        source_size: size_t,
86        shader_kind: i32,
87        input_file_name: *const c_char,
88        entry_point_name: *const c_char,
89        additional_options: *const ShadercCompileOptions,
90    ) -> *mut ShadercCompilationResult;
91    pub fn shaderc_compile_into_spv_assembly(
92        compiler: *const ShadercCompiler,
93        source_text: *const c_char,
94        source_size: size_t,
95        shader_kind: i32,
96        input_file_name: *const c_char,
97        entry_point_name: *const c_char,
98        additional_options: *const ShadercCompileOptions,
99    ) -> *mut ShadercCompilationResult;
100    pub fn shaderc_compile_into_preprocessed_text(
101        compiler: *const ShadercCompiler,
102        source_text: *const c_char,
103        source_size: size_t,
104        shader_kind: i32,
105        input_file_name: *const c_char,
106        entry_point_name: *const c_char,
107        additional_options: *const ShadercCompileOptions,
108    ) -> *mut ShadercCompilationResult;
109    pub fn shaderc_assemble_into_spv(
110        compiler: *const ShadercCompiler,
111        source_assembly: *const c_char,
112        source_size: size_t,
113        additional_options: *const ShadercCompileOptions,
114    ) -> *mut ShadercCompilationResult;
115
116    pub fn shaderc_compile_options_initialize() -> *mut ShadercCompileOptions;
117    pub fn shaderc_compile_options_clone(
118        options: *const ShadercCompileOptions,
119    ) -> *mut ShadercCompileOptions;
120    pub fn shaderc_compile_options_release(options: *mut ShadercCompileOptions);
121
122    pub fn shaderc_compile_options_add_macro_definition(
123        options: *mut ShadercCompileOptions,
124        name: *const c_char,
125        name_length: size_t,
126        value: *const c_char,
127        vaule_length: size_t,
128    );
129    pub fn shaderc_compile_options_set_source_language(
130        options: *mut ShadercCompileOptions,
131        language: i32,
132    );
133    pub fn shaderc_compile_options_set_generate_debug_info(options: *mut ShadercCompileOptions);
134    pub fn shaderc_compile_options_set_optimization_level(
135        options: *mut ShadercCompileOptions,
136        level: i32,
137    );
138    pub fn shaderc_compile_options_set_forced_version_profile(
139        options: *mut ShadercCompileOptions,
140        version: c_int,
141        profile: i32,
142    );
143    pub fn shaderc_compile_options_set_include_callbacks(
144        options: *mut ShadercCompileOptions,
145        resolver: shaderc_include_resolve_fn,
146        result_releaser: shaderc_include_result_release_fn,
147        user_data: *mut c_void,
148    );
149    pub fn shaderc_compile_options_set_suppress_warnings(options: *mut ShadercCompileOptions);
150    pub fn shaderc_compile_options_set_warnings_as_errors(options: *mut ShadercCompileOptions);
151    pub fn shaderc_compile_options_set_target_env(
152        options: *mut ShadercCompileOptions,
153        env: i32,
154        version: u32,
155    );
156    pub fn shaderc_compile_options_set_target_spirv(
157        options: *mut ShadercCompileOptions,
158        version: i32,
159    );
160    pub fn shaderc_compile_options_set_limit(
161        options: *mut ShadercCompileOptions,
162        limit: i32,
163        value: c_int,
164    );
165    pub fn shaderc_compile_options_set_auto_bind_uniforms(
166        options: *mut ShadercCompileOptions,
167        auto_bind: bool,
168    );
169    pub fn shaderc_compile_options_set_auto_combined_image_sampler(
170        options: *mut ShadercCompileOptions,
171        auto_combine: bool,
172    );
173    pub fn shaderc_compile_options_set_hlsl_io_mapping(
174        options: *mut ShadercCompileOptions,
175        hlsl_iomap: bool,
176    );
177    pub fn shaderc_compile_options_set_hlsl_offsets(
178        options: *mut ShadercCompileOptions,
179        hlsl_offsets: bool,
180    );
181    pub fn shaderc_compile_options_set_binding_base(
182        options: *mut ShadercCompileOptions,
183        resource_kind: c_int,
184        base: u32,
185    );
186    pub fn shaderc_compile_options_set_binding_base_for_stage(
187        options: *mut ShadercCompileOptions,
188        shader_kind: c_int,
189        resource_kind: c_int,
190        base: u32,
191    );
192    pub fn shaderc_compile_options_set_hlsl_register_set_and_binding(
193        options: *mut ShadercCompileOptions,
194        register: *const c_char,
195        set: *const c_char,
196        binding: *const c_char,
197    );
198    pub fn shaderc_compile_options_set_auto_map_locations(
199        options: *mut ShadercCompileOptions,
200        auto_map: bool,
201    );
202    pub fn shaderc_compile_options_set_hlsl_register_set_and_binding_for_stage(
203        options: *mut ShadercCompileOptions,
204        shader_kind: c_int,
205        register: *const c_char,
206        set: *const c_char,
207        binding: *const c_char,
208    );
209    pub fn shaderc_compile_options_set_hlsl_functionality1(
210        options: *mut ShadercCompileOptions,
211        enable: bool,
212    );
213    pub fn shaderc_compile_options_set_invert_y(options: *mut ShadercCompileOptions, enable: bool);
214    pub fn shaderc_compile_options_set_nan_clamp(options: *mut ShadercCompileOptions, enable: bool);
215
216    pub fn shaderc_result_release(result: *mut ShadercCompilationResult);
217    pub fn shaderc_result_get_compilation_status(result: *const ShadercCompilationResult) -> i32;
218    pub fn shaderc_result_get_num_errors(result: *const ShadercCompilationResult) -> size_t;
219    pub fn shaderc_result_get_num_warnings(result: *const ShadercCompilationResult) -> size_t;
220    pub fn shaderc_result_get_error_message(
221        result: *const ShadercCompilationResult,
222    ) -> *const c_char;
223    pub fn shaderc_result_get_length(result: *const ShadercCompilationResult) -> size_t;
224    pub fn shaderc_result_get_bytes(result: *const ShadercCompilationResult) -> *const c_char;
225
226    pub fn shaderc_get_spv_version(version: *mut c_int, revision: *mut c_int);
227    pub fn shaderc_parse_version_profile(
228        str: *const c_char,
229        version: *mut c_int,
230        profile: *mut i32,
231    ) -> bool;
232}