Replace nlohmann/json with native C++20 JSON engine, cut build RAM/time, fix 32-bit build, enable -O2 -march=native
This commit is contained in:
@@ -34,17 +34,18 @@ The whole philosophy of Bantam rests on two principles:
|
||||
`std::map`, `std::span`) instead of raw memory areas.
|
||||
- Eliminate hand-rolled allocation/string code; rely on RAII so there is far
|
||||
less room for memory-allocation related vulnerabilities.
|
||||
- Depend only on **libcurl** (HTTP), **GNU readline** (interactive line
|
||||
editing) and the vendored single-header **nlohmann/json** library (vendored
|
||||
under `nlohmann/json.hpp`); the unsafe json-c C API is no longer used.
|
||||
- Depend only on **libcurl** (HTTP) and **GNU readline** (interactive line
|
||||
editing); JSON parsing/serialization and Markdown rendering are implemented
|
||||
natively in C++20 with no external or vendored library bloat, and the unsafe
|
||||
json-c C API is no longer used.
|
||||
|
||||
## Repository layout
|
||||
|
||||
```
|
||||
bantam.hpp all shared declarations (structs, prototypes)
|
||||
bantam.hpp all shared declarations (structs, prototypes, native Json type)
|
||||
util.cpp string building, UTF-8, prompt-injection filter, color, IDs, MD5
|
||||
config.cpp config file parsing, env precedence, /models discovery
|
||||
json.cpp request building + non-stream response parsing (nlohmann/json)
|
||||
json.cpp native RFC 8259 JSON engine, request building + response parsing
|
||||
llm.cpp libcurl HTTP client, OpenCode headers, backoff, SSE streaming
|
||||
tools.cpp bash/read/write tools, oversized-result offloading
|
||||
session.cpp message copy, session save/load, compaction
|
||||
@@ -52,7 +53,6 @@ render.cpp terminal markdown renderer (native, box-drawing tables)
|
||||
editor.cpp GNU readline line editor + history (+ term helpers)
|
||||
main.cpp REPL, agentic loop, tool dispatch, commands
|
||||
Makefile POSIX-compatible build
|
||||
nlohmann/ vendored nlohmann/json single-header (v3.12.0)
|
||||
README.md this document
|
||||
```
|
||||
|
||||
@@ -61,8 +61,8 @@ README.md this document
|
||||
- A C++20 compiler (`c++` / `g++` / `clang++`) and a POSIX `make`
|
||||
(`bmake`, `gmake`, `smake`, …).
|
||||
- **libcurl** development packages, available via the standard include /
|
||||
library search paths. The JSON layer is a vendored single-header
|
||||
(`nlohmann/json.hpp`) and needs no separate dependency.
|
||||
library search paths. The JSON layer is implemented natively in `json.cpp`
|
||||
and needs no separate dependency.
|
||||
- **GNU readline** development packages (`libreadline-dev` on Debian/Ubuntu,
|
||||
`readline` on Fedora/macOS) for the interactive prompt, history and line
|
||||
editing. On common systems:
|
||||
@@ -99,7 +99,7 @@ make CPPFLAGS="-I/opt/include" LDLIBS="-L/opt/lib -lcurl"
|
||||
## Building
|
||||
|
||||
```bash
|
||||
make # builds ./bantam (c++ -std=c++20 -O2 -s -Wall -Wextra -Wpedantic)
|
||||
make # builds & strips ./bantam (c++ -std=c++20 -O2 -march=native -s -Wall -Wextra -Wpedantic)
|
||||
make clean # remove build artifacts
|
||||
make install # install to $(DESTDIR)/usr/local/bin/bantam
|
||||
```
|
||||
@@ -391,8 +391,9 @@ collections use `std::vector`, and curl header lists and streaming state are
|
||||
wrapped in RAII types (`CurlHeaders`, `StreamCtx`) that free themselves on
|
||||
scope exit. There is no hand-rolled allocator and no manual `free` of message
|
||||
or tool-call data, so use-after-free and double-free are structurally
|
||||
unlikely. The vendored nlohmann/json library is used for all JSON parsing and
|
||||
serialization instead of the unsafe json-c C API.
|
||||
unlikely. A lightweight, native RFC 8259 JSON engine (`struct Json` in
|
||||
`json.cpp`) handles all JSON parsing and serialization using standard C++
|
||||
containers instead of an unsafe C API or a heavy header-only template library.
|
||||
|
||||
## Credits
|
||||
|
||||
|
||||
Reference in New Issue
Block a user