|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +**fast_io** is a header-only C++20 I/O library designed to replace `<iostream>` and `<cstdio>` with dramatically better performance. It makes direct system calls, bypassing intermediary layers, and uses C++20 concepts extensively for type abstraction. |
| 8 | + |
| 9 | +## Build & Development |
| 10 | + |
| 11 | +### Prerequisites |
| 12 | +- C++20 compiler: GCC >= 15, Clang >= 21, or MSVC |
| 13 | +- CMake >= 3.15 |
| 14 | + |
| 15 | +### Build Tests, Benchmarks, and Examples |
| 16 | + |
| 17 | +```bash |
| 18 | +# Prebuild: generate test files (only needed once) |
| 19 | +cmake -B fast_io_prebuild -S . -DCMAKE_BUILD_TYPE=Release -DENABLE_TESTS=On -DTESTS_PREBUILD=On |
| 20 | +cmake --build fast_io_prebuild |
| 21 | +./fast_io_prebuild/tests_prebuild linux # or "windows msvc" |
| 22 | + |
| 23 | +# Build tests/examples/benchmarks |
| 24 | +cmake -B fast_io_build -S . -DCMAKE_BUILD_TYPE=Release -DENABLE_TESTS=On |
| 25 | +cmake --build fast_io_build |
| 26 | + |
| 27 | +# Run tests |
| 28 | +cmake --build fast_io_build --target test |
| 29 | +``` |
| 30 | + |
| 31 | +### Run a Single Test |
| 32 | + |
| 33 | +Tests are located under `tests/`. After building, individual test binaries are in the `fast_io_build/tests/` subdirectories. Run them directly. |
| 34 | + |
| 35 | +### CI |
| 36 | + |
| 37 | +GitHub Actions (`.github/workflows/c-cpp.yml`) runs: |
| 38 | +- **Linux**: GCC with `-fsanitize=address,undefined -Wall -Wextra -Wpedantic -Wshadow -Wconversion -Werror` |
| 39 | +- **Windows**: MSVC with `/EHsc /W3 /WX /sdl` |
| 40 | +- Uses Ninja generator on both platforms |
| 41 | + |
| 42 | +## Architecture |
| 43 | + |
| 44 | +The library uses a layered architecture: |
| 45 | + |
| 46 | +| Layer | Header | Description | |
| 47 | +|-------|--------|-------------| |
| 48 | +| Concepts | `fast_io_concept.h` | C++20 concepts for I/O device abstraction | |
| 49 | +| Core | `fast_io_core.h` | Freestanding-capable: bit ops, integer formatting, codecvt, SIMD | |
| 50 | +| Freestanding | `fast_io_freestanding.h` | Adds buffered I/O, decorators, serializers, transcoders | |
| 51 | +| Hosted | `fast_io_hosted.h` | Full features: platform abstractions, filesystem, threads, process/IPC | |
| 52 | +| Main | `fast_io.h` | Entry point: combines hosted + legacy stream interop | |
| 53 | + |
| 54 | +### Key Directories |
| 55 | + |
| 56 | +- `include/fast_io_core_impl/` — Core implementation internals (operations: `printimpl`, `readimpl`, `writeimpl`, `transmitimpl`, `transcodeimpl`) |
| 57 | +- `include/fast_io_hosted/` — Hosted platform implementations (console, filesystem, mmap, threads, process) |
| 58 | +- `include/fast_io_freestanding_impl/` — Buffered I/O, decorators, scanners, serialization |
| 59 | +- `include/fast_io_legacy_impl/` — FILE*/streambuf hacks for glibc, MSVCRT, UCRT, MUSL, BSD libc, libstdc++, libc++, MSVC STL |
| 60 | +- `include/fast_io_dsal/` — Data Structure Abstraction Layer (vector, string, deque, list, etc.) |
| 61 | +- `include/fast_io_driver/` — Third-party integrations (Boost.Asio, OpenSSL, Qt, MFC, LLVM, Python, zlib) |
| 62 | +- `include/fast_io_crypto/` — SHA-1, SHA-256, SHA-512, HMAC, ciphers |
| 63 | +- `share/fast_io/` — C++20 module files |
| 64 | + |
| 65 | +### Header Organization |
| 66 | + |
| 67 | +- `fast_io.h` — Primary entry point (most common include) |
| 68 | +- `fast_io_device.h` — Device types (files, pipes, sockets) |
| 69 | +- `fast_io_crypto.h` — Cryptographic hash functions |
| 70 | +- `fast_io_i18n.h` — Internationalization/locale |
| 71 | +- `fast_io_legacy.h` — Legacy C/C++ stream compatibility |
| 72 | + |
| 73 | +### fast_io's 6 layers of files from bottom to top |
| 74 | +- wine_file |
| 75 | +- nt_file |
| 76 | +- win32_file |
| 77 | +- posix_file |
| 78 | +- c_file |
| 79 | +- filebuf_file |
| 80 | + |
| 81 | +From bottom to top we do a move. |
| 82 | +From top to bottom we do a static cast to the |
| 83 | +lower level of io_observer. |
| 84 | + |
| 85 | +## Testing |
| 86 | + |
| 87 | +- Tests are organized into numbered categories under `tests/` |
| 88 | +- `.test_prop.toml` controls which tests run per platform/compiler |
| 89 | +- Test files are generated by `tests/0000.tests_prebuild/gentests.cc` |
| 90 | +- Some tests are ignored for incomplete features or platform requirements |
| 91 | + |
| 92 | +## Benchmarking |
| 93 | + |
| 94 | +Benchmarks live under `benchmark/` with numbered categories (integer I/O, floating-point, file I/O, concat, containers, codecvt, syscalls, etc.). Many have standalone `Makefile`s using `clang++ -Ofast -march=native -std=c++20` with precompiled headers. |
| 95 | + |
| 96 | +## Style & Conventions |
| 97 | + |
| 98 | +- `.clang-format` and `.editorconfig` are present — format code before committing |
| 99 | +- This is a header-only library — no `.cpp` source files in `include/` |
| 100 | +- The library targets both freestanding (no OS) and hosted environments |
| 101 | +- Consistent error handling via exceptions only (no `std::error_code` or `std::system_error`) |
| 102 | +- License: Anti-Tivo License (ATL) v1.0 |
0 commit comments