hecate/
lib.rs

1#![allow(non_upper_case_globals)]
2#![allow(non_camel_case_types)]
3#![allow(non_snake_case)]
4
5pub use codegen::input_schema::CodeGenError;
6pub use codegen::input_schema::IndexMap;
7pub use codegen::input_schema::SchemaValidationError;
8#[cfg(target_family = "wasm")]
9use codegen::input_schema::InputSchema;
10use schemars::schema_for;
11pub mod codegen;
12#[cfg(all(feature = "js", not(target_arch = "wasm32")))]
13pub mod js;
14pub use codegen::BuildingBlock;
15pub use std::error::Error as StdError;
16#[cfg(target_family = "wasm")]
17use wasm_bindgen::prelude::*;
18
19pub use crate::codegen::input_schema::InputSchema;
20
21#[cfg(all(feature = "cpp", not(target_family = "wasm")))]
22include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
23
24// use derive_alias::derive_alias;
25//
26// derive_alias! {
27//     derive_schema => #[derive(Serialize, Deserialize, PartialEq, PartialOrd)]
28// }
29
30#[cfg(all(target_family = "wasm", feature = "cpp"))]
31unsafe extern "C" {
32    fn __wasm_call_ctors();
33}
34
35#[cfg(target_family = "wasm")]
36#[wasm_bindgen(start)]
37pub fn start() {
38    #[cfg(target_family = "wasm")]
39    unsafe {
40        __wasm_call_ctors();
41    }
42}
43
44pub fn format_err<E: StdError + Sync + Send + 'static>(err: E) -> String {
45    let err = anyhow::Error::from(err);
46    format!("Error: {err:?}")
47}
48
49pub fn input_schema_json_schema() -> String {
50    schema_for!(InputSchema).to_value().to_string()
51}
52
53#[cfg(target_family = "wasm")]
54#[wasm_bindgen]
55pub fn code_gen_from_yaml(schema_yaml: &str) -> Result<String, String> {
56    let schema = InputSchema::from_yaml(schema_yaml).map_err(format_err)?;
57    schema.generate_cpp_sources().map_err(format_err)
58}
59
60#[cfg(target_arch = "wasm32")]
61pub mod wasm_api {
62    use wasm_bindgen::prelude::*;
63
64    #[wasm_bindgen]
65    pub fn sum(a: i32, b: i32) -> i32 {
66        a + b
67    }
68}
69
70// derive_schema! {
71// pub enum Mesh {
72//
73// }
74// }
75//
76// derive_schema! {
77//     pub struct NumericalScheme {
78//
79//     }
80// }