Skip to main content

transcribe_cpp_sys/
lib.rs

1//! Raw native FFI bindings for [transcribe.cpp](https://github.com/handy-computer/transcribe.cpp),
2//! a C/C++ speech-to-text library built on ggml.
3//!
4//! This crate is the unsafe, generated FFI surface. The safe, idiomatic API is
5//! the [`transcribe-cpp`](https://crates.io/crates/transcribe-cpp) crate.
6//!
7//! The bindings in [`transcribe_sys`] are generated by `bindings/rust/xtask`
8//! (bindgen, comments disabled for determinism) from
9//! `include/transcribe/extensions.h` — the flattened public surface
10//! (`transcribe.h` plus every family extension header) — and committed to the
11//! repo, so building this crate needs no libclang. CI regenerates them and
12//! diffs against the committed copy, pinned to `include/transcribe.abihash`
13//! (`xtask check`); per-field ABI layout checks are waived because bindgen
14//! takes layout from a real compiler (see the crate README).
15
16#![allow(non_upper_case_globals)]
17#![allow(non_camel_case_types)]
18#![allow(non_snake_case)]
19#![allow(dead_code)]
20
21#[allow(clippy::all)]
22mod transcribe_sys {
23    include!("transcribe_sys.rs");
24}
25
26pub use transcribe_sys::*;
27
28#[cfg(test)]
29mod smoke {
30    //! Proves the whole chain wires up: the cmake source build, the link
31    //! manifest -> link line, and the committed bindgen surface. If this links
32    //! and prints a version, `build.rs` and the FFI are sound.
33    use super::*;
34    use std::ffi::CStr;
35
36    #[test]
37    fn version_links_and_matches_package() {
38        let raw = unsafe { transcribe_version() };
39        assert!(!raw.is_null());
40        let version = unsafe { CStr::from_ptr(raw) }.to_str().unwrap();
41        assert_eq!(version, env!("CARGO_PKG_VERSION"));
42    }
43
44    #[test]
45    fn abi_struct_size_is_live() {
46        // A real call into the native lib that returns a runtime value.
47        let size =
48            unsafe { transcribe_abi_struct_size(transcribe_abi_struct::TRANSCRIBE_ABI_RUN_PARAMS) };
49        assert!(size > 0);
50    }
51}