frozen_duckdb/lib.rs
1//! # Frozen DuckDB Binary - Drop-in Replacement for duckdb-rs
2//!
3//! This crate provides pre-compiled DuckDB binaries that eliminate the slow
4//! compilation bottleneck in Rust projects using `duckdb-rs`. It achieves
5//! 99% faster build times by using architecture-specific optimized binaries
6//! instead of compiling DuckDB from source.
7//!
8//! ## 🚀 Drop-in Replacement
9//!
10//! **Replace `duckdb-rs` with `frozen-duckdb` for instant 99% faster builds:**
11//!
12//! ```toml
13//! # Before (slow builds): the duckdb-rs crate version matching the target
14//! # DuckDB release. duckdb-rs encodes the bundled DuckDB version as
15//! # 1.MAJOR*10000 + MINOR*100 + PATCH, so a DuckDB 2.0.0 release would be
16//! # encoded as duckdb "1.20000" once duckdb-rs publishes that series.
17//! # (The legacy plain series — e.g. duckdb "1.4.0" = the DuckDB 1.4.x era —
18//! # predates this encoding.)
19//! duckdb = "1.20000"
20//!
21//! # After (99% faster builds)
22//! frozen-duckdb = "2.0.0"
23//! ```
24//!
25//! **No code changes needed** - same API, same functionality, 99% faster builds!
26//!
27//! ## Key Features
28//!
29//! - **🚀 Fast builds**: 99% faster than compiling DuckDB from source
30//! - **🏗️ Architecture-specific**: Optimized binaries for x86_64 and arm64
31//! - **🔧 Drop-in replacement**: Seamless integration with existing projects
32//! - **🧠 Smart detection**: Automatic architecture detection with manual override
33//! - **📦 Minimal dependencies**: Reduces build complexity and download size
34//! - **🔒 Production-ready**: Tested binaries with comprehensive validation
35//!
36//! ## Quick Start
37//!
38//! ### For New Projects
39//! ```bash
40//! # Add frozen-duckdb to your project
41//! cargo add frozen-duckdb
42//!
43//! # Build (99% faster than duckdb-rs!)
44//! cargo build
45//! ```
46//!
47//! ### For Existing Projects
48//! ```bash
49//! # Replace duckdb-rs with frozen-duckdb
50//! cargo remove duckdb
51//! cargo add frozen-duckdb
52//!
53//! # No code changes needed - same API!
54//! cargo build # Now 99% faster
55//! ```
56//!
57//! ## Architecture Detection
58//!
59//! The crate automatically detects your system architecture and selects the
60//! appropriate binary:
61//!
62//! - **x86_64**: Uses `libduckdb_x86_64.dylib` (~112MB measured)
63//! - **arm64/aarch64**: Uses `libduckdb_arm64.dylib` (~112MB measured)
64//! - **Manual override**: Set `ARCH` to steer the `architecture` module's
65//! runtime helpers (`detect`, `get_binary_name`). Build-time binary
66//! selection does not read `ARCH` — frozen-duckdb-builder follows `uname -m`.
67//!
68//! ## Performance Benchmarks
69//!
70//! | Build Type | Before (Source) | After (Pre-built) | Improvement |
71//! |------------|-----------------|-------------------|-------------|
72//! | First Build | 1-2 minutes | 7-10 seconds | 85% faster |
73//! | Incremental | 30 seconds | 0.11 seconds | 99% faster |
74//! | Release | 1-2 minutes | 0.11 seconds | 99% faster |
75//! | Download Size | ~200MB | ~112MB (measured, current dylib) | ~45% smaller |
76//!
77//! ## Integration Examples
78//!
79//! ### Basic Usage (Same API as duckdb-rs)
80//!
81//! ```rust
82//! use frozen_duckdb::{Connection, Result};
83//!
84//! fn main() -> Result<()> {
85//! // Same API as duckdb-rs, but 99% faster builds!
86//! let conn = Connection::open_in_memory()?;
87//!
88//! conn.execute_batch(
89//! "CREATE TABLE users (id INTEGER, name TEXT);
90//! INSERT INTO users VALUES (1, 'Alice'), (2, 'Bob');"
91//! )?;
92//!
93//! let mut stmt = conn.prepare("SELECT name FROM users WHERE id = ?")?;
94//! let name: String = stmt.query_row([1], |row| row.get(0))?;
95//!
96//! println!("User: {}", name); // Prints: User: Alice
97//! Ok(())
98//! }
99//! ```
100//!
101//! ### Performance Benchmarking
102//!
103//! ```rust
104//! use frozen_duckdb::benchmark;
105//!
106//! // Measure build time for an operation
107//! let duration = benchmark::measure_build_time(|| {
108//! // Your build operation here
109//! Ok(())
110//! });
111//!
112//! println!("Build completed in: {:?}", duration);
113//! ```
114//!
115//! ## Safety and Reliability
116//!
117//! - **No unsafe code**: All FFI interactions are handled safely
118//! - **Comprehensive testing**: Unit tests, integration tests, and property tests
119//! - **Error handling**: Clear error messages with actionable guidance
120//! - **Fallback behavior**: Graceful degradation if prebuilt binaries unavailable
121//!
122//! ## Troubleshooting
123//!
124//! ### Common Issues
125//!
126//! 1. **"DUCKDB_LIB_DIR not set"**: Run `source prebuilt/setup_env.sh`
127//! 2. **"No frozen DuckDB binary found"**: Check that binaries exist in prebuilt/
128//! 3. **Architecture mismatch**: Verify your system architecture is supported
129//!
130//! ### Debug Information
131//!
132//! ```bash
133//! # Show system information (INFO-level output requires -v; plain `info`
134//! # is silent at the default WARN verbosity)
135//! cargo run -- -v info
136//!
137//! # Test with verbose output
138//! RUST_LOG=debug cargo test
139//! ```
140//!
141//! ## Contributing
142//!
143//! When contributing to this crate:
144//!
145//! 1. **Run tests multiple times**: `cargo test --all` (at least 3 runs)
146//! 2. **Check performance**: Ensure builds remain <10s for first build
147//! 3. **Update documentation**: Keep examples and benchmarks current
148//! 4. **Validate architecture support**: Test on both x86_64 and arm64
149
150// Re-export modules from separate files
151pub mod architecture;
152pub mod benchmark;
153pub mod env_setup;
154
155// Re-export CLI modules
156pub mod cli;
157
158// Re-export our duckdb module (adapted from duckdb-rs)
159pub mod duckdb;
160
161// Re-export duckdb-rs API for drop-in replacement compatibility
162// This enables frozen-duckdb to be a true drop-in replacement
163pub use duckdb::{
164 // params! is exported at the crate root via #[macro_export] in the
165 // vendored module; params_from_iter comes through the duckdb module
166 params_from_iter,
167 // Appender for bulk inserts
168 Appender,
169 Config,
170 Connection,
171 // Error types
172 Error as DuckDBError,
173 Result as DuckDBResult,
174 Row,
175 Rows,
176 Statement,
177 // Common types
178 ToSql,
179 // Transaction support
180 Transaction,
181};
182
183// Re-export types from duckdb::types for convenience
184pub use duckdb::types::{FromSql, Type, Value};
185
186// duckdb-rs also exposes the arrow crate at its root; keep the same surface
187pub use duckdb::arrow;
188
189// Re-export Result type for convenience (DuckDB's Result, not anyhow)
190pub type Result<T> = DuckDBResult<T>;