Skip to main content

manganis_core/
ffi.rs

1use crate::BundledAsset;
2use const_serialize::{ConstStr, SerializeConst};
3use const_serialize_08 as const_serialize;
4use std::hash::Hash;
5
6/// Unified symbol data that can represent both assets and permissions
7///
8/// This enum is used to serialize different types of metadata into the binary
9/// using the same `__ASSETS__` symbol prefix. The CBOR format allows for
10/// self-describing data, making it easy to add new variants in the future.
11///
12/// Variant order does NOT matter for CBOR enum serialization - variants are
13/// matched by name (string), not by position or tag value.
14#[derive(Debug, Clone, Copy, PartialEq, Eq, SerializeConst)]
15#[repr(C, u8)]
16#[allow(clippy::large_enum_variant)]
17#[non_exhaustive]
18pub enum SymbolData {
19    /// An asset that should be bundled with the application
20    Asset(BundledAsset),
21
22    /// Android plugin metadata (prebuilt artifacts + Gradle deps)
23    AndroidArtifact(AndroidArtifactMetadata),
24
25    /// Swift package metadata (SPM location + product)
26    SwiftPackage(SwiftPackageMetadata),
27}
28
29/// Platform categories for permission mapping
30#[repr(u8)]
31#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, SerializeConst)]
32pub enum Platform {
33    Android,
34    Ios,
35    Macos,
36}
37
38/// Bit flags for supported platforms
39#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, SerializeConst)]
40pub struct PlatformFlags(u8);
41
42impl PlatformFlags {
43    pub const fn new() -> Self {
44        Self(0)
45    }
46}
47
48impl Default for PlatformFlags {
49    fn default() -> Self {
50        Self::new()
51    }
52}
53
54impl PlatformFlags {
55    pub const fn with_platform(mut self, platform: Platform) -> Self {
56        self.0 |= 1 << platform as u8;
57        self
58    }
59
60    pub const fn supports(&self, platform: Platform) -> bool {
61        (self.0 & (1 << platform as u8)) != 0
62    }
63
64    pub const fn all() -> Self {
65        Self(0b000111) // Android + iOS + macOS
66    }
67
68    pub const fn mobile() -> Self {
69        Self(0b000011) // Android + iOS
70    }
71}
72
73/// Platform-specific permission identifiers
74#[derive(Debug, Clone, PartialEq, Eq, Hash)]
75pub struct PlatformIdentifiers {
76    pub android: Option<ConstStr>,
77    pub ios: Option<ConstStr>,
78    pub macos: Option<ConstStr>,
79}
80
81/// Metadata describing an Android plugin artifact (.aar) that must be copied into the host Gradle project.
82#[derive(Debug, Clone, Copy, PartialEq, Eq, SerializeConst)]
83pub struct AndroidArtifactMetadata {
84    pub plugin_name: ConstStr,
85    pub artifact_path: ConstStr,
86    pub gradle_dependencies: ConstStr,
87}
88
89impl AndroidArtifactMetadata {
90    pub const fn new(
91        plugin_name: &'static str,
92        artifact_path: &'static str,
93        gradle_dependencies: &'static str,
94    ) -> Self {
95        Self {
96            plugin_name: ConstStr::new(plugin_name),
97            artifact_path: ConstStr::new(artifact_path),
98            gradle_dependencies: ConstStr::new(gradle_dependencies),
99        }
100    }
101}
102
103/// Metadata for a Swift package that needs to be linked into the app (iOS/macOS).
104#[derive(Debug, Clone, Copy, PartialEq, Eq, SerializeConst)]
105pub struct SwiftPackageMetadata {
106    pub plugin_name: ConstStr,
107    pub package_path: ConstStr,
108    pub product: ConstStr,
109}
110
111impl SwiftPackageMetadata {
112    pub const fn new(
113        plugin_name: &'static str,
114        package_path: &'static str,
115        product: &'static str,
116    ) -> Self {
117        Self {
118            plugin_name: ConstStr::new(plugin_name),
119            package_path: ConstStr::new(package_path),
120            product: ConstStr::new(product),
121        }
122    }
123}