[package]
name = "alkahest-cas"
version.workspace = true
edition.workspace = true
authors.workspace = true
license.workspace = true
description   = "High-performance computer algebra kernel: symbolic expressions, polynomials, Gröbner bases, JIT, and Arb ball arithmetic."
repository    = "https://github.com/alkahest-cas/alkahest"
homepage      = "https://alkahest-cas.github.io/alkahest/"
documentation = "https://docs.rs/alkahest-cas"
keywords      = ["computer-algebra", "symbolic-math", "polynomial", "groebner", "jit"]
categories    = ["mathematics", "science"]
readme        = "../README.md"

[package.metadata.docs.rs]
# Build docs with feature-gated APIs visible; jit omitted because
# docs.rs does not have LLVM 15 headers available.
features      = ["egraph", "groebner", "parallel"]
rustdoc-args  = ["--cfg", "docsrs"]

[features]
default = ["groebner"]
egraph = ["dep:egglog"]
# Requires LLVM 15 dev headers (llvm-15-dev / llvm@15) at compile time.
jit   = ["dep:inkwell"]
# Pure-Rust Tier-1 JIT: ~10× faster compile than LLVM, ~10–20% slower code.
# Enables JIT in the default PyPI wheel without a system LLVM install.
cranelift = [
    "dep:cranelift-jit",
    "dep:cranelift-codegen",
    "dep:cranelift-frontend",
    "dep:cranelift-module",
    "dep:cranelift-native",
]
parallel = ["dep:rayon", "dep:dashmap"]
# Phase 29: use libflint3-dev (FLINT ≥ 3.0) for ArbBall when available.
# Falls back to MPFR by default; flip this on Ubuntu 24.04 where libflint3-dev ships.
flint3 = []
# V5-11: Gröbner basis computation (F4-style over ℚ)
groebner = []
# V1-1: production NVPTX JIT backend. Implies `jit` for the inkwell-based
# codegen. Requires LLVM 15 with the NVPTX target (`llc --version | grep nvptx`)
# at build time and libcuda.so.1 at runtime. cudarc uses dynamic loading so the
# feature builds even on machines without CUDA installed.
cuda = ["jit", "dep:cudarc"]
# V1-7: GPU-accelerated Gröbner basis via Macaulay-matrix row reduction mod p.
# Only needs cudarc (driver + NVRTC), NOT inkwell/jit — the reduction kernel is
# a static PTX string, not LLVM-generated. Falls back to pure-Rust row reduction
# when no CUDA device is present at runtime.
groebner-cuda = ["groebner", "dep:cudarc"]

[dependencies]
rug = { version = "1", features = ["integer", "rational", "float"] }
num-integer = "0.1"
# force-cross lets gmp-mpfr-sys build when the Rust host and target triples
# differ (e.g. x86_64-pc-windows-msvc host → x86_64-pc-windows-gnu target).
gmp-mpfr-sys = { version = "1", features = ["force-cross"] }
egglog  = { version = "0.4", optional = true }
inkwell = { version = "0.9", features = ["llvm15-0-prefer-dynamic"], optional = true }
cranelift-jit      = { version = "0.132", optional = true }
cranelift-codegen  = { version = "0.132", optional = true }
cranelift-frontend = { version = "0.132", optional = true }
cranelift-module   = { version = "0.132", optional = true }
cranelift-native   = { version = "0.132", optional = true }
rayon   = { version = "1",   optional = true }
dashmap = { version = "6",   optional = true }
cudarc  = { version = "0.19", default-features = false, features = ["driver", "nvrtc", "fallback-dynamic-loading", "cuda-12060"], optional = true }
bitflags = "2.11.1"
boxcar = "0.2.14"
wide = "0.7"

[dev-dependencies]
proptest = "1"
codspeed-criterion-compat = { version = "2", features = ["html_reports"] }

[[bench]]
name = "alkahest_bench"
harness = false

[[example]]
name = "dump_ptx"
required-features = ["cuda"]
