1use axiolid_contracts::{
4 BoundaryContract, IntegrationDescriptor, IntegrationProfile, Representation,
5};
6
7macro_rules! compiled_feature {
8 ($target:expr, $name:literal) => {
9 if cfg!(feature = $name) {
10 $target.push($name);
11 }
12 };
13}
14
15macro_rules! compiled_representation {
16 ($target:expr, $feature:literal, $representation:expr) => {
17 if cfg!(feature = $feature) {
18 $target.push($representation);
19 }
20 };
21}
22
23pub fn descriptor() -> IntegrationDescriptor {
29 let mut descriptor = IntegrationDescriptor::empty(IntegrationProfile::RustFacade);
30 descriptor.boundary = BoundaryContract::rust();
31 descriptor.enabled_features = enabled_features();
32 descriptor.representations = enabled_representations();
33 descriptor
34}
35
36fn enabled_features() -> Vec<&'static str> {
37 let mut features = Vec::new();
38 compiled_feature!(features, "integration");
39 compiled_feature!(features, "mesh");
40 compiled_feature!(features, "linear");
41 compiled_feature!(features, "predicates");
42 compiled_feature!(features, "linear-intersection");
43 compiled_feature!(features, "profiles");
44 compiled_feature!(features, "curves");
45 compiled_feature!(features, "surfaces");
46 compiled_feature!(features, "topology");
47 compiled_feature!(features, "brep");
48 compiled_feature!(features, "primitives");
49 compiled_feature!(features, "model");
50 compiled_feature!(features, "evaluate");
51 compiled_feature!(features, "nurbs");
52 compiled_feature!(features, "tessellation");
53 compiled_feature!(features, "spatial");
54 compiled_feature!(features, "ray-mesh");
55 compiled_feature!(features, "measure");
56 compiled_feature!(features, "overlay");
57 compiled_feature!(features, "field");
58 compiled_feature!(features, "field-ops");
59 compiled_feature!(features, "field-navigation");
60 compiled_feature!(features, "heal");
61 compiled_feature!(features, "contracts");
62 compiled_feature!(features, "mesh-contracts");
63 compiled_feature!(features, "mesh-boolean");
64 compiled_feature!(features, "mesh-section");
65 compiled_feature!(features, "graph-compile");
66 compiled_feature!(features, "dispatch-mesh-boolean");
67 compiled_feature!(features, "dispatch-mesh-section");
68 compiled_feature!(features, "generate");
69 compiled_feature!(features, "cpu");
70 compiled_feature!(features, "parallel");
71 compiled_feature!(features, "simd");
72 compiled_feature!(features, "gpu");
73 compiled_feature!(features, "discrete");
74 compiled_feature!(features, "parametric");
75 compiled_feature!(features, "advanced");
76 compiled_feature!(features, "application");
77 compiled_feature!(features, "portable-provider");
78 compiled_feature!(features, "full");
79 features.sort_unstable();
80 features
81}
82
83fn enabled_representations() -> Vec<Representation> {
84 let mut representations = vec![Representation::Scalar];
85 compiled_representation!(representations, "linear", Representation::Linear);
86 compiled_representation!(representations, "profiles", Representation::Profile2d);
87 compiled_representation!(representations, "curves", Representation::AnalyticCurve);
88 compiled_representation!(representations, "surfaces", Representation::AnalyticSurface);
89 compiled_representation!(representations, "topology", Representation::Topology);
90 compiled_representation!(representations, "brep", Representation::ExactBrep);
91 compiled_representation!(representations, "mesh", Representation::TriangleMesh);
92 compiled_representation!(representations, "model", Representation::ModelGraph);
93 compiled_representation!(representations, "field", Representation::SampledField);
94 representations.sort_unstable();
95 representations.dedup();
96 representations
97}
98
99#[cfg(test)]
100mod tests {
101 use super::*;
102 use axiolid_contracts::{INTEGRATION_API_VERSION, MINIMUM_RUST_VERSION};
103
104 #[test]
105 fn compiled_descriptor_is_honest_about_default_surface() {
106 let descriptor = descriptor();
107 assert_eq!(descriptor.api_version, INTEGRATION_API_VERSION);
108 assert_eq!(descriptor.minimum_rust_version, Some(MINIMUM_RUST_VERSION));
109 assert!(descriptor.enabled_features.contains(&"integration"));
110 assert!(descriptor.representations.contains(&Representation::Scalar));
111 assert!(descriptor.capabilities.is_empty());
112 }
113
114 #[test]
115 fn feature_and_representation_rows_are_unique() {
116 let descriptor = descriptor();
117 let mut features = descriptor.enabled_features.clone();
118 features.sort_unstable();
119 features.dedup();
120 assert_eq!(features, descriptor.enabled_features);
121
122 let mut representations = descriptor.representations.clone();
123 representations.sort_unstable();
124 representations.dedup();
125 assert_eq!(representations, descriptor.representations);
126 }
127}