Skip to main content

ferrum_native_ops/
abi.rs

1//! Stable native operator ABI constants and C descriptor shapes.
2
3pub const LEGACY_FERRUM_NATIVE_ABI_VERSION: &str =
4    ferrum_types::LEGACY_FERRUM_NATIVE_OPERATOR_ABI_VERSION;
5pub const FERRUM_NATIVE_ABI_VERSION: &str = ferrum_types::FERRUM_NATIVE_OPERATOR_ABI_VERSION;
6pub const LEGACY_FERRUM_NATIVE_OP_INIT_SYMBOL: &str = "ferrum_native_op_init";
7pub const LEGACY_FERRUM_NATIVE_OP_DESCRIPTOR_SYMBOL: &str = "ferrum_native_op_descriptor";
8
9// Compatibility aliases for schema-v1 consumers. New artifacts must declare a
10// unique descriptor symbol in their provider-bound manifest.
11pub const FERRUM_NATIVE_OP_INIT_SYMBOL: &str = "ferrum_native_op_init";
12pub const FERRUM_NATIVE_OP_DESCRIPTOR_SYMBOL: &str = "ferrum_native_op_descriptor";
13
14#[repr(C)]
15#[derive(Debug, Clone, Copy)]
16pub struct LegacyFerrumNativeOperatorDescriptor {
17    pub abi_version: u32,
18    pub operator_name: *const std::ffi::c_char,
19    pub operator_abi_version: *const std::ffi::c_char,
20}
21
22#[repr(C)]
23#[derive(Debug, Clone, Copy)]
24pub struct FerrumNativeOperatorDescriptorV2 {
25    pub struct_size: u32,
26    pub ferrum_native_abi_version: u32,
27    pub operator_name: *const std::ffi::c_char,
28    pub operator_abi_version: *const std::ffi::c_char,
29    pub g03_catalog_sha256: *const std::ffi::c_char,
30    pub abi_contract_sha256: *const std::ffi::c_char,
31}
32
33pub type FerrumNativeOperatorDescriptor = LegacyFerrumNativeOperatorDescriptor;
34
35#[derive(Debug, Clone, Copy, PartialEq, Eq)]
36pub struct NativeOperatorAbi {
37    pub ferrum_native_abi_version: &'static str,
38}
39
40impl NativeOperatorAbi {
41    pub const fn current() -> Self {
42        Self {
43            ferrum_native_abi_version: FERRUM_NATIVE_ABI_VERSION,
44        }
45    }
46
47    pub const fn legacy_v1() -> LegacyNativeOperatorAbi {
48        LegacyNativeOperatorAbi {
49            ferrum_native_abi_version: LEGACY_FERRUM_NATIVE_ABI_VERSION,
50            init_symbol: LEGACY_FERRUM_NATIVE_OP_INIT_SYMBOL,
51            descriptor_symbol: LEGACY_FERRUM_NATIVE_OP_DESCRIPTOR_SYMBOL,
52        }
53    }
54}
55
56#[derive(Debug, Clone, Copy, PartialEq, Eq)]
57pub struct LegacyNativeOperatorAbi {
58    pub ferrum_native_abi_version: &'static str,
59    pub init_symbol: &'static str,
60    pub descriptor_symbol: &'static str,
61}