Skip to main content

lean_toolchain/
lib.rs

1//! Lean 4 toolchain discovery, fingerprinting, allowlist re-export, and build-script helpers.
2//!
3//! Sits one layer above the workspace crate [`lean_rs_sys`], which owns the raw `extern "C"`
4//! declarations, the hand-written refcount inline helpers, the signature-checked symbol
5//! allowlist, the header SHA-256 digest, and the link directives. This crate composes on top:
6//! a typed [`ToolchainFingerprint`], the workspace-only Lake [`LAKE_FIXTURE_DIGEST`], a layered
7//! [`LinkDiagnostics`] error type, and reusable build-script helpers
8//! ([`emit_lean_link_directives_checked`], [`build_lake_target`],
9//! [`build_lake_target_quiet`]) that downstream embedders and higher layers can use to get
10//! consistent link/rerun directives and Lake dylib paths without duplicating policy.
11//!
12//! ## Single typed entry point
13//!
14//! [`LEAN_VERSION`], [`LEAN_HEADER_PATH`], and [`LEAN_HEADER_DIGEST`] are re-exported from
15//! [`lean_rs_sys`] so embedders that depend on this crate need only one import for build
16//! metadata. The allowlist comes through [`required_symbols`] (no copy).
17//!
18//! ## Layering
19//!
20//! `lean-rs-sys → lean-toolchain → lean-rs`. Raw `lean_*` symbols never appear in this
21//! crate's public surface — they remain in `lean-rs-sys` and reach the safe layers through
22//! `lean-rs`'s `pub(crate)` modules.
23
24mod build_helpers;
25mod diagnostics;
26mod discover;
27mod fingerprint;
28mod modules;
29
30pub use build_helpers::{
31    BuiltLeanCapability, CAPABILITY_MANIFEST_SCHEMA_VERSION, CargoLeanCapability, build_lake_target,
32    build_lake_target_quiet, capability_env_var, capability_manifest_env_var, emit_lean_link_directives,
33    emit_lean_link_directives_checked,
34};
35pub use diagnostics::LinkDiagnostics;
36pub use discover::{DiscoverOptions, DiscoverySource, ToolchainInfo, discover_toolchain};
37pub use fingerprint::{HOST_TRIPLE, LAKE_FIXTURE_DIGEST, ToolchainFingerprint};
38pub use lean_rs_sys::{LEAN_HEADER_DIGEST, LEAN_HEADER_PATH, LEAN_VERSION};
39pub use modules::{
40    LeanLakeProjectModules, LeanModuleDescriptor, LeanModuleDiscoveryDiagnostic, LeanModuleDiscoveryOptions,
41    LeanModuleSetFingerprint, discover_lake_modules, lake_target_declared,
42};
43
44/// Version of the `lean-toolchain` crate, matching `Cargo.toml`.
45pub const VERSION: &str = env!("CARGO_PKG_VERSION");
46
47/// Curated allowlist of `LEAN_EXPORT` symbols the workspace relies on.
48///
49/// Returns [`lean_rs_sys::REQUIRED_SYMBOLS`] directly — the allowlist lives in
50/// exactly one place. Use this through `lean-toolchain` so consumer crates do
51/// not also need a direct `lean-rs-sys` dependency just to enumerate symbol
52/// names.
53#[must_use]
54pub fn required_symbols() -> &'static [&'static str] {
55    lean_rs_sys::REQUIRED_SYMBOLS
56}
57
58#[cfg(test)]
59mod tests {
60    use super::{LEAN_HEADER_DIGEST, LEAN_VERSION, VERSION, required_symbols};
61
62    #[test]
63    fn version_constant_matches_package() {
64        assert_eq!(VERSION, env!("CARGO_PKG_VERSION"));
65    }
66
67    #[test]
68    fn required_symbols_is_nonempty() {
69        assert!(!required_symbols().is_empty());
70    }
71
72    #[test]
73    fn lean_metadata_is_baked() {
74        assert!(!LEAN_VERSION.is_empty());
75        assert_eq!(LEAN_HEADER_DIGEST.len(), 64);
76        assert!(LEAN_HEADER_DIGEST.chars().all(|c| c.is_ascii_hexdigit()));
77    }
78}