Skip to main content

edgefirst_tflite_sys/
lib.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2025 Au-Zone Technologies. All Rights Reserved.
3
4//! Low-level FFI bindings for the TensorFlow Lite C API.
5//!
6//! This crate provides raw, unsafe bindings generated by `bindgen` with
7//! `--dynamic-loading`. Symbols are resolved at runtime via `libloading`.
8//!
9//! **Most users should depend on `edgefirst-tflite` instead**, which
10//! provides a safe, ergonomic API on top of these bindings.
11//!
12//! # Library Discovery
13//!
14//! Use [`discovery::discover`] to automatically find and load the `TFLite`
15//! shared library, or [`discovery::load`] to load from a specific path.
16//!
17//! # Delegate Extensions
18//!
19//! The [`hal_ffi`] module provides function pointer structs for the
20//! HAL Delegate DMA-BUF API (the standard, delegate-agnostic interface).
21//!
22//! The [`vx_ffi`] module provides function pointer structs for the
23//! legacy `VxDelegate` DMA-BUF and `CameraAdaptor` APIs. Both are loaded
24//! at runtime from the delegate shared library.
25//!
26//! The [`xnnpack_ffi`] module provides function pointer structs for the
27//! XNNPACK built-in delegate API, loaded from the main `TFLite` library.
28
29// Suppress all clippy/rustc/rustdoc warnings for bindgen-generated code.
30#[allow(
31    clippy::all,
32    clippy::pedantic,
33    clippy::nursery,
34    non_upper_case_globals,
35    non_camel_case_types,
36    non_snake_case,
37    missing_debug_implementations,
38    unreachable_pub,
39    dead_code,
40    rustdoc::bare_urls,
41    rustdoc::broken_intra_doc_links
42)]
43mod ffi {
44    include!("ffi.rs");
45
46    impl tensorflowlite_c {
47        /// Returns a reference to the underlying `libloading::Library`.
48        ///
49        /// This is an escape hatch for loading optional symbols (e.g.,
50        /// XNNPACK) that live inside the main TFLite shared library rather
51        /// than a separate delegate `.so`.
52        #[must_use]
53        pub fn library(&self) -> &::libloading::Library {
54            &self.__library
55        }
56    }
57}
58
59pub use ffi::*;
60
61/// Sentinel value for an unset `TfLiteBufferHandle` (`kTfLiteNullBufferHandle = -1`).
62#[allow(non_upper_case_globals)]
63pub const kTfLiteNullBufferHandle: TfLiteBufferHandle = -1;
64
65pub mod discovery;
66pub mod hal_ffi;
67pub mod vx_ffi;
68pub mod xnnpack_ffi;