leveldb-rs-binding 2.2.0

An interface for the LevelDB
Documentation
//! Extension library build module.

use super::{C_STANDARD, CXX_STANDARD};
use crate::boost::BoostBuild;
use crate::linker;
use crate::t3lru::T3lruBuild;
use std::path::{Path, PathBuf};

#[allow(dead_code)]
pub fn build(
    install_dir: &Path,
    build_type: &str,
    leveldb_prefix: &Path,
    t3lru_build: Option<&T3lruBuild>,
    boost_build: Option<&BoostBuild>,
) -> PathBuf {
    println!("[extension] Building");
    let mut config = cmake::Config::new("extension");
    config
        .profile(build_type)
        .define("CMAKE_CXX_STANDARD", CXX_STANDARD)
        .define("CMAKE_C_STANDARD", C_STANDARD)
        .define("CMAKE_INSTALL_LIBDIR", install_dir)
        .define(
            "LEVELDB_INSTALL_DIR",
            leveldb_prefix.join("lib").to_str().unwrap(),
        )
        .define("RUST_USIZE_SIZE", std::mem::size_of::<usize>().to_string())
        .define("BUILD_TESTS", "OFF")
        .cflag(format!("-I{}", leveldb_prefix.join("include").display()))
        .cxxflag(format!("-I{}", leveldb_prefix.join("include").display()));

    // Pass t3lru installation directory if available
    if let Some(t3lru) = t3lru_build {
        config.define("T3LRU_INSTALL_DIR", &t3lru.prefix);
    }

    // Pass Boost include directories (header-only, no build needed)
    if let Some(boost) = boost_build {
        for dir in &boost.include_dirs {
            config.cxxflag(format!("-I{}", dir.display()));
        }
    }

    crate::apply_cmake_flags(&mut config);

    let lib_paths = vec![
        leveldb_prefix
            .join(install_dir.file_name().unwrap())
            .display()
            .to_string(),
    ];
    linker::set_ldflags(&lib_paths);

    let dest_prefix = config.build();
    assert_eq!(
        dest_prefix.join(install_dir.file_name().unwrap()),
        install_dir,
        "CMake should build extensions in provided install_dir"
    );

    dest_prefix
}