Repository: libsql/libsql
File: libsql-ffi/build.rs (Rust)

Code before:
        .flag("-DHAVE_USLEEP=1")
        .flag("-D_POSIX_THREAD_SAFE_FUNCTIONS") // cross compile with MinGW
        .warnings(false);

    println!("cargo:rerun-if-env-changed=LIBSQLITE3_FLAGS");

    cfg.compile(LIB_NAME);

    println!("cargo:lib_dir={out_dir}");
}

fn copy_multiple_ciphers(out_dir: &str, out_path: &Path) {
    let dylib = format!("{out_dir}/sqlite3mc/libsqlite3mc_static.a");
    if !Path::new(&dylib).exists() {
        build_multiple_ciphers(out_path);
    }

    std::fs::copy(dylib, format!("{out_dir}/libsqlite3mc.a")).unwrap();
    println!("cargo:rustc-link-lib=static=sqlite3mc");
    println!("cargo:rustc-link-search={out_dir}");
}

fn build_multiple_ciphers(out_path: &Path) {
    let target = env::var("TARGET").unwrap();
    let bindgen_rs_path = if cfg!(feature = "session") {
        "bundled/bindings/session_bindgen.rs"
    } else {
        "bundled/bindings/bindgen.rs"
    };
    if std::env::var("LIBSQL_DEV").is_ok() {
        let header = HeaderLocation::FromPath(format!("{BUNDLED_DIR}/src/sqlite3.h"));
        bindings::write_to_out_dir(header, bindgen_rs_path.as_ref());
    }
    let dir = env!("CARGO_MANIFEST_DIR");

    std::fs::copy(format!("{dir}/{bindgen_rs_path}"), out_path).unwrap();

    std::fs::copy(
        (BUNDLED_DIR.as_ref() as &Path)
            .join("src")
            .join("sqlite3.c"),
        (BUNDLED_DIR.as_ref() as &Path)
            .join("SQLite3MultipleCiphers")
            .join("src")
            .join("sqlite3.c"),
    )
    .unwrap();

    let bundled_dir = fs::canonicalize(BUNDLED_DIR)
        .unwrap()
        .join("SQLite3MultipleCiphers");

Review comment (suggestion):
They will however require changes to compile for android as I was having errors on Cmake when trying to compile against sqlcipher.

Code after:
        .flag("-DSQLITE_ENABLE_MEMORY_MANAGEMENT")
        .flag("-DSQLITE_ENABLE_RTREE")
        .flag("-DSQLITE_ENABLE_STAT2")
        .flag("-DSQLITE_ENABLE_STAT4")
        .flag("-DSQLITE_SOUNDEX")
        .flag("-DSQLITE_THREADSAFE=1")
        .flag("-DSQLITE_USE_URI")
        .flag("-DHAVE_USLEEP=1")
        .flag("-D_POSIX_THREAD_SAFE_FUNCTIONS") // cross compile with MinGW
        .warnings(false);

    if cfg!(feature = "wasmtime-bindings") {
        cfg.flag("-DLIBSQL_ENABLE_WASM_RUNTIME=1");
    }

    if cfg!(feature = "bundled-sqlcipher") {
        cfg.flag("-DSQLITE_HAS_CODEC").flag("-DSQLITE_TEMP_STORE=2");

        let target = env::var("TARGET").unwrap();
        let host = env::var("HOST").unwrap();

        let is_windows = host.contains("windows") && target.contains("windows");
        let is_apple = host.contains("apple") && target.contains("apple");

        let lib_dir = env("OPENSSL_LIB_DIR").map(PathBuf::from);
        let inc_dir = env("OPENSSL_INCLUDE_DIR").map(PathBuf::from);
        let mut use_openssl = false;

        let (lib_dir, inc_dir) = match (lib_dir, inc_dir) {
            (Some(lib_dir), Some(inc_dir)) => {
                use_openssl = true;
                (lib_dir, inc_dir)
            }
            (lib_dir, inc_dir) => match find_openssl_dir(&host, &target) {
                None => {
                    if is_windows && !cfg!(feature = "bundled-sqlcipher-vendored-openssl") {
                        panic!("Missing environment variable OPENSSL_DIR or OPENSSL_DIR is not set")
                    } else {
                        (PathBuf::new(), PathBuf::new())
                    }
                }
                Some(openssl_dir) => {
                    let lib_dir = lib_dir.unwrap_or_else(|| openssl_dir.join("lib"));
                    let inc_dir = inc_dir.unwrap_or_else(|| openssl_dir.join("include"));

                    assert!(
                        Path::new(&lib_dir).exists(),
                        "OpenSSL library directory does not exist: {}",
                        lib_dir.to_string_lossy()
                    );