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;
52extern crate link_cplusplus;
53use libc::{c_char, c_int, c_void, size_t};
54
55pub enum ShadercCompiler {}
56pub enum ShadercCompileOptions {}
57pub enum ShadercCompilationResult {}
58
59#[repr(C)]
60pub struct shaderc_include_result {
61    pub source_name: *const c_char,
62    pub source_name_length: size_t,
63    pub content: *const c_char,
64    pub content_length: size_t,
65    pub user_data: *mut c_void,
66}
67
68type shaderc_include_resolve_fn = extern "C" fn(
69    user_data: *mut c_void,
70    requested_source: *const c_char,
71    type_: c_int,
72    requesting_source: *const c_char,
73    include_depth: size_t,
74) -> *mut shaderc_include_result;
75
76type shaderc_include_result_release_fn =
77    extern "C" fn(user_data: *mut c_void, include_result: *mut shaderc_include_result);
78
79extern "C" {
80    pub fn shaderc_compiler_initialize() -> *mut ShadercCompiler;
81    pub fn shaderc_compiler_release(compiler: *mut ShadercCompiler);
82
83    pub fn shaderc_compile_into_spv(
84        compiler: *const ShadercCompiler,
85        source_text: *const c_char,
86        source_size: size_t,
87        shader_kind: i32,
88        input_file_name: *const c_char,
89        entry_point_name: *const c_char,
90        additional_options: *const ShadercCompileOptions,
91    ) -> *mut ShadercCompilationResult;
92    pub fn shaderc_compile_into_spv_assembly(
93        compiler: *const ShadercCompiler,
94        source_text: *const c_char,
95        source_size: size_t,
96        shader_kind: i32,
97        input_file_name: *const c_char,
98        entry_point_name: *const c_char,
99        additional_options: *const ShadercCompileOptions,
100    ) -> *mut ShadercCompilationResult;
101    pub fn shaderc_compile_into_preprocessed_text(
102        compiler: *const ShadercCompiler,
103        source_text: *const c_char,
104        source_size: size_t,
105        shader_kind: i32,
106        input_file_name: *const c_char,
107        entry_point_name: *const c_char,
108        additional_options: *const ShadercCompileOptions,
109    ) -> *mut ShadercCompilationResult;
110    pub fn shaderc_assemble_into_spv(
111        compiler: *const ShadercCompiler,
112        source_assembly: *const c_char,
113        source_size: size_t,
114        additional_options: *const ShadercCompileOptions,
115    ) -> *mut ShadercCompilationResult;
116
117    pub fn shaderc_compile_options_initialize() -> *mut ShadercCompileOptions;
118    pub fn shaderc_compile_options_clone(
119        options: *const ShadercCompileOptions,
120    ) -> *mut ShadercCompileOptions;
121    pub fn shaderc_compile_options_release(options: *mut ShadercCompileOptions);
122
123    pub fn shaderc_compile_options_add_macro_definition(
124        options: *mut ShadercCompileOptions,
125        name: *const c_char,
126        name_length: size_t,
127        value: *const c_char,
128        vaule_length: size_t,
129    );
130    pub fn shaderc_compile_options_set_source_language(
131        options: *mut ShadercCompileOptions,
132        language: i32,
133    );
134    pub fn shaderc_compile_options_set_generate_debug_info(options: *mut ShadercCompileOptions);
135    pub fn shaderc_compile_options_set_optimization_level(
136        options: *mut ShadercCompileOptions,
137        level: i32,
138    );
139    pub fn shaderc_compile_options_set_forced_version_profile(
140        options: *mut ShadercCompileOptions,
141        version: c_int,
142        profile: i32,
143    );
144    pub fn shaderc_compile_options_set_include_callbacks(
145        options: *mut ShadercCompileOptions,
146        resolver: shaderc_include_resolve_fn,
147        result_releaser: shaderc_include_result_release_fn,
148        user_data: *mut c_void,
149    );
150    pub fn shaderc_compile_options_set_suppress_warnings(options: *mut ShadercCompileOptions);
151    pub fn shaderc_compile_options_set_warnings_as_errors(options: *mut ShadercCompileOptions);
152    pub fn shaderc_compile_options_set_target_env(
153        options: *mut ShadercCompileOptions,
154        env: i32,
155        version: u32,
156    );
157    pub fn shaderc_compile_options_set_target_spirv(
158        options: *mut ShadercCompileOptions,
159        version: i32,
160    );
161    pub fn shaderc_compile_options_set_limit(
162        options: *mut ShadercCompileOptions,
163        limit: i32,
164        value: c_int,
165    );
166    pub fn shaderc_compile_options_set_auto_bind_uniforms(
167        options: *mut ShadercCompileOptions,
168        auto_bind: bool,
169    );
170    pub fn shaderc_compile_options_set_auto_combined_image_sampler(
171        options: *mut ShadercCompileOptions,
172        auto_combine: bool,
173    );
174    pub fn shaderc_compile_options_set_hlsl_io_mapping(
175        options: *mut ShadercCompileOptions,
176        hlsl_iomap: bool,
177    );
178    pub fn shaderc_compile_options_set_hlsl_offsets(
179        options: *mut ShadercCompileOptions,
180        hlsl_offsets: bool,
181    );
182    pub fn shaderc_compile_options_set_binding_base(
183        options: *mut ShadercCompileOptions,
184        resource_kind: c_int,
185        base: u32,
186    );
187    pub fn shaderc_compile_options_set_binding_base_for_stage(
188        options: *mut ShadercCompileOptions,
189        shader_kind: c_int,
190        resource_kind: c_int,
191        base: u32,
192    );
193    pub fn shaderc_compile_options_set_hlsl_register_set_and_binding(
194        options: *mut ShadercCompileOptions,
195        register: *const c_char,
196        set: *const c_char,
197        binding: *const c_char,
198    );
199    pub fn shaderc_compile_options_set_auto_map_locations(
200        options: *mut ShadercCompileOptions,
201        auto_map: bool,
202    );
203    pub fn shaderc_compile_options_set_hlsl_register_set_and_binding_for_stage(
204        options: *mut ShadercCompileOptions,
205        shader_kind: c_int,
206        register: *const c_char,
207        set: *const c_char,
208        binding: *const c_char,
209    );
210    pub fn shaderc_compile_options_set_hlsl_functionality1(
211        options: *mut ShadercCompileOptions,
212        enable: bool,
213    );
214    pub fn shaderc_compile_options_set_invert_y(options: *mut ShadercCompileOptions, enable: bool);
215    pub fn shaderc_compile_options_set_nan_clamp(options: *mut ShadercCompileOptions, enable: bool);
216
217    pub fn shaderc_result_release(result: *mut ShadercCompilationResult);
218    pub fn shaderc_result_get_compilation_status(result: *const ShadercCompilationResult) -> i32;
219    pub fn shaderc_result_get_num_errors(result: *const ShadercCompilationResult) -> size_t;
220    pub fn shaderc_result_get_num_warnings(result: *const ShadercCompilationResult) -> size_t;
221    pub fn shaderc_result_get_error_message(
222        result: *const ShadercCompilationResult,
223    ) -> *const c_char;
224    pub fn shaderc_result_get_length(result: *const ShadercCompilationResult) -> size_t;
225    pub fn shaderc_result_get_bytes(result: *const ShadercCompilationResult) -> *const c_char;
226
227    pub fn shaderc_get_spv_version(version: *mut c_int, revision: *mut c_int);
228    pub fn shaderc_parse_version_profile(
229        str: *const c_char,
230        version: *mut c_int,
231        profile: *mut i32,
232    ) -> bool;
233}