main()1 fn main() {
2     // Prevent building SPIRV-Cross on wasm32 target
3     let target_arch = std::env::var("CARGO_CFG_TARGET_ARCH");
4     if let Ok(arch) = target_arch {
5         if "wasm32" == arch {
6             return;
7         }
8     }
9 
10     let target_vendor = std::env::var("CARGO_CFG_TARGET_VENDOR");
11     let is_apple = target_vendor.is_ok() && target_vendor.unwrap() == "apple";
12 
13     let target_os = std::env::var("CARGO_CFG_TARGET_OS");
14     let is_ios = target_os.is_ok() && target_os.unwrap() == "ios";
15 
16     let mut build = cc::Build::new();
17     build.cpp(true);
18 
19     let compiler = build.try_get_compiler();
20     let is_clang = compiler.is_ok() && compiler.unwrap().is_like_clang();
21 
22     if is_apple && (is_clang || is_ios) {
23         build.flag("-std=c++14").cpp_set_stdlib("c++");
24     } else {
25         build.flag_if_supported("-std=c++14");
26     }
27 
28     build
29         .flag("-DSPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS")
30         .flag("-DSPIRV_CROSS_WRAPPER_NO_EXCEPTIONS");
31 
32     build
33         .file("src/wrapper.cpp")
34         .file("src/vendor/SPIRV-Cross/spirv_cfg.cpp")
35         .file("src/vendor/SPIRV-Cross/spirv_cross.cpp")
36         .file("src/vendor/SPIRV-Cross/spirv_cross_parsed_ir.cpp")
37         .file("src/vendor/SPIRV-Cross/spirv_parser.cpp")
38         .file("src/vendor/SPIRV-Cross/spirv_cross_util.cpp");
39 
40     // Ideally the GLSL compiler would be omitted here, but the HLSL and MSL compiler
41     // currently inherit from it. So it's necessary to unconditionally include it here.
42     build
43         .file("src/vendor/SPIRV-Cross/spirv_glsl.cpp")
44         .flag("-DSPIRV_CROSS_WRAPPER_GLSL");
45 
46     #[cfg(feature = "hlsl")]
47     build
48         .file("src/vendor/SPIRV-Cross/spirv_hlsl.cpp")
49         .flag("-DSPIRV_CROSS_WRAPPER_HLSL");
50 
51     #[cfg(feature = "msl")]
52     build
53         .file("src/vendor/SPIRV-Cross/spirv_msl.cpp")
54         .flag("-DSPIRV_CROSS_WRAPPER_MSL");
55 
56     build.compile("spirv-cross-rust-wrapper");
57 }
58