Skip to main content

diffsol_c/
lib.rs

1#![cfg_attr(
2    not(any(
3        feature = "external",
4        feature = "diffsl-cranelift",
5        feature = "diffsl-llvm"
6    )),
7    allow(dead_code, unused_imports, unused_variables)
8)]
9
10// Configure dlmalloc as the global allocator for WASM targets
11// dlmalloc is a maintained alternative to the unmaintained wee_alloc
12#[cfg(target_arch = "wasm32")]
13use dlmalloc::GlobalDlmalloc;
14
15#[cfg(target_arch = "wasm32")]
16#[global_allocator]
17static ALLOCATOR: GlobalDlmalloc = GlobalDlmalloc;
18
19#[cfg(all(feature = "diffsl-llvm15", feature = "diffsl-llvm16"))]
20compile_error!("diffsol-c cannot enable more than one `diffsl-llvm*` feature.");
21#[cfg(all(feature = "diffsl-llvm15", feature = "diffsl-llvm17"))]
22compile_error!("diffsol-c cannot enable more than one `diffsl-llvm*` feature.");
23#[cfg(all(feature = "diffsl-llvm15", feature = "diffsl-llvm18"))]
24compile_error!("diffsol-c cannot enable more than one `diffsl-llvm*` feature.");
25#[cfg(all(feature = "diffsl-llvm15", feature = "diffsl-llvm19"))]
26compile_error!("diffsol-c cannot enable more than one `diffsl-llvm*` feature.");
27#[cfg(all(feature = "diffsl-llvm15", feature = "diffsl-llvm20"))]
28compile_error!("diffsol-c cannot enable more than one `diffsl-llvm*` feature.");
29#[cfg(all(feature = "diffsl-llvm15", feature = "diffsl-llvm21"))]
30compile_error!("diffsol-c cannot enable more than one `diffsl-llvm*` feature.");
31#[cfg(all(feature = "diffsl-llvm16", feature = "diffsl-llvm17"))]
32compile_error!("diffsol-c cannot enable more than one `diffsl-llvm*` feature.");
33#[cfg(all(feature = "diffsl-llvm16", feature = "diffsl-llvm18"))]
34compile_error!("diffsol-c cannot enable more than one `diffsl-llvm*` feature.");
35#[cfg(all(feature = "diffsl-llvm16", feature = "diffsl-llvm19"))]
36compile_error!("diffsol-c cannot enable more than one `diffsl-llvm*` feature.");
37#[cfg(all(feature = "diffsl-llvm16", feature = "diffsl-llvm20"))]
38compile_error!("diffsol-c cannot enable more than one `diffsl-llvm*` feature.");
39#[cfg(all(feature = "diffsl-llvm16", feature = "diffsl-llvm21"))]
40compile_error!("diffsol-c cannot enable more than one `diffsl-llvm*` feature.");
41#[cfg(all(feature = "diffsl-llvm17", feature = "diffsl-llvm18"))]
42compile_error!("diffsol-c cannot enable more than one `diffsl-llvm*` feature.");
43#[cfg(all(feature = "diffsl-llvm17", feature = "diffsl-llvm19"))]
44compile_error!("diffsol-c cannot enable more than one `diffsl-llvm*` feature.");
45#[cfg(all(feature = "diffsl-llvm17", feature = "diffsl-llvm20"))]
46compile_error!("diffsol-c cannot enable more than one `diffsl-llvm*` feature.");
47#[cfg(all(feature = "diffsl-llvm17", feature = "diffsl-llvm21"))]
48compile_error!("diffsol-c cannot enable more than one `diffsl-llvm*` feature.");
49#[cfg(all(feature = "diffsl-llvm18", feature = "diffsl-llvm19"))]
50compile_error!("diffsol-c cannot enable more than one `diffsl-llvm*` feature.");
51#[cfg(all(feature = "diffsl-llvm18", feature = "diffsl-llvm20"))]
52compile_error!("diffsol-c cannot enable more than one `diffsl-llvm*` feature.");
53#[cfg(all(feature = "diffsl-llvm18", feature = "diffsl-llvm21"))]
54compile_error!("diffsol-c cannot enable more than one `diffsl-llvm*` feature.");
55#[cfg(all(feature = "diffsl-llvm19", feature = "diffsl-llvm20"))]
56compile_error!("diffsol-c cannot enable more than one `diffsl-llvm*` feature.");
57#[cfg(all(feature = "diffsl-llvm19", feature = "diffsl-llvm21"))]
58compile_error!("diffsol-c cannot enable more than one `diffsl-llvm*` feature.");
59#[cfg(all(feature = "diffsl-llvm20", feature = "diffsl-llvm21"))]
60compile_error!("diffsol-c cannot enable more than one `diffsl-llvm*` feature.");
61
62pub mod c_api_utils;
63pub mod error;
64#[path = "error_c.rs"]
65pub mod error_c;
66pub mod host_array;
67#[path = "host_array_c.rs"]
68pub mod host_array_c;
69pub mod initial_condition_options;
70#[path = "initial_condition_options_c.rs"]
71pub mod initial_condition_options_c;
72pub mod jit;
73#[path = "jit_c.rs"]
74pub mod jit_c;
75pub mod linear_solver_type;
76#[path = "linear_solver_type_c.rs"]
77pub mod linear_solver_type_c;
78pub mod matrix_type;
79#[path = "matrix_type_c.rs"]
80pub mod matrix_type_c;
81pub mod ode;
82#[path = "ode_c.rs"]
83pub mod ode_c;
84pub mod ode_options;
85#[path = "ode_options_c.rs"]
86pub mod ode_options_c;
87pub mod ode_solver_type;
88#[path = "ode_solver_type_c.rs"]
89pub mod ode_solver_type_c;
90pub mod scalar_type;
91#[path = "scalar_type_c.rs"]
92pub mod scalar_type_c;
93pub mod solution;
94pub mod solution_wrapper;
95#[path = "solution_wrapper_c.rs"]
96pub mod solution_wrapper_c;
97pub mod solve;
98pub mod solve_macros;
99#[path = "string_c.rs"]
100pub mod string_c;
101pub mod utils;
102pub mod valid_linear_solver;
103
104#[cfg(test)]
105mod test_support;
106
107// dlmalloc already exports malloc/free, but we need to make sure they're available
108// The global allocator handles allocation, dlmalloc will provide the exports
109
110/// Core library functionality for diffsol-js
111/// This will be compiled to WASM and exposed via raw bindings
112pub mod solver {
113    /// Example solver function - placeholder for future implementation
114    pub fn initialize() -> i32 {
115        42
116    }
117}
118
119pub use error::DiffsolJsError;
120pub use initial_condition_options::InitialConditionSolverOptions;
121pub use jit::{JitBackendType, default_enabled_jit_backend};
122pub use linear_solver_type::LinearSolverType;
123pub use matrix_type::MatrixType;
124pub use ode::OdeWrapper;
125pub use ode_options::OdeSolverOptions;
126pub use ode_solver_type::OdeSolverType;
127pub use scalar_type::ScalarType;
128pub use solution_wrapper::SolutionWrapper;
129
130#[cfg(test)]
131mod solver_tests {
132    use super::solver;
133
134    #[test]
135    fn verify_initialization() {
136        let output = solver::initialize();
137        assert_eq!(output, 42);
138    }
139}