[package]
# Pure-Rust core, polars-style. The Python wheel is built by
# maturin from `crates/kglite-py/` (which depends on this crate).
# Rust embedders depend on this crate directly:
#   kglite = { path = "..." }  # pre-publish
#   kglite = "0.10"            # post-crates.io-publish
name = "kglite"
version = "0.11.10"
edition = "2021"
authors = ["Kristian dF Kollsgård <kkollsg@gmail.com>"]
license = "MIT"
description = "Pure-Rust knowledge graph engine — Cypher pipeline, snapshot/working CoW transactions, columnar/mmap/disk storage backends, optional dataset loaders (SEC EDGAR, Sodir, Wikidata). PyO3 wrappers live in the sibling kglite-py crate (the Python wheel); embeddable directly from any Rust binary without PyO3 in the dep tree."
readme = "README.md"
repository = "https://github.com/kkollsga/kglite"
homepage = "https://github.com/kkollsga/kglite"
documentation = "https://docs.rs/kglite"
keywords = ["graph", "knowledge-graph", "cypher", "petgraph", "database"]
categories = ["database", "data-structures"]

[lib]
# `[lib] name = "kglite"` matches the `[package] name` so
# dependent crates do the natural `use kglite::api::*`. The
# kglite-py wrapper uses `[lib] name = "kglite_py"` to avoid
# producing the same rlib filename as this crate (they're different
# artifact types — rlib here, cdylib over there — but cargo still
# requires distinct filenames).
name = "kglite"
doctest = false

# Standalone perf microbench for the bz2 decoder. Requires the
# `parallel-bz2` feature because it calls `bzip2_rs` directly. Run
# with `cargo run -p kglite --bin bz2_bench --release --features
# parallel-bz2 -- <path>`.
[[bin]]
name = "bz2_bench"
path = "src/bin/bz2_bench.rs"
required-features = ["parallel-bz2"]

# code_tree accuracy harness — reports CALLS-resolution stats + node/edge
# counts for a repo as JSON, the baseline the re-resolution phases track.
# Run with `cargo run -p kglite --bin code_tree_stats --release -- <path>`.
[[bin]]
name = "code_tree_stats"
path = "src/bin/code_tree_stats.rs"

[features]
default = []
# Rust-native embedder backend behind the `fastembed` Cargo feature.
# Downloads ONNX model weights on first use (cached at
# `~/.cache/fastembed/`). Off by default — the Python wheel relies
# on user-provided Python embedder classes via `PyEmbedderAdapter`,
# and we don't want to pull a 100-200 MB ONNX runtime into every
# wheel build. The `kglite-mcp-server` binary enables this feature
# so the Rust-only deployment path supports `text_score()` semantic
# search without a Python embedder.
fastembed = ["dep:fastembed"]
# Block-level parallel decoder for single-stream `.bz2` files (the
# Wikidata `latest-truthy.nt.bz2` shape). Off by default because the
# implementation depends on `bzip2-rs` with its `rayon` Cargo
# feature — that feature is only available in the paolobarbolini
# git fork (see the dep block below), not on the crates.io
# `bzip2-rs = 0.1.x` release. With this feature off the loader
# still parallelises multi-stream pbzip2-produced files; only the
# single-stream block-level path falls back to sequential
# `bzip2::read::MultiBzDecoder`. Wikidata-scale ingest is the only
# workload that actually benefits — opt in if you're decompressing
# > 50 GB single-stream files. The `bz2_bench` binary requires this
# feature.
# `bzip2-rs/rayon` is intentionally omitted here even though the
# code path uses `bzip2_rs::RayonThreadPool`. Cargo's publish-time
# manifest resolver checks that *every* feature can be enabled
# against crates.io versions of every dep, and bzip2-rs 0.1.x on
# crates.io has no `rayon` feature. Consumers who enable
# `parallel-bz2` are expected to also pull a bzip2-rs version that
# has the `rayon` feature, via their own `[patch.crates-io]`
# pointing at the paolobarbolini fork (the workspace root does
# this automatically for local development).
parallel-bz2 = ["dep:bzip2-rs"]

# Pre-packaged dataset loaders. Polars-io style: opt in to only the
# loaders you actually use. Phase G.3a folded the standalone
# `kglite-{sec,sodir,wikidata}` sibling crates into here.
sec = [
    "dep:thiserror",
    "dep:reqwest",
    "dep:governor",
    "dep:zip",
    "dep:quick-xml",
]
sodir = [
    "dep:thiserror",
    "dep:reqwest",
    "dep:governor",
]
# OKF (Open Knowledge Format) bundle loader — parses a directory of
# markdown files with YAML frontmatter, cross-linked by markdown links,
# into a knowledge graph (read-only ingestion, like `code_tree` but for
# OKF / memory / skills / Obsidian bundles). Off by default so the bare
# crate pulls no YAML parser; the Python wheel enables it. `regex` (link
# extraction) and `walkdir` (tree walk) are already non-optional deps.
okf = ["dep:yaml-rust2"]
wikidata = [
    "dep:thiserror",
    "dep:reqwest",
    # `wikidata` does NOT imply `parallel-bz2` even though Wikidata's
    # `latest-truthy.nt.bz2` is the canonical workload for the
    # parallel decoder. Reason: `parallel-bz2` depends on the
    # paolobarbolini bzip2-rs git fork, which docs.rs (building
    # from crates.io) can't see. If `wikidata` implied
    # `parallel-bz2`, `[package.metadata.docs.rs]` couldn't enable
    # `wikidata` to surface its API docs → broken docs.rs page on
    # publish. The sequential `MultiBzDecoder` fallback handles
    # wikidata correctly (just slower); opt into `parallel-bz2`
    # explicitly for the ~10× speedup on M-series hardware.
]
# General-purpose RDF loader (Turtle / N-Triples / N-Quads / TriG via
# the oxttl parser family). Off by default so the bare crate pulls no
# RDF parser; `oxttl` + `oxrdf` are only in the dep tree when `rdf` is
# enabled. Phase 1 covers the in-memory (Default) backend only.
rdf = ["dep:oxttl", "dep:oxrdf"]

# `--cfg loom` is set manually when running the loom interleaving model
# (tests/loom_session.rs); register it so normal builds don't warn (and
# `make lint`'s `-D warnings` doesn't fail) on the `#[cfg(loom)]` gate.
[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(loom)'] }

[dependencies]
petgraph = { version = "0.8.3", features = ["serde-1"] }
fastembed = { version = "5", optional = true, default-features = false, features = ["ort-download-binaries-native-tls", "hf-hub-native-tls"] }
serde = { version = "1.0.228", features = ["derive"] }
serde_json = "1.0.149"
bincode = "1.3"
chrono = { version = "0.4.43", features = ["serde"] }
geo = "0.33"
rstar = "0.12"
wkt = "0.14"
regex = "1"
rayon = "1.10"
flate2 = "1"
zstd = "0.13"
memmap2 = "0.9"
libc = "0.2"
bzip2 = "0.6"
# Optional — gated behind the `parallel-bz2` Cargo feature. The
# `rayon` feature on bzip2-rs lives only on the paolobarbolini git
# fork, not on crates.io `bzip2-rs = 0.1.x`. The
# workspace-root `[patch.crates-io]` points local builds at the
# fork so `parallel-bz2` works during development; on `cargo
# publish` the patch isn't carried into the published manifest, so
# crates.io consumers who enable `parallel-bz2` need to add a
# matching `[patch.crates-io]` in their own workspace. Default-off
# so the headline crates.io build resolves cleanly without needing
# the patch.
bzip2-rs = { version = "0.1", optional = true }
tree-sitter = "0.26.8"
tree-sitter-python = "0.25.0"
tree-sitter-rust = "0.24.2"
tree-sitter-typescript = "0.23.2"
tree-sitter-javascript = "0.25.0"
tree-sitter-go = "0.25.0"
tree-sitter-java = "0.23.5"
tree-sitter-c = "0.24.1"
tree-sitter-cpp = "0.23.4"
tree-sitter-c-sharp = "0.23.5"
tree-sitter-swift = "0.7.2"
tree-sitter-php = "0.24.2"
tree-sitter-html = "0.23.2"
tree-sitter-css = "0.25.0"
tree-sitter-dart = "0.2.0"
toml = "1.1.2"
roxmltree = "0.21.1"
walkdir = "2.5.0"
tempfile = "3"
aho-corasick = "1.1.4"
memchr = "2"
rustc-hash = "2"
csv = "1.3"
geojson = "0.24"
indexmap = { version = "2", features = ["serde"] }
tokio = { version = "1", features = ["rt-multi-thread", "macros", "fs", "io-util", "sync", "time"] }

# ── Dataset loader deps (feature-gated, all `optional = true`) ──
# Folded from the standalone `kglite-{sec,sodir,wikidata}` crates in
# G.3a. Each is `optional = true` so users who don't enable the
# `sec` / `sodir` / `wikidata` features get a build without these
# in their dep tree.
thiserror = { version = "1", optional = true }
reqwest = { version = "0.12", optional = true, default-features = false, features = ["rustls-tls", "gzip", "stream"] }
governor = { version = "0.7", optional = true }
zip = { version = "2", optional = true, default-features = false, features = ["deflate"] }
quick-xml = { version = "0.36", optional = true }

# OKF loader YAML frontmatter parser — gated behind the `okf` feature.
# `yaml-rust2` is a pure-Rust, actively-maintained YAML 1.2 parser (no
# `unsafe`/libyaml, no unmaintained advisory); only pulled when `okf` is
# enabled (the wheel enables it; bare builds don't).
yaml-rust2 = { version = "0.10", optional = true }

# RDF loader deps — gated behind the `rdf` feature. `oxttl` is the
# Oxigraph family's standalone Turtle/N-Triples/N-Quads/TriG parser;
# it re-exports `oxrdf` term types (Triple / Quad / Term / Literal).
# oxttl 0.2.3 resolves oxrdf 0.3.x — pin oxrdf to the version oxttl
# pulls so they agree on the term types.
oxttl = { version = "0.2", optional = true }
oxrdf = { version = "0.3", optional = true }

[dev-dependencies]
tempfile = "3"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }

# loom — exhaustive interleaving model-checker for the Session commit/snapshot
# lock pattern. Only pulled in under `--cfg loom` (the loom test is
# `#![cfg(loom)]`), so normal `cargo test` / `cargo build` never compile it.
# Run: RUSTFLAGS="--cfg loom" cargo test -p kglite --test loom_session
[target.'cfg(loom)'.dev-dependencies]
loom = "0.7"

# docs.rs builds with these features so the published API page covers
# the dataset loaders + fastembed adapter, which would otherwise be
# missing (defaults are intentionally empty). `parallel-bz2` is
# excluded deliberately — it depends on the paolobarbolini bzip2-rs
# git fork, which docs.rs (building from the crates.io registry)
# can't resolve. `all-features = true` would pull `parallel-bz2` in
# transitively and break the docs.rs build → broken
# docs.rs/kglite badge in the README. `rustdoc-args` enables doc-cfg
# annotations so feature-gated APIs are visually marked on the page.
[package.metadata.docs.rs]
features = ["sec", "sodir", "wikidata", "fastembed", "okf"]
rustdoc-args = ["--cfg", "docsrs"]
