# LevelDB Extensions

This directory contains C++ extensions that enhance LevelDB with custom functionality beyond the standard API. These extensions are designed to work seamlessly with the Rust bindings through a safe FFI interface.

## Architecture

The extension system follows a layered architecture:

- **C++ Layer** (`extension/src/`): Low-level implementations that integrate directly with LevelDB internals
- **Header Files** (`extension/include/`): C++ headers defining the extension interfaces
- **Rust Bridge** (`src/extension/`): Safe Rust wrappers that provide idiomatic APIs

## Current Extensions

- Logger

## Building Extensions

### Prerequisites
- CMake 3.10 or higher
- C++17 compatible compiler
- LevelDB library and headers
- Google Test Library (Optional, required by tests)

### Build Process

#### To use with Cargo

Extensions are built automatically when using the Rust build system with appropriate feature flags:

```bash
# Build with logger extension
cargo build --features logger
```
#### Makefile

Execute commandline under the root of parent repo

```
make clean-extension
make build-extension
make test-extension
```

#### Manual CMake Build

For manual compilation or debugging, you can build the extensions directly using CMake:

```bash
# Create build directory
mkdir build && cd build

# Configure CMake
cmake .. \
    -DCMAKE_CXX_STANDARD=17 \
    -DCMAKE_CXX_STANDARD_REQUIRED=ON \
    -DLEVELDB_INSTALL_DIR=/path/to/leveldb_static_lib

# Build
cmake --build .
```

To build tests, CMake should be configured with `-DBUILD_TESTS=ON`. There should be an executable `logger_test` in `extension/build` folder built and ready.

### Important: LEVELDB_INSTALL_DIR Parameter

The `LEVELDB_INSTALL_DIR` parameter is crucial for proper extension compilation. It should point to the directory containing:

```
${LEVELDB_INSTALL_DIR}/
├── include/
│   └── leveldb/
│       ├── c.h
│       ├── db.h
│       ├── env.h
│       └── ...
└── lib/
    ├── libleveldb.a
    └── ...
```

When building through the Rust build system, `LEVELDB_INSTALL_DIR` is automatically set to the temporary build directory, which contains the compiled LevelDB library and header files, in `target/`.

## License

Files of `extensions` follow the same license as the main `leveldb-rs-binding` project.
