Cargo.toml
Overview
This file, Cargo.toml, serves as the manifest for a Rust package named libsqlite3-sys. It specifies the package metadata, dependencies, optional features, and build configuration necessary for compiling and distributing the native bindings to the libsqlite3 library. The file enables Cargo, Rust's package manager and build system, to correctly build, package, and manage this library as part of a larger Rust project or ecosystem.
Package Metadata
The [package] section contains essential metadata describing the crate:
name: The package name, "libsqlite3-sys".
version: The current version,"0.35.0".authors: List of authors, here
"The rusqlite developers".edition: Rust edition used,"2021".repository: URL of the source repository, "https://github.com/rusqlite/rusqlite".
description: A short description of the crate — native bindings to thelibsqlite3library.license: License type,
"MIT".links: The native system library this crate links to, "sqlite3".build: Specifies the build script file, "build.rs".keywords: Array of keywords such as "sqlite",
"sqlcipher","ffi"used for categorization.categories: Categorizes the crate under"external-ffi-bindings".
This metadata governs how the crate is identified and handled by Cargo and package registries.
Features
The [features] section declares optional features that can be enabled or disabled by consumers of the crate. Features allow conditional compilation and inclusion of dependencies or functionality:
default: Activates "min_sqlite_version_3_14_0" by default.bundled: Includes"cc"and"bundled_bindings"for building SQLite from source.bundled-windows: Similar tobundledbut targeted for Windows.bundled-sqlcipher: Enables SQLCipher support, depends onbundled.bundled-sqlcipher-vendored-openssl: Extends SQLCipher support with vendored OpenSSL.buildtime_bindgen: Enables build-time generation of bindings usingbindgen,pkg-config, andvcpkg.sqlcipher: Empty placeholder for enabling SQLCipher support without bundling.min_sqlite_version_3_14_0: Ensures minimum SQLite version 3.14.0 by requiringpkg-configorvcpkg.bundled_bindings: Bundles pre-generated bindings, disabled ifbuildtime_bindgenis enabled.loadable_extension: Adds dependencies for processing SQLite loadable extensions.unlock_notify,column_metadata, preupdate_hook,session: Feature flags that enable support for specific SQLite capabilities introduced in various versions.in_gecko,with-asan, wasm32-wasi-vfs: Additional feature flags for specialized environments or sanitizers.
Usage Example of Features
To enable SQLCipher with vendored OpenSSL at build time, a user may specify:
libsqlite3-sys = { version = "0.35.0", features = ["bundled-sqlcipher-vendored-openssl"] }
This modular feature system allows fine-grained control over binary size, dependencies, and supported SQLite functionality.
Dependencies
The [dependencies] and [build-dependencies] sections list runtime and build-time dependencies respectively.
Runtime Dependencies
openssl-sys: Optional dependency version0.9.103for OpenSSL system bindings, used primarily when SQLCipher with OpenSSL is enabled.
Build Dependencies
bindgen: Optional, version0.72, used for generating Rust FFI bindings at build time with runtime feature enabled.cc: Optional, version1.1.6, used to compile C code such as bundled SQLite sources.pkg-config: Optional, version0.3.19, assists in discovering system-installed SQLite.vcpkg: Optional, version0.2.15, another tool for locating system dependencies.prettyplease,quote,syn: Optional dependencies used for code generation and manipulation in featureloadable_extension.
These dependencies support conditional compilation and building of the crate in various environments and configurations.
Package Metadata for Cargo Machete
The [package.metadata.cargo-machete] section lists dependencies ignored by the cargo-machete tool, which is likely used for dependency analysis or management. It excludes build-time and code-generation related crates such as bindgen, cc, pkg-config, prettyplease, quote, syn, and vcpkg.
Implementation Details and Build Process
The
buildfield points tobuild.rs, a Rust build script executed by Cargo before compiling the crate. This script handles tasks such as generating bindings viabindgen, compiling bundled SQLite sources usingccif enabled, or configuring linking to system SQLite libraries.The presence of features like
buildtime_bindgenindicates that bindings can be generated on the fly during the build, whilebundled_bindingsallows shipping pre-generated bindings for faster builds.The feature flags allow minimal dependencies when only basic linking to system SQLite is required, or full static compilation of SQLite and SQLCipher with vendored dependencies.
The use of
pkg-configandvcpkgassists in locating system-installed libraries in a cross-platform manner.
Interaction with Other Parts of the System
The crate
libsqlite3-sysprovides low-level FFI bindings to SQLite3, which are consumed by higher-level crates such asrusqlite.It interacts with native SQLite libraries either by linking to system-installed binaries or compiling bundled sources.
The feature flags allow this crate to be configured for different deployment environments, e.g., enabling SQLCipher encryption or custom SQLite extensions.
The build dependencies and scripts ensure that the bindings and native code are correctly compiled and linked as part of the Rust build process.
This file configures how the Rust ecosystem manages this native bridge, influencing the build and runtime behavior of dependent crates.
Mermaid Diagram: Feature and Dependency Flowchart
flowchart TD
A[libsqlite3-sys Package]
A --> B[Features]
B --> B1[default: min_sqlite_version_3_14_0]
B --> B2[bundled]
B --> B3[buildtime_bindgen]
B --> B4[sqlcipher]
B --> B5[loadable_extension]
B2 --> C[cc]
B2 --> D[bundled_bindings]
B4 --> E[bundled-sqlcipher]
E --> F[bundled-sqlcipher-vendored-openssl]
C --> G[build.rs]
F --> H[openssl-sys]
G --> I[bindgen]
G --> J[pkg-config]
G --> K[vcpkg]
B5 --> L[prettyplease]
B5 --> M[quote]
B5 --> N[syn]
This diagram represents the hierarchical relationship between the package, its features, and the dependencies involved in building and enabling various capabilities. It shows how features enable specific dependencies and build-time tools, illustrating the conditional compilation structure defined in the Cargo.toml.