1 // Copyright 2016 The Shaderc Authors. All rights reserved. 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 #include "shaderc/shaderc.h" 16 #include <assert.h> 17 #include <string.h> 18 19 // Because we want to test this as a plain old C file, we cannot use 20 // gtest, so just run a simple smoke test. 21 22 int main() { 23 const char* test_program = 24 "#version 310 es\n" 25 "layout(location = 0) in highp vec4 vtxColor;\n" 26 "layout(location = 0) out highp vec4 outColor;\n" 27 "void main() {\n" 28 " outColor = vtxColor;" 29 "}\n"; 30 shaderc_compiler_t compiler; 31 shaderc_compilation_result_t result; 32 shaderc_compile_options_t options; 33 34 compiler = shaderc_compiler_initialize(); 35 options = shaderc_compile_options_initialize(); 36 shaderc_compile_options_add_macro_definition(options, "FOO", 3, "1", 1); 37 result = shaderc_compile_into_spv( 38 compiler, test_program, strlen(test_program), 39 shaderc_glsl_fragment_shader, "a.glsl", "main", options); 40 41 assert(result); 42 43 if (shaderc_result_get_compilation_status(result) != 44 shaderc_compilation_status_success) { 45 // Early exit on failure. 46 return -1; 47 } 48 shaderc_result_release(result); 49 shaderc_compile_options_release(options); 50 shaderc_compiler_release(compiler); 51 52 return 0; 53 } 54 55