1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
//! An intermediate representation of the FFI layer.
//!
//! Things annotated with the `#[swift_bridge::bridge]` attribute get parsed into this IR.
//!
//! This IR is then used to generate the C header files, Objective-C bridging headers, Swift code,
//! and Rust code needed to power Rust + Swift interop.
#![deny(missing_docs)]
use proc_macro2::Ident;
use syn::Path;
use crate::bridge_module_attributes::CfgAttr;
use crate::parse::TypeDeclarations;
use crate::parsed_extern_fn::ParsedExternFn;
pub use self::bridge_macro_attributes::{SwiftBridgeModuleAttr, SwiftBridgeModuleAttrs};
pub use self::codegen::CodegenConfig;
mod errors;
mod parse;
mod bridge_macro_attributes;
mod bridge_module_attributes;
mod bridged_type;
mod parsed_extern_fn;
mod codegen;
#[cfg(test)]
mod test_utils;
const SWIFT_BRIDGE_PREFIX: &'static str = "__swift_bridge__";
/// Represents a type definition within an `extern "Rust"` module, as well as all of its methods.
///
/// ```no_run,ignore
/// #[swift_bridge::bridge]
/// mod ffi {
/// extern "Rust" {
/// type Stack;
///
/// fn push(&mut self, val: u8);
///
/// fn pop(self: &mut Stack) -> Option<u8>;
///
/// fn as_ptr(&self) -> *const u8;
///
/// fn len(self: &Stack) -> usize;
///
/// fn consume(self);
/// }
///
/// extern "Swift" {
/// // TODO: Examples
/// }
/// }
/// ```
pub struct SwiftBridgeModule {
name: Ident,
types: TypeDeclarations,
functions: Vec<ParsedExternFn>,
swift_bridge_path: Path,
cfg_attrs: Vec<CfgAttr>,
}
impl SwiftBridgeModule {
/// Set the path used for `swift_bridge` types such as `swift_bridge::RustString`.
/// We set this to `crate` when we're inside of the `swift_bridge` crate.
pub fn set_swift_bridge_path(&mut self, path: Path) {
self.swift_bridge_path = path;
}
}
#[cfg(test)]
mod tests {
#[test]
fn foo() {
//
}
}