|
| 1 | +# Ada Development Guide for Claude |
| 2 | + |
| 3 | +This guide provides instructions for building, testing, and benchmarking the Ada URL parser library using CMake. |
| 4 | + |
| 5 | +## Quick Reference |
| 6 | + |
| 7 | +```bash |
| 8 | +# Build library only (no tests, no benchmarks) |
| 9 | +cmake -B build && cmake --build build |
| 10 | + |
| 11 | +# Build with tests (development checks ENABLED) |
| 12 | +cmake -B build -DADA_TESTING=ON && cmake --build build |
| 13 | +ctest --output-on-failure --test-dir build |
| 14 | + |
| 15 | +# Build with benchmarks (development checks DISABLED for accurate performance) |
| 16 | +cmake -B build -DADA_BENCHMARKS=ON -DADA_USE_UNSAFE_STD_REGEX_PROVIDER=ON -DCMAKE_BUILD_TYPE=Release && cmake --build build |
| 17 | +./build/benchmarks/benchdata # Run main benchmark |
| 18 | + |
| 19 | +# FASTER BUILDS: Use Ninja instead of Make |
| 20 | +cmake -B build -G Ninja -DADA_TESTING=ON && cmake --build build |
| 21 | +cmake -B build -G Ninja -DADA_BENCHMARKS=ON -DADA_USE_UNSAFE_STD_REGEX_PROVIDER=ON -DCMAKE_BUILD_TYPE=Release && cmake --build build |
| 22 | +``` |
| 23 | + |
| 24 | +## Requirements |
| 25 | + |
| 26 | +- C++20 compatible compiler (GCC 12+, LLVM 14+, MSVC 2022+) |
| 27 | +- CMake 3.15+ |
| 28 | +- Git (for fetching test dependencies) |
| 29 | +- Ninja (optional, for faster builds): `sudo apt install ninja-build` on Ubuntu |
| 30 | + |
| 31 | +## Building the Library |
| 32 | + |
| 33 | +### Basic Build (Library Only) |
| 34 | + |
| 35 | +For a minimal build with just the library: |
| 36 | + |
| 37 | +```bash |
| 38 | +cmake -B build |
| 39 | +cmake --build build |
| 40 | +``` |
| 41 | + |
| 42 | +This creates the Ada library without tests or benchmarks. |
| 43 | + |
| 44 | +### Build with Tests |
| 45 | + |
| 46 | +To build with tests enabled: |
| 47 | + |
| 48 | +```bash |
| 49 | +cmake -B build -DADA_TESTING=ON |
| 50 | +cmake --build build |
| 51 | +``` |
| 52 | + |
| 53 | +**Important:** When `ADA_TESTING=ON`, development checks are automatically enabled unless you explicitly build in Release mode with `NDEBUG` defined. Development checks include assertions (`ADA_ASSERT_TRUE`, `ADA_ASSERT_EQUAL`) that validate internal state. |
| 54 | + |
| 55 | +### Build with Benchmarks |
| 56 | + |
| 57 | +To build benchmarks for performance testing: |
| 58 | + |
| 59 | +```bash |
| 60 | +cmake -B build -DADA_BENCHMARKS=ON -DCMAKE_BUILD_TYPE=Release |
| 61 | +cmake --build build |
| 62 | +``` |
| 63 | + |
| 64 | +**Critical:** Always build benchmarks in Release mode (`-DCMAKE_BUILD_TYPE=Release`) to disable development checks. Development assertions significantly impact performance and will give misleading benchmark results. |
| 65 | + |
| 66 | +### Using Local Packages |
| 67 | + |
| 68 | +If you have dependencies (like GoogleTest, Google Benchmark) already installed locally: |
| 69 | + |
| 70 | +```bash |
| 71 | +cmake -B build -DADA_TESTING=ON -DCPM_USE_LOCAL_PACKAGES=ON |
| 72 | +cmake --build build |
| 73 | +``` |
| 74 | + |
| 75 | +## CMake Build Options |
| 76 | + |
| 77 | +| Option | Default | Description | |
| 78 | +|--------|---------|-------------| |
| 79 | +| `ADA_TESTING` | OFF | Enable building tests | |
| 80 | +| `ADA_BENCHMARKS` | OFF | Enable building benchmarks (requires 64-bit) | |
| 81 | +| `ADA_TOOLS` | OFF | Enable building command-line tools | |
| 82 | +| `ADA_BUILD_SINGLE_HEADER_LIB` | OFF | Build from single-header amalgamated files | |
| 83 | +| `ADA_USE_SIMDUTF` | OFF | Enable SIMD-accelerated Unicode via simdutf | |
| 84 | +| `CMAKE_BUILD_TYPE` | - | Set to `Release` for optimized builds, `Debug` for development | |
| 85 | + |
| 86 | +## Running Tests |
| 87 | + |
| 88 | +After building with `-DADA_TESTING=ON`: |
| 89 | + |
| 90 | +```bash |
| 91 | +# Run all tests |
| 92 | +ctest --output-on-failure --test-dir build |
| 93 | + |
| 94 | +# Run specific test executable |
| 95 | +./build/tests/basic_tests |
| 96 | + |
| 97 | +# Run tests with verbose output |
| 98 | +ctest --verbose --test-dir build |
| 99 | +``` |
| 100 | + |
| 101 | +### Development Checks in Tests |
| 102 | + |
| 103 | +Tests run with development checks **enabled by default** (unless built with `-DCMAKE_BUILD_TYPE=Release -DNDEBUG`). This means: |
| 104 | + |
| 105 | +- Assertions are active (`ADA_ASSERT_TRUE`, `ADA_ASSERT_EQUAL`) |
| 106 | +- Internal state validation occurs |
| 107 | +- Performance is slower but catches bugs early |
| 108 | + |
| 109 | +This is the **recommended mode for development**. |
| 110 | + |
| 111 | +## Running Benchmarks |
| 112 | + |
| 113 | +After building with `-DADA_BENCHMARKS=ON`: |
| 114 | + |
| 115 | +```bash |
| 116 | +# Main benchmark comparing against competitors |
| 117 | +./build/benchmarks/benchdata |
| 118 | + |
| 119 | +# Specific benchmarks |
| 120 | +./build/benchmarks/bench # Basic URL parsing benchmarks |
| 121 | +./build/benchmarks/bbc_bench # BBC URLs benchmark |
| 122 | +./build/benchmarks/wpt_bench # Web Platform Tests benchmark |
| 123 | +./build/benchmarks/percent_encode # Percent encoding benchmarks |
| 124 | +``` |
| 125 | + |
| 126 | +### Development Checks in Benchmarks |
| 127 | + |
| 128 | +**Always disable development checks for benchmarks** by building in Release mode: |
| 129 | + |
| 130 | +```bash |
| 131 | +# CORRECT: Benchmarks with development checks disabled |
| 132 | +cmake -B build -DADA_BENCHMARKS=ON -DCMAKE_BUILD_TYPE=Release |
| 133 | +cmake --build build |
| 134 | +./build/benchmarks/benchdata |
| 135 | + |
| 136 | +# WRONG: Don't benchmark with development checks enabled |
| 137 | +cmake -B build -DADA_BENCHMARKS=ON # Missing Release mode! |
| 138 | +``` |
| 139 | + |
| 140 | +Development checks add significant overhead that skews performance measurements. The `ADA_DEVELOPMENT_CHECKS` macro is automatically disabled when: |
| 141 | +- Building with `-DCMAKE_BUILD_TYPE=Release` |
| 142 | +- `NDEBUG` is defined |
| 143 | +- Explicitly set `ADA_DEVELOPMENT_CHECKS=0` |
| 144 | + |
| 145 | +## Complete Development Workflow |
| 146 | + |
| 147 | +### 1. Initial Setup |
| 148 | + |
| 149 | +```bash |
| 150 | +# Clone and enter directory |
| 151 | +cd /path/to/ada |
| 152 | + |
| 153 | +# Create build directory for tests |
| 154 | +cmake -B build -DADA_TESTING=ON |
| 155 | +cmake --build build |
| 156 | +``` |
| 157 | + |
| 158 | +### 2. Development Cycle (with tests) |
| 159 | + |
| 160 | +```bash |
| 161 | +# Make code changes... |
| 162 | + |
| 163 | +# Rebuild (only rebuilds changed files) |
| 164 | +cmake --build build |
| 165 | + |
| 166 | +# Run tests to verify correctness |
| 167 | +ctest --output-on-failure --test-dir build |
| 168 | + |
| 169 | +# Or run specific test |
| 170 | +./build/tests/basic_tests |
| 171 | +``` |
| 172 | + |
| 173 | +### 3. Performance Validation (with benchmarks) |
| 174 | + |
| 175 | +```bash |
| 176 | +# Create separate benchmark build |
| 177 | +cmake -B build-release -DADA_BENCHMARKS=ON -DCMAKE_BUILD_TYPE=Release |
| 178 | +cmake --build build-release |
| 179 | + |
| 180 | +# Run benchmarks |
| 181 | +./build-release/benchmarks/benchdata |
| 182 | + |
| 183 | +# Compare before/after optimizations |
| 184 | +# (stash changes, rebuild, run benchmark, restore, rebuild, run again) |
| 185 | +``` |
| 186 | + |
| 187 | +### 4. Clean Rebuild |
| 188 | + |
| 189 | +```bash |
| 190 | +# Remove build directory and start fresh |
| 191 | +rm -rf build |
| 192 | +cmake -B build -DADA_TESTING=ON |
| 193 | +cmake --build build |
| 194 | +``` |
| 195 | + |
| 196 | +## Understanding Development Checks |
| 197 | + |
| 198 | +### What are Development Checks? |
| 199 | + |
| 200 | +Development checks are compile-time assertions that validate: |
| 201 | +- Function preconditions and postconditions |
| 202 | +- Internal invariants (e.g., `validate()` on URL objects) |
| 203 | +- Argument validity |
| 204 | + |
| 205 | +### When are they Enabled? |
| 206 | + |
| 207 | +Automatically enabled when: |
| 208 | +- `ADA_TESTING=ON` (unless overridden with Release mode) |
| 209 | +- Debug build (`CMAKE_BUILD_TYPE=Debug`) |
| 210 | +- `NDEBUG` is not defined |
| 211 | + |
| 212 | +Automatically disabled when: |
| 213 | +- `CMAKE_BUILD_TYPE=Release` |
| 214 | +- `NDEBUG` is defined |
| 215 | +- Production builds |
| 216 | + |
| 217 | +### Manual Control |
| 218 | + |
| 219 | +```bash |
| 220 | +# Force enable development checks (even in Release) |
| 221 | +cmake -B build -DADA_DEVELOPMENT_CHECKS=1 |
| 222 | + |
| 223 | +# Force disable development checks (even in Debug) |
| 224 | +cmake -B build -DNDEBUG=1 |
| 225 | +``` |
| 226 | + |
| 227 | +## Platform-Specific Notes |
| 228 | + |
| 229 | +### Windows |
| 230 | + |
| 231 | +Specify configuration during build: |
| 232 | + |
| 233 | +```bash |
| 234 | +cmake -B build -DADA_TESTING=ON |
| 235 | +cmake --build build --config Release |
| 236 | +ctest --output-on-failure --test-dir build --config Release |
| 237 | +``` |
| 238 | + |
| 239 | +### macOS/Linux |
| 240 | + |
| 241 | +Standard commands work as documented above. |
| 242 | + |
| 243 | +## Troubleshooting |
| 244 | + |
| 245 | +### Benchmarks are unexpectedly slow |
| 246 | + |
| 247 | +**Cause:** Development checks are enabled. |
| 248 | + |
| 249 | +**Solution:** Rebuild with Release mode: |
| 250 | +```bash |
| 251 | +cmake -B build -DADA_BENCHMARKS=ON -DCMAKE_BUILD_TYPE=Release |
| 252 | +cmake --build build |
| 253 | +``` |
| 254 | + |
| 255 | +### Tests are failing with assertion errors |
| 256 | + |
| 257 | +**Expected behavior** - development checks are catching bugs. Review the assertion message and fix the underlying issue. |
| 258 | + |
| 259 | +### Can't find benchmark executable |
| 260 | + |
| 261 | +**Cause:** Benchmarks not built (32-bit system or not enabled). |
| 262 | + |
| 263 | +**Solution:** |
| 264 | +```bash |
| 265 | +cmake -B build -DADA_BENCHMARKS=ON |
| 266 | +cmake --build build |
| 267 | +ls build/benchmarks/ # Check what was built |
| 268 | +``` |
| 269 | + |
| 270 | +## Additional Resources |
| 271 | + |
| 272 | +- **README.md**: General project overview and API usage |
| 273 | +- **docs/cli.md**: Command-line interface documentation |
| 274 | +- **benchmarks/**: Benchmark source code |
| 275 | +- **tests/**: Test source code |
| 276 | +- **include/ada/**: Library headers |
| 277 | + |
| 278 | +## Summary |
| 279 | + |
| 280 | +| Task | Command | Development Checks | |
| 281 | +|------|---------|-------------------| |
| 282 | +| Library only | `cmake -B build && cmake --build build` | N/A | |
| 283 | +| Testing | `cmake -B build -DADA_TESTING=ON && cmake --build build` | ✅ Enabled | |
| 284 | +| Benchmarking | `cmake -B build -DADA_BENCHMARKS=ON -DCMAKE_BUILD_TYPE=Release && cmake --build build` | ❌ Disabled | |
| 285 | +| Development | `cmake -B build -DADA_TESTING=ON -DCMAKE_BUILD_TYPE=Debug && cmake --build build` | ✅ Enabled | |
0 commit comments