1#[cfg(target_arch = "wasm32")]
2macro_rules! check {
3 ($check:expr) => {{
4 $check
5 }};
6}
7
8#[cfg(not(target_arch = "wasm32"))]
9macro_rules! check {
10 ($check:expr) => {{
11 let result = $check;
12 if br::ScInternalResult::Success != result {
13 if br::ScInternalResult::CompilationError == result {
14 let mut message_ptr = ptr::null();
15
16 if br::ScInternalResult::Success
17 != br::sc_internal_get_latest_exception_message(&mut message_ptr)
18 {
19 return Err(ErrorCode::Unhandled);
20 }
21
22 let message = match std::ffi::CStr::from_ptr(message_ptr)
23 .to_owned()
24 .into_string()
25 {
26 Err(_) => return Err(ErrorCode::Unhandled),
27 Ok(v) => v,
28 };
29
30 if br::ScInternalResult::Success
31 != br::sc_internal_free_pointer(message_ptr as *mut std::os::raw::c_void)
32 {
33 return Err(ErrorCode::Unhandled);
34 }
35
36 return Err(ErrorCode::CompilationError(message));
37 }
38
39 return Err(ErrorCode::Unhandled);
40 }
41 }};
42}
43
44mod compiler;
45
46#[cfg(feature = "glsl")]
47pub mod glsl;
48#[cfg(all(feature = "hlsl", not(target_arch = "wasm32")))]
49pub mod hlsl;
50#[cfg(all(feature = "msl", not(target_arch = "wasm32")))]
51pub mod msl;
52
53pub mod spirv;
54
55#[cfg(target_arch = "wasm32")]
56pub(crate) mod emscripten;
57pub(crate) mod ptr_util;
58
59#[cfg(target_arch = "wasm32")]
60mod bindings_wasm_functions;
61
62#[cfg(target_arch = "wasm32")]
63mod bindings {
64 #![allow(dead_code)]
65 #![allow(non_upper_case_globals)]
66 #![allow(non_camel_case_types)]
67 #![allow(non_snake_case)]
68 include!(concat!("bindings_wasm.rs"));
69 pub use crate::bindings_wasm_functions::*;
70 pub use root::*;
71}
72
73#[cfg(not(target_arch = "wasm32"))]
74mod bindings {
75 #![allow(dead_code)]
76 #![allow(non_upper_case_globals)]
77 #![allow(non_camel_case_types)]
78 #![allow(non_snake_case)]
79 include!(concat!("bindings_native.rs"));
80 pub use root::*;
81}
82
83#[derive(Clone, Debug, Hash, Eq, PartialEq)]
84pub enum ErrorCode {
85 Unhandled,
86 CompilationError(String),
87}
88
89impl std::fmt::Display for ErrorCode {
90 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
91 write!(f, "{:?}", self)
92 }
93}
94
95impl std::error::Error for ErrorCode {}