|
| 1 | +# Libfork Copilot Instructions |
| 2 | + |
| 3 | +## Project Overview |
| 4 | + |
| 5 | +**libfork** is a continuation-stealing coroutine-tasking library implementing |
| 6 | +strict fork-join parallelism using C++20 coroutines. |
| 7 | + |
| 8 | +- **Type**: C++ library with module/`import std` support |
| 9 | +- **Languages**: C++23 |
| 10 | + |
| 11 | +## Critical Build Requirements |
| 12 | + |
| 13 | +### Compiler & Module Support |
| 14 | + |
| 15 | +This project **requires C++23 `import std`** and **MUST** use the appropriate |
| 16 | +toolchain file: |
| 17 | + |
| 18 | +- **MacOS**: Use `-DCMAKE_TOOLCHAIN_FILE=cmake/llvm-brew-toolchain.cmake` |
| 19 | +- **Linux**: Use `-DCMAKE_TOOLCHAIN_FILE=cmake/gcc-brew-toolchain.cmake` |
| 20 | + |
| 21 | +**Common Error**: Without the toolchain file, CMake will fail. |
| 22 | + |
| 23 | +**Always include the toolchain file** in configure commands. |
| 24 | + |
| 25 | +### Dependencies (Homebrew) |
| 26 | + |
| 27 | +Make sure Homebrew is installed and `brew` is in your `PATH`: |
| 28 | + |
| 29 | +```bash |
| 30 | +brew --version |
| 31 | +``` |
| 32 | + |
| 33 | +**Required for building/testing:** |
| 34 | + |
| 35 | +- `cmake` |
| 36 | +- `ninja` |
| 37 | +- `catch2` |
| 38 | +- `google-benchmark` |
| 39 | +- `clang-format` |
| 40 | +- `codespell` |
| 41 | + |
| 42 | +If on MacOS, also require: |
| 43 | + |
| 44 | +- `llvm` |
| 45 | + |
| 46 | +If on Linux, also require: |
| 47 | + |
| 48 | +- `gcc` |
| 49 | +- `binutils` |
| 50 | + |
| 51 | +Install all at once (MacOS): |
| 52 | + |
| 53 | +```bash |
| 54 | +brew install cmake ninja catch2 google-benchmark clang-format codespell llvm |
| 55 | +``` |
| 56 | + |
| 57 | +Install all at once (Linux): |
| 58 | + |
| 59 | +```bash |
| 60 | +brew install cmake ninja catch2 google-benchmark clang-format codespell gcc binutils |
| 61 | +``` |
| 62 | + |
| 63 | +## Build & Test Workflow |
| 64 | + |
| 65 | +### 1. Configure |
| 66 | + |
| 67 | +Always use presets with the toolchain file: |
| 68 | + |
| 69 | +```bash |
| 70 | +cmake --preset <preset-name> -DCMAKE_TOOLCHAIN_FILE=cmake/<toolchain>.cmake |
| 71 | +``` |
| 72 | + |
| 73 | +**Relevant available presets** (from `CMakePresets.json`): |
| 74 | + |
| 75 | +- `ci-hardened` - Debug build with warnings and hardening flags |
| 76 | +- `ci-release` - Optimized release build |
| 77 | + |
| 78 | +All presets enable developer mode (`libfork_DEV_MODE=ON`) and use Ninja generator. |
| 79 | + |
| 80 | +You should use the `ci-hardened` preset for development/testing and |
| 81 | +`ci-release` for benchmarking. |
| 82 | + |
| 83 | +### 2. Build |
| 84 | + |
| 85 | +```bash |
| 86 | +cmake --build --preset <preset-name> |
| 87 | +``` |
| 88 | + |
| 89 | +**Build warnings** (expected and safe): |
| 90 | + |
| 91 | +- "It is recommended to build benchmarks in Release mode" - only relevant for `ci-hardened` |
| 92 | +- CMake experimental `import std;` warning - expected for C++23 modules |
| 93 | + |
| 94 | +### 3. Test |
| 95 | + |
| 96 | +```bash |
| 97 | +ctest --preset <preset-name> |
| 98 | +``` |
| 99 | + |
| 100 | +All tests should pass. If tests fail, check that: |
| 101 | + |
| 102 | +- Configuration used the correct toolchain file |
| 103 | +- Build completed without errors |
| 104 | +- Any changes you have made are correct |
| 105 | + |
| 106 | +## Linting & Validation |
| 107 | + |
| 108 | +The CI runs two linting tools that you should run before committing: |
| 109 | + |
| 110 | +### codespell (spelling) |
| 111 | + |
| 112 | +```bash |
| 113 | +codespell |
| 114 | +``` |
| 115 | + |
| 116 | +Config: `.codespellrc` (ignores: build/, .git/, etc.) |
| 117 | +Should produce no output if passing. |
| 118 | + |
| 119 | +### clang-format (code formatting) |
| 120 | + |
| 121 | +```bash |
| 122 | +find src include test benchmark/src -name "*.cpp" -o -name "*.hpp" -o -name "*.cxx" | xargs clang-format --dry-run --Werror |
| 123 | +``` |
| 124 | + |
| 125 | +Config: `.clang-format` (110 column limit, specific style) |
| 126 | +Should produce no output if passing. |
| 127 | + |
| 128 | +**To auto-fix formatting**: |
| 129 | + |
| 130 | +```bash |
| 131 | +find src include test benchmark/src -name "*.cpp" -o -name "*.hpp" -o -name "*.cxx" | xargs clang-format -i |
| 132 | +``` |
| 133 | + |
| 134 | +## Project Structure |
| 135 | + |
| 136 | +### Source Layout |
| 137 | + |
| 138 | +```sh |
| 139 | +libfork/ |
| 140 | +├── cmake/ # CMake utilities |
| 141 | +├── include/libfork/**/*.hpp # Public headers |
| 142 | +├── src/**/ # Module and source files |
| 143 | +│ ├── *.cxx # Module files |
| 144 | +│ └── *.cpp # Source files |
| 145 | +├── test/src/**/ # Test suite (Catch2) |
| 146 | +│ └── *.cpp # Test source files |
| 147 | +├── benchmark/src/ # Benchmarking suite (google-benchmark) |
| 148 | +│ └── libfork_benchmark/ # Merged source/header files for benchmarks |
| 149 | +│ └── fib/ # Each benchmark in its own sub-directory |
| 150 | +│ ├── *.hpp # Benchmark header files |
| 151 | +│ └── *.cpp # Benchmark source files |
| 152 | +├── .github/workflows/ # CI workflows |
| 153 | +│ ├── linux.yml # Linux builds |
| 154 | +│ ├── macos.yml # MacOS builds |
| 155 | +│ ├── lint.yml # Linting |
| 156 | +│ └── linear.yml # Enforces linear history (no merge commits) |
| 157 | +└── CMakeLists.txt # Main build configuration |
| 158 | +``` |
| 159 | + |
| 160 | +## Workflows |
| 161 | + |
| 162 | +### Workflow Command Pattern |
| 163 | + |
| 164 | +All workflows follow this pattern: |
| 165 | + |
| 166 | +```yaml |
| 167 | +- Install Dependencies: brew install ... |
| 168 | +- Configure: cmake --preset <preset> -DCMAKE_TOOLCHAIN_FILE=<toolchain>.cmake |
| 169 | +- Build: cmake --build --preset <preset> |
| 170 | +- Test: ctest --preset <preset> |
| 171 | +``` |
| 172 | +
|
| 173 | +## Common Development Tasks |
| 174 | +
|
| 175 | +### Making Code Changes |
| 176 | +
|
| 177 | +1. **Modify source files** in `src/`, `include/`, `test/`, or `benchmark/` |
| 178 | +2. **Rebuild**: `cmake --build --preset <your-preset>` |
| 179 | +3. **Test**: `ctest --preset <your-preset>` |
| 180 | +4. **Lint**: Run codespell and clang-format checks |
| 181 | + |
| 182 | +#### Adding/removing files from `src/` or `include/` |
| 183 | + |
| 184 | +- Update the root `CMakeLists.txt` with new/removed files. |
| 185 | + |
| 186 | +#### Adding/removing files from `benchmark/src/` |
| 187 | + |
| 188 | +- Update `benchmark/CMakeLists.txt` with new/removed files. |
| 189 | + |
| 190 | +### Adding Tests |
| 191 | + |
| 192 | +Strive to add tests for new features/bug fixes. |
| 193 | + |
| 194 | +- Add `.cpp` files to `test/src/` |
| 195 | +- Tests auto-discovered by CMake (GLOB_RECURSE) |
| 196 | +- Links against `libfork::libfork` and `Catch2::Catch2WithMain` |
| 197 | +- Uses `cxx_std_23` feature requirement |
| 198 | + |
| 199 | +### Modifying Build Configuration |
| 200 | + |
| 201 | +**Warning**: Module-related changes are complex. Test thoroughly with clean builds. |
| 202 | + |
| 203 | +## Troubleshooting |
| 204 | + |
| 205 | +### Build Failures |
| 206 | + |
| 207 | +**Problem**: Configuration/Build fails after adding/removing files or modifying CMakeLists.txt |
| 208 | +**Solution**: Try a clean build directory: |
| 209 | + |
| 210 | +```bash |
| 211 | +rm -rf build/ |
| 212 | +``` |
| 213 | + |
| 214 | +**Problem**: "compiler does not provide a way to discover the import graph" |
| 215 | +**Solution**: Add `-DCMAKE_TOOLCHAIN_FILE=cmake/llvm-brew-toolchain.cmake` to configure |
| 216 | + |
| 217 | +**Problem**: "Could not find 'brew' executable" |
| 218 | +**Solution**: Install Homebrew |
| 219 | + |
| 220 | +**Problem**: "Could not automatically find libc++.modules.json" |
| 221 | +**Solution**: Ensure LLVM is installed via Homebrew; toolchain auto-detects the path |
| 222 | + |
| 223 | +### Linting Failures |
| 224 | + |
| 225 | +**Problem**: clang-format errors |
| 226 | +**Solution**: Run fix command above to auto-format code |
| 227 | + |
| 228 | +**Problem**: codespell errors |
| 229 | +**Solution**: Fix typos or add to ignore list in `.codespellrc` if false positive |
0 commit comments