From 7606caa82081619bf61cc1fa6aecef2c592b60b2 Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Mon, 6 Apr 2026 17:30:04 +0200 Subject: [PATCH 1/2] Allow SQLite to be linked against dynamically Keeping the default behaviour of SQLite being built statically, so as not to break anyone's workflow, but allowing for downstream packagers to link dynamically against SQLite (where it's fine because that's the point of package managers). Note that SQLite is still *not* enabled by default, thanks to the `?` operator. --- Cargo.toml | 10 ++++++---- build.rs | 12 ++++++------ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 60286287..fd50827a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,15 +23,17 @@ publish.workspace = true [features] default = [ - # "sqlite", + # "sqlite" or "sqlite_system", # "mysql", # "postgresql", ] # Empty to keep compatibility, prefer to set USE_SYSLOG=true enable_syslog = [] +# Please enable at least one of these DB backends. mysql = ["diesel/mysql", "diesel_migrations/mysql"] postgresql = ["diesel/postgres", "diesel_migrations/postgres"] -sqlite = ["diesel/sqlite", "diesel_migrations/sqlite", "dep:libsqlite3-sys"] +sqlite_system = ["diesel/sqlite", "diesel_migrations/sqlite"] +sqlite = ["sqlite_system", "libsqlite3-sys/bundled"] # Alternative to the above, statically linked SQLite into the binary instead of dynamically. # Enable to use a vendored and statically linked openssl vendored_openssl = ["openssl/vendored"] # Enable MiMalloc memory allocator to replace the default malloc @@ -94,8 +96,8 @@ diesel_migrations = "2.3.1" derive_more = { version = "2.1.1", features = ["from", "into", "as_ref", "deref", "display"] } diesel-derive-newtype = "2.1.2" -# Bundled/Static SQLite -libsqlite3-sys = { version = "0.36.0", features = ["bundled"], optional = true } +# SQLite, statically compiled if the `sqlite_bundled` feature is enabled +libsqlite3-sys = { version = "0.36.0", optional = true } # Crypto-related libraries rand = "0.10.0" diff --git a/build.rs b/build.rs index 4a831737..2d1106c2 100644 --- a/build.rs +++ b/build.rs @@ -2,21 +2,21 @@ use std::env; use std::process::Command; fn main() { - // This allow using #[cfg(sqlite)] instead of #[cfg(feature = "sqlite")], which helps when trying to add them through macros - #[cfg(feature = "sqlite")] + // These allow using e.g. #[cfg(mysql)] instead of #[cfg(feature = "mysql")], which helps when trying to add them through macros + #[cfg(feature = "sqlite_system")] // The `sqlite` feature implies this one. println!("cargo:rustc-cfg=sqlite"); #[cfg(feature = "mysql")] println!("cargo:rustc-cfg=mysql"); #[cfg(feature = "postgresql")] println!("cargo:rustc-cfg=postgresql"); - #[cfg(feature = "s3")] - println!("cargo:rustc-cfg=s3"); - - #[cfg(not(any(feature = "sqlite", feature = "mysql", feature = "postgresql")))] + #[cfg(not(any(feature = "sqlite_system", feature = "mysql", feature = "postgresql")))] compile_error!( "You need to enable one DB backend. To build with previous defaults do: cargo build --features sqlite" ); + #[cfg(feature = "s3")] + println!("cargo:rustc-cfg=s3"); + // Use check-cfg to let cargo know which cfg's we define, // and avoid warnings when they are used in the code. println!("cargo::rustc-check-cfg=cfg(sqlite)"); From 4ee45697a08b45c234157d831cf4033805770f65 Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Mon, 6 Apr 2026 18:00:02 +0200 Subject: [PATCH 2/2] Avoid depending on a specific version of SQLite directly We do not access its features directly, rather transitively; it is thus a good idea to defer its version selection to our dependencies. --- Cargo.toml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index fd50827a..596670f6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -97,7 +97,9 @@ derive_more = { version = "2.1.1", features = ["from", "into", "as_ref", "deref" diesel-derive-newtype = "2.1.2" # SQLite, statically compiled if the `sqlite_bundled` feature is enabled -libsqlite3-sys = { version = "0.36.0", optional = true } +# We do not depend on a specific version ourselves, instead that is done by downstream crates; +# this is only to toggle a feature for this crate +libsqlite3-sys = { version = "*", optional = true } # Crypto-related libraries rand = "0.10.0"