From c86ca314119b391787573dc427e6c6985255cea7 Mon Sep 17 00:00:00 2001 From: LucaCappelletti94 Date: Thu, 1 Oct 2026 14:58:58 +0200 Subject: [PATCH] Enforce native smoke lint policy --- smoke/Cargo.toml | 14 ++++++++++++ smoke/build.rs | 2 ++ smoke/src/bin/interop.rs | 46 +++++++++++++++++++++++++--------------- smoke/src/exchange.rs | 13 +++++++++--- 4 files changed, 55 insertions(+), 20 deletions(-) diff --git a/smoke/Cargo.toml b/smoke/Cargo.toml index 0a469f0..394068b 100644 --- a/smoke/Cargo.toml +++ b/smoke/Cargo.toml @@ -12,3 +12,17 @@ sqlite3mc-src = { path = ".." } [build-dependencies] cc = "1.2.27" sqlite3mc-src = { path = ".." } + +[lints.rust] +missing_docs = "forbid" +unsafe_op_in_unsafe_fn = "deny" +rust_2018_idioms = { level = "warn", priority = -1 } +unreachable_pub = "warn" + +[lints.clippy] +all = { level = "deny", priority = -1 } +pedantic = { level = "warn", priority = -1 } +nursery = { level = "warn", priority = -1 } +cargo = { level = "warn", priority = -1 } +allow_attributes = "deny" +allow_attributes_without_reason = "deny" diff --git a/smoke/build.rs b/smoke/build.rs index aec500b..9e2c6fa 100644 --- a/smoke/build.rs +++ b/smoke/build.rs @@ -1,3 +1,5 @@ +//! Compiles the vendored amalgamation for the native smoke binaries. + fn main() { let source = sqlite3mc_src::source_dir().join(sqlite3mc_src::SOURCE_FILE); println!("cargo:rerun-if-changed={}", source.display()); diff --git a/smoke/src/bin/interop.rs b/smoke/src/bin/interop.rs index 3cef981..7f00152 100644 --- a/smoke/src/bin/interop.rs +++ b/smoke/src/bin/interop.rs @@ -1,53 +1,65 @@ //! `write DIR` creates `native-.db` for every cipher, `read DIR PREFIX` checks the `PREFIX-.db` Wasm wrote. +#[expect( + unreachable_pub, + reason = "The Wasm crate exports this shared module to its integration tests" +)] #[path = "../exchange.rs"] mod exchange; #[expect( - non_camel_case_types, - reason = "SQLite's C names, as sqlite-wasm-rs spells them" + clippy::redundant_pub_crate, + reason = "Restricted FFI visibility satisfies `unreachable_pub` in this binary" )] mod ffi { use std::ffi::{c_char, c_int, c_uchar, c_void}; - pub enum sqlite3 {} - pub enum sqlite3_stmt {} + #[repr(C)] + pub(super) struct sqlite3 { + _private: [u8; 0], + } + + #[repr(C)] + pub(super) struct sqlite3_stmt { + _private: [u8; 0], + } - pub const SQLITE_OK: c_int = 0; - pub const SQLITE_NOTADB: c_int = 26; - pub const SQLITE_ROW: c_int = 100; - pub const SQLITE_OPEN_READWRITE: c_int = 2; - pub const SQLITE_OPEN_CREATE: c_int = 4; + pub(super) const SQLITE_OK: c_int = 0; + pub(super) const SQLITE_NOTADB: c_int = 26; + pub(super) const SQLITE_ROW: c_int = 100; + pub(super) const SQLITE_OPEN_READWRITE: c_int = 2; + pub(super) const SQLITE_OPEN_CREATE: c_int = 4; type ExecCallback = unsafe extern "C" fn(*mut c_void, c_int, *mut *mut c_char, *mut *mut c_char) -> c_int; unsafe extern "C" { - pub fn sqlite3_open_v2( + pub(super) fn sqlite3_open_v2( filename: *const c_char, db: *mut *mut sqlite3, flags: c_int, vfs: *const c_char, ) -> c_int; - pub fn sqlite3_close(db: *mut sqlite3) -> c_int; - pub fn sqlite3_exec( + pub(super) fn sqlite3_close(db: *mut sqlite3) -> c_int; + pub(super) fn sqlite3_exec( db: *mut sqlite3, sql: *const c_char, callback: Option, arg: *mut c_void, errmsg: *mut *mut c_char, ) -> c_int; - pub fn sqlite3_prepare_v2( + pub(super) fn sqlite3_prepare_v2( db: *mut sqlite3, sql: *const c_char, bytes: c_int, stmt: *mut *mut sqlite3_stmt, tail: *mut *const c_char, ) -> c_int; - pub fn sqlite3_step(stmt: *mut sqlite3_stmt) -> c_int; - pub fn sqlite3_column_text(stmt: *mut sqlite3_stmt, column: c_int) -> *const c_uchar; - pub fn sqlite3_finalize(stmt: *mut sqlite3_stmt) -> c_int; - pub fn sqlite3_errmsg(db: *mut sqlite3) -> *const c_char; + pub(super) fn sqlite3_step(stmt: *mut sqlite3_stmt) -> c_int; + pub(super) fn sqlite3_column_text(stmt: *mut sqlite3_stmt, column: c_int) + -> *const c_uchar; + pub(super) fn sqlite3_finalize(stmt: *mut sqlite3_stmt) -> c_int; + pub(super) fn sqlite3_errmsg(db: *mut sqlite3) -> *const c_char; } } diff --git a/smoke/src/exchange.rs b/smoke/src/exchange.rs index ef3ccd3..d10d787 100644 --- a/smoke/src/exchange.rs +++ b/smoke/src/exchange.rs @@ -44,8 +44,9 @@ impl Db { let mut handle = std::ptr::null_mut(); let flags = ffi::SQLITE_OPEN_READWRITE | ffi::SQLITE_OPEN_CREATE; // `c_name` outlives the call, and SQLite copies it. - let rc = - unsafe { ffi::sqlite3_open_v2(c_name.as_ptr(), &mut handle, flags, std::ptr::null()) }; + let rc = unsafe { + ffi::sqlite3_open_v2(c_name.as_ptr(), &raw mut handle, flags, std::ptr::null()) + }; let db = Self(handle, name.to_owned()); assert_eq!(rc, ffi::SQLITE_OK, "{name}: {}", db.error()); for pragma in pragmas { @@ -80,7 +81,13 @@ impl Db { let mut stmt = std::ptr::null_mut(); // `c_sql` outlives the call, which reads it up to its NUL. let rc = unsafe { - ffi::sqlite3_prepare_v2(self.0, c_sql.as_ptr(), -1, &mut stmt, std::ptr::null_mut()) + ffi::sqlite3_prepare_v2( + self.0, + c_sql.as_ptr(), + -1, + &raw mut stmt, + std::ptr::null_mut(), + ) }; assert_eq!(rc, ffi::SQLITE_OK, "{}: {sql}: {}", self.1, self.error()); // `stmt` was just prepared, and the text is copied before it is finalized.