Skip to main content

cera/
lib.rs

1// `stdarch_neon_dotprod` stabilized in 1.99.0-nightly, so it's no longer gated
2// here (keeping it would trip the `stable_features` lint). `stdarch_neon_i8mm`
3// and `stdarch_aarch64_prefetch` are still unstable — remove them from this
4// list as they stabilize.
5#![cfg_attr(
6    target_arch = "aarch64",
7    feature(stdarch_aarch64_prefetch, stdarch_neon_i8mm)
8)]
9
10/// Crate version, sourced from `Cargo.toml` at compile time. Useful
11/// for FFI / wrapper crates that want to surface the core lib version
12/// to their consumers (e.g. `cera-wasm::ceraVersion()`) without
13/// re-reading the manifest themselves.
14pub const VERSION: &str = env!("CARGO_PKG_VERSION");
15
16/// Short git SHA of this build, embedded by `build.rs`. Best-effort: `"unknown"`
17/// when git was unavailable at build time (a packaged source build). Can be
18/// pinned via the `CERA_GIT_SHA` build-env override.
19pub const GIT_SHA: &str = env!("CERA_GIT_SHA");
20
21/// Build provenance for telemetry — `"<version>+<git-sha>"`, e.g.
22/// `"0.4.0+1a2b3c4d5e6f"`. This is the analog of the llama.cpp build commit that
23/// a benchmark harness records alongside results to identify exactly which
24/// engine build produced them.
25pub fn build_info() -> String {
26    format!("{VERSION}+{GIT_SHA}")
27}
28
29pub mod audio_engine;
30pub mod backend;
31pub mod bundle;
32pub mod classifier;
33pub mod convert;
34pub mod engine;
35/// Auto-generated FlatBuffers code for KV cache serialization.
36/// Regenerate with: `flatc --rust -o src/generated schema/kv_cache.fbs`
37#[allow(warnings)]
38mod generated {
39    include!("generated/kv_cache_generated.rs");
40}
41pub mod gguf;
42pub mod grammar;
43pub mod kv_cache;
44pub mod lora;
45pub mod manifest;
46pub mod model;
47pub mod par;
48pub mod quant;
49pub mod sampler;
50pub mod session;
51pub mod spec;
52pub mod sysmem;
53pub mod tensor;
54pub mod time;
55pub mod tokenizer;
56pub mod tools;
57pub mod turboquant;
58pub mod vad;
59
60// Canonical public re-exports for the stateful API. Consumers should
61// `use cera::{Session, ModalitySink, ...}` rather than reaching into
62// `cera::session::*`.
63pub use backend::cpu_features::{CpuFeatures, CpuTier, cpu_features, cpu_tier};
64pub use classifier::{
65    BioesPrefix, EntitySpan, detect_pii, extract_spans, parse_bioes, viterbi_decode,
66};
67pub use engine::{
68    BackendPreference, CeraEngine, EngineConfig, ModelBytes, ModelFiles, ModelMetadata,
69};
70pub use model::whisper::{
71    Conv1dWeights, WHISPER_CATALOG, WhisperConfig, WhisperDecoderBlockWeights,
72    WhisperDecoderWeights, WhisperEncoderBlockWeights, WhisperEncoderWeights, WhisperModel,
73    WhisperModelCatalogEntry, WhisperSpecialTokens, WhisperTranscribeOpts, WhisperWeights,
74    find_whisper_catalog_entry, is_whisper_gguf, transcribe_pcm, transcribe_pcm_with_tokens,
75};
76pub use session::{
77    CeraError, FinishReason, GenerateOpts, GenerateSummary, ModalityCapabilities, ModalitySink,
78    Session, SessionConfig, SpecDecode,
79};
80pub use sysmem::{available_memory_bytes, fits_in_available_memory};
81pub use vad::{SileroVad, SpeechTimestamp, VadConfig, VadEvent, VadIterator, VadSampleRate};
82
83#[cfg(test)]
84mod build_info_tests {
85    use super::*;
86
87    #[test]
88    fn build_info_is_version_plus_sha() {
89        let info = build_info();
90        assert_eq!(info, format!("{VERSION}+{GIT_SHA}"));
91        // version prefix, single '+' separator, non-empty sha segment.
92        let (ver, sha) = info.split_once('+').expect("build_info has a '+'");
93        assert_eq!(ver, VERSION);
94        assert!(!sha.is_empty());
95    }
96}