Skip to main content

_native/
lib.rs

1//! Entrypoint for the fontlift Python extension crate.
2//!
3//! # Two build modes
4//!
5//! This crate compiles differently depending on whether the `python-bindings`
6//! Cargo feature is active:
7//!
8//! | Feature on? | What compiles | Who sets it |
9//! |-------------|---------------|-------------|
10//! | Yes | `bindings.rs` — real PyO3 extension, produces the `_native` Python module | `maturin` |
11//! | No  | `stub.rs` — a tiny stand-in with no Python dependency | `cargo test --workspace` |
12//!
13//! ## Why the stub exists
14//!
15//! PyO3 needs a live Python installation to link against. CI machines and
16//! developer laptops running `cargo test --workspace` often have neither Python
17//! nor the matching `libpython`. The stub satisfies the Rust type-checker and
18//! lets workspace tests pass without requiring a Python toolchain.
19//!
20//! ## How maturin uses the real bindings
21//!
22//! When you run `maturin develop` or `maturin build`, maturin passes
23//! `--features python-bindings` to Cargo. That switches this crate to compile
24//! `bindings.rs` and link against the active Python interpreter, producing the
25//! `.so` / `.pyd` file that Python imports as `fontlift._native`.
26
27#![allow(dead_code)]
28
29#[cfg(feature = "python-bindings")]
30mod bindings;
31#[cfg(not(feature = "python-bindings"))]
32mod stub;
33
34#[cfg(feature = "python-bindings")]
35pub use bindings::*;
36#[cfg(not(feature = "python-bindings"))]
37pub use stub::*;
38
39#[cfg(test)]
40mod feature_flags {
41    use super::*;
42
43    #[cfg(feature = "python-bindings")]
44    #[test]
45    fn bindings_feature_flag_true() {
46        assert!(PYTHON_BINDINGS_ENABLED);
47    }
48
49    #[cfg(not(feature = "python-bindings"))]
50    #[test]
51    fn bindings_feature_flag_false() {
52        assert!(!PYTHON_BINDINGS_ENABLED);
53    }
54}