From 2c58b3f804b4cee76a3b21a1be7ce18270da54f8 Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Thu, 16 Feb 2017 11:17:24 -0500 Subject: [PATCH] Remove the dependency on `libc` Recent versions of bindgen use `std::os::raw` over `libc`, but currently `libsqlite3-sys` is overriding that. `std::os::raw` is a subset of `libc` that exports only the relevant type definitions, but not any functions which require additional linking. This enables `libsqlite3-sys` to be more easily used on targets that may not have a libc available (presumably sqlite itself would have been compiled with musl in that case) --- Cargo.toml | 1 - Changelog.md | 1 + libsqlite3-sys/Cargo.toml | 3 --- libsqlite3-sys/build.rs | 1 - libsqlite3-sys/src/error.rs | 2 +- libsqlite3-sys/src/lib.rs | 2 -- src/backup.rs | 2 +- src/error.rs | 2 +- src/functions.rs | 4 ++-- src/lib.rs | 9 ++++----- src/limits.rs | 2 +- src/named_params.rs | 2 +- src/raw_statement.rs | 2 +- src/trace.rs | 2 +- src/types/mod.rs | 5 ++--- tests/config_log.rs | 3 +-- 16 files changed, 17 insertions(+), 26 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4d55031..9f66c8a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,7 +30,6 @@ limits = [] time = "0.1.0" bitflags = "0.7" lru-cache = "0.1.0" -libc = "0.2" chrono = { version = "0.3", optional = true } serde_json = { version = "0.9", optional = true } diff --git a/Changelog.md b/Changelog.md index 5d09688..6fdff7a 100644 --- a/Changelog.md +++ b/Changelog.md @@ -8,6 +8,7 @@ * Clarifies supported SQLite versions. Running with SQLite older than 3.6.8 now panics, and some features will not compile unless a sufficiently-recent SQLite version is used. See the README for requirements of particular features. +* Removes the `libc` dependency in favor of using `std::os::raw` # Version 0.9.5 (2017-01-26) diff --git a/libsqlite3-sys/Cargo.toml b/libsqlite3-sys/Cargo.toml index 64b9ba5..ab47f79 100644 --- a/libsqlite3-sys/Cargo.toml +++ b/libsqlite3-sys/Cargo.toml @@ -15,6 +15,3 @@ bundled = [] bindgen = "0.21" pkg-config = "0.3" gcc = "0.3" - -[dependencies] -libc = "0.2" diff --git a/libsqlite3-sys/build.rs b/libsqlite3-sys/build.rs index ad86aee..a9bf365 100644 --- a/libsqlite3-sys/build.rs +++ b/libsqlite3-sys/build.rs @@ -27,7 +27,6 @@ fn run_bindgen>(header: T) { let mut output = Vec::new(); bindgen::builder() .header(header.clone()) - .ctypes_prefix("::libc") .type_chooser(Box::new(SqliteTypeChooser)) .generate() .expect(&format!("could not run bindgen on header {}", header)) diff --git a/libsqlite3-sys/src/error.rs b/libsqlite3-sys/src/error.rs index 53c5ea9..855cef2 100644 --- a/libsqlite3-sys/src/error.rs +++ b/libsqlite3-sys/src/error.rs @@ -1,4 +1,4 @@ -use libc::c_int; +use std::os::raw::c_int; use std::error; use std::fmt; diff --git a/libsqlite3-sys/src/lib.rs b/libsqlite3-sys/src/lib.rs index 4a228cb..6f619c0 100644 --- a/libsqlite3-sys/src/lib.rs +++ b/libsqlite3-sys/src/lib.rs @@ -1,7 +1,5 @@ #![allow(non_snake_case, non_camel_case_types)] -extern crate libc; - pub use self::error::*; use std::mem; diff --git a/src/backup.rs b/src/backup.rs index 77ba0f6..afa796c 100644 --- a/src/backup.rs +++ b/src/backup.rs @@ -30,7 +30,7 @@ use std::marker::PhantomData; use std::path::Path; use std::ptr; -use libc::c_int; +use std::os::raw::c_int; use std::thread; use std::time::Duration; diff --git a/src/error.rs b/src/error.rs index ada725d..3ef8a2a 100644 --- a/src/error.rs +++ b/src/error.rs @@ -2,7 +2,7 @@ use std::error; use std::fmt; use std::path::PathBuf; use std::str; -use libc::c_int; +use std::os::raw::c_int; use {ffi, errmsg_to_string}; use types::Type; diff --git a/src/functions.rs b/src/functions.rs index 3c35b6f..fb39ca3 100644 --- a/src/functions.rs +++ b/src/functions.rs @@ -54,7 +54,7 @@ use std::ffi::CStr; use std::mem; use std::ptr; use std::slice; -use libc::{c_int, c_char, c_void}; +use std::os::raw::{c_int, c_char, c_void}; use ffi; use ffi::sqlite3_context; @@ -508,7 +508,7 @@ mod test { extern crate regex; use std::collections::HashMap; - use libc::c_double; + use std::os::raw::c_double; use self::regex::Regex; use std::f64::EPSILON; diff --git a/src/lib.rs b/src/lib.rs index f753902..bda3e7c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -52,7 +52,6 @@ //! ``` #![allow(unknown_lints)] -extern crate libc; extern crate libsqlite3_sys as ffi; extern crate lru_cache; #[macro_use] @@ -74,7 +73,7 @@ use std::result; use std::str; use std::sync::{Once, ONCE_INIT}; use std::sync::atomic::{AtomicBool, ATOMIC_BOOL_INIT, Ordering}; -use libc::{c_int, c_char, c_void}; +use std::os::raw::{c_int, c_char, c_void}; use types::{ToSql, ToSqlOutput, FromSql, FromSqlError, ValueRef}; use error::{error_from_sqlite_code, error_from_handle}; @@ -534,7 +533,7 @@ bitflags! { #[doc = "Flags for opening SQLite database connections."] #[doc = "See [sqlite3_open_v2](http://www.sqlite.org/c3ref/open.html) for details."] #[repr(C)] - pub flags OpenFlags: ::libc::c_int { + pub flags OpenFlags: ::std::os::raw::c_int { const SQLITE_OPEN_READ_ONLY = 0x00000001, const SQLITE_OPEN_READ_WRITE = 0x00000002, const SQLITE_OPEN_CREATE = 0x00000004, @@ -742,7 +741,7 @@ impl InnerConnection { Ok(()) } else { let message = errmsg_to_string(&*errmsg); - ffi::sqlite3_free(errmsg as *mut libc::c_void); + ffi::sqlite3_free(errmsg as *mut ::std::os::raw::c_void); Err(error_from_sqlite_code(r, Some(message))) } } @@ -1357,7 +1356,7 @@ mod test { let raw_stmt = { use std::mem; use std::ptr; - use libc::c_int; + use std::os::raw::c_int; use super::str_to_cstring; let raw_db = db.db.borrow_mut().db; diff --git a/src/limits.rs b/src/limits.rs index 5a9866e..d8fc2b0 100644 --- a/src/limits.rs +++ b/src/limits.rs @@ -1,6 +1,6 @@ //! Run-Time Limits -use libc::c_int; +use std::os::raw::c_int; use ffi; pub use ffi::Limit; diff --git a/src/named_params.rs b/src/named_params.rs index f1307f8..d6f8382 100644 --- a/src/named_params.rs +++ b/src/named_params.rs @@ -1,6 +1,6 @@ use std::convert; use std::result; -use libc::c_int; +use std::os::raw::c_int; use {Result, Error, Connection, Statement, MappedRows, AndThenRows, Rows, Row, str_to_cstring}; use types::ToSql; diff --git a/src/raw_statement.rs b/src/raw_statement.rs index adb5396..d25c09f 100644 --- a/src/raw_statement.rs +++ b/src/raw_statement.rs @@ -1,6 +1,6 @@ use std::ffi::CStr; use std::ptr; -use libc::c_int; +use std::os::raw::c_int; use super::ffi; // Private newtype for raw sqlite3_stmts that finalize themselves when dropped. diff --git a/src/trace.rs b/src/trace.rs index 32382a2..a97c0df 100644 --- a/src/trace.rs +++ b/src/trace.rs @@ -1,6 +1,6 @@ //! Tracing and profiling functions. Error and warning log. -use libc::{c_char, c_int, c_void}; +use std::os::raw::{c_char, c_int, c_void}; use std::ffi::{CStr, CString}; use std::mem; use std::ptr; diff --git a/src/types/mod.rs b/src/types/mod.rs index c62e0c2..630db02 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -73,11 +73,10 @@ mod serde_json; /// ## Example /// /// ```rust,no_run -/// # extern crate libc; /// # extern crate rusqlite; /// # use rusqlite::{Connection, Result}; /// # use rusqlite::types::{Null}; -/// # use libc::{c_int}; +/// # use std::os::raw::{c_int}; /// fn main() { /// } /// fn insert_null(conn: &Connection) -> Result { @@ -114,7 +113,7 @@ mod test { use Connection; use Error; - use libc::{c_int, c_double}; + use std::os::raw::{c_int, c_double}; use std::f64::EPSILON; use super::Value; diff --git a/tests/config_log.rs b/tests/config_log.rs index 83a660e..f945210 100644 --- a/tests/config_log.rs +++ b/tests/config_log.rs @@ -3,12 +3,11 @@ #[macro_use] extern crate lazy_static; -extern crate libc; extern crate rusqlite; #[cfg(feature = "trace")] fn main() { - use libc::c_int; + use std::os::raw::c_int; use std::sync::Mutex; lazy_static! {