$ show haskell/hie-bios
hie-bios is a Haskell library and CLI tool that manages the configuration and initialization of GHC API sessions for IDE tools like haskell-language-server. It finds and loads a 'Cradle' configuration from a `hie.yaml` file or via implicit detection (e.g., stack.yaml, cabal.project), then obtains the necessary GHC compiler flags by invoking build tools (cabal, stack, or a user-supplied script). It supports multiple cradle types (cabal, stack, bios, direct, multi, none) and handles the full lifecycle: locating the project root, parsing configuration, running build tools with wrapper scripts to capture flags, caching interface files, and setting up GHC's DynFlags and targets. The architecture is modular, with clear separation between config parsing, cradle resolution, process execution, and GHC session management. The code is well-structured, uses modern Haskell patterns (monad transformers, CPS for temporary files), and has an extensive test suite covering various project layouts and tool combinations. Key reusable components include the process utility module (HIE.Bios.Process) for running commands with temp-file outputs and caching, and the GHC version compatibility layer (HIE.Bios.Ghc.Gap).
The LLM identified 2 files worth highlighting for reuse:
Provides generic process execution utilities used across all cradle implementations. Key functions include `readProcessWithCwd` (runs a command with clean environment and wraps result in CradleLoadResult), `readProcessWithOutputs` (runs a command with temp files for outputs like HIE_BIOS_OUTPUT and captures them), `cacheFile`/`cacheFileIn` (atomic, thread-safe file caching with lock files and temp-file rename), and `findFileUpwards`/`findFileUpwardsPredicate` (traverse directories upward to locate files). These functions are self-contained (import only standard libraries and HIE.Bios.Types) and could be extracted into a standalone library for any Haskell tool that needs to invoke subprocesses with output files and caching.
Central compatibility layer for differences across GHC versions (9.2 through 9.14+). Uses CPP and version guards to abstract over API changes in GHC modules (e.g., `load'`, `typecheckModule`, `parseDynamicFlags`, `initMulti`, `homeUnitId_`). It also provides utility functions like `removeRTS`, `setNoCode`, `setWayDynamicIfHostIsDynamic`, and `gopt_set`. This module is essential for any tool that directly uses the GHC API and needs to support multiple GHC versions. It is relatively isolated (imports only GHC internals and a few standard libraries) and could be reused as a shim layer for other GHC-based projects.