From 1d02e1ac4cf5f7e64a64c7f4a55bab35f5087b21 Mon Sep 17 00:00:00 2001 From: Fabio Valentini Date: Tue, 9 Apr 2024 18:30:49 +0200 Subject: [PATCH] Update to version 0.28.0; Fixes RHBZ#2181816 --- .gitignore | 1 + ...enable-building-with-bindgen-and-pkg.patch | 453 +++++++++++++----- libsqlite3-sys-fix-metadata.diff | 54 ++- rust-libsqlite3-sys.spec | 59 +-- rust2rpm.conf | 8 - rust2rpm.toml | 11 + sources | 2 +- 7 files changed, 376 insertions(+), 212 deletions(-) delete mode 100644 rust2rpm.conf create mode 100644 rust2rpm.toml diff --git a/.gitignore b/.gitignore index 46245e4..c2bbf40 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ /libsqlite3-sys-0.23.1.crate /libsqlite3-sys-0.23.2.crate /libsqlite3-sys-0.25.2.crate +/libsqlite3-sys-0.28.0.crate diff --git a/0001-unconditionally-enable-building-with-bindgen-and-pkg.patch b/0001-unconditionally-enable-building-with-bindgen-and-pkg.patch index 6caf808..01ebe99 100644 --- a/0001-unconditionally-enable-building-with-bindgen-and-pkg.patch +++ b/0001-unconditionally-enable-building-with-bindgen-and-pkg.patch @@ -1,17 +1,17 @@ -From ca89ee36a1a2bedded5d4fbde46be8b680755c35 Mon Sep 17 00:00:00 2001 +From 2acd3859743c32d54e1b2b7458fef3f64b4f2aa9 Mon Sep 17 00:00:00 2001 From: Fabio Valentini -Date: Wed, 1 Mar 2023 15:18:10 +0100 +Date: Tue, 9 Apr 2024 18:24:38 +0200 Subject: [PATCH] unconditionally enable building with bindgen and pkg-config --- - build.rs | 467 +------------------------------------------------------ - 1 file changed, 8 insertions(+), 459 deletions(-) + build.rs | 630 ++----------------------------------------------------- + 1 file changed, 16 insertions(+), 614 deletions(-) diff --git a/build.rs b/build.rs -index e154a8d..15f0430 100644 +index 64f228b..6237720 100644 --- a/build.rs +++ b/build.rs -@@ -1,312 +1,14 @@ +@@ -1,328 +1,14 @@ use std::env; use std::path::Path; @@ -39,6 +39,16 @@ index e154a8d..15f0430 100644 -fn is_compiler(compiler_name: &str) -> bool { - env::var("CARGO_CFG_TARGET_ENV").map_or(false, |v| v == compiler_name) -} +- +-/// Copy bindgen file from `dir` to `out_path`. +-fn copy_bindings>(dir: &str, bindgen_name: &str, out_path: T) { +- let from = if cfg!(feature = "loadable_extension") { +- format!("{dir}/{bindgen_name}_ext.rs") +- } else { +- format!("{dir}/{bindgen_name}.rs") +- }; +- std::fs::copy(from, out_path).expect("Could not copy bindings to output directory"); +-} - fn main() { let out_dir = env::var("OUT_DIR").unwrap(); @@ -46,11 +56,16 @@ index e154a8d..15f0430 100644 - if cfg!(feature = "in_gecko") { - // When inside mozilla-central, we are included into the build with - // sqlite3.o directly, so we don't want to provide any linker arguments. -- std::fs::copy("sqlite3/bindgen_bundled_version.rs", out_path) -- .expect("Could not copy bindings to output directory"); +- copy_bindings("sqlite3", "bindgen_bundled_version", out_path); - return; - } -- if cfg!(all( +- +- println!("cargo:rerun-if-env-changed=LIBSQLITE3_SYS_USE_PKG_CONFIG"); +- if env::var_os("LIBSQLITE3_SYS_USE_PKG_CONFIG").map_or(false, |s| s != "0") +- || cfg!(feature = "loadable_extension") +- { +- build_linked::main(&out_dir, &out_path); +- } else if cfg!(all( - feature = "sqlcipher", - not(feature = "bundled-sqlcipher") - )) { @@ -106,21 +121,18 @@ index e154a8d..15f0430 100644 - #[cfg(feature = "buildtime_bindgen")] - { - use super::{bindings, HeaderLocation}; -- let header = HeaderLocation::FromPath(format!("{}/sqlite3.h", lib_name)); +- let header = HeaderLocation::FromPath(lib_name.to_owned()); - bindings::write_to_out_dir(header, out_path); - } - #[cfg(not(feature = "buildtime_bindgen"))] - { -- use std::fs; -- fs::copy(format!("{}/bindgen_bundled_version.rs", lib_name), out_path) -- .expect("Could not copy bindings to output directory"); +- super::copy_bindings(lib_name, "bindgen_bundled_version", out_path); - } -- // println!("cargo:rerun-if-changed=sqlite3/sqlite3.c"); -- // println!("cargo:rerun-if-changed=sqlcipher/sqlite3.c"); -- println!("cargo:rerun-if-changed={}/sqlite3.c", lib_name); +- println!("cargo:include={}/{lib_name}", env!("CARGO_MANIFEST_DIR")); +- println!("cargo:rerun-if-changed={lib_name}/sqlite3.c"); - println!("cargo:rerun-if-changed=sqlite3/wasm32-wasi-vfs.c"); - let mut cfg = cc::Build::new(); -- cfg.file(format!("{}/sqlite3.c", lib_name)) +- cfg.file(format!("{lib_name}/sqlite3.c")) - .flag("-DSQLITE_CORE") - .flag("-DSQLITE_DEFAULT_FOREIGN_KEYS=1") - .flag("-DSQLITE_ENABLE_API_ARMOR") @@ -195,16 +207,10 @@ index e154a8d..15f0430 100644 - cfg.include(env::var("DEP_OPENSSL_INCLUDE").unwrap()); - // cargo will resolve downstream to the static lib in - // openssl-sys -- } else if is_windows { -- // Windows without `-vendored-openssl` takes this to link against a prebuilt -- // OpenSSL lib -- cfg.include(inc_dir.to_string_lossy().as_ref()); -- let lib = lib_dir.join("libcrypto.lib"); -- cfg.flag(lib.to_string_lossy().as_ref()); - } else if use_openssl { - cfg.include(inc_dir.to_string_lossy().as_ref()); -- // branch not taken on Windows, just `crypto` is fine. -- println!("cargo:rustc-link-lib=dylib=crypto"); +- let lib_name = if is_windows { "libcrypto" } else { "crypto" }; +- println!("cargo:rustc-link-lib=dylib={}", lib_name); - println!("cargo:rustc-link-search={}", lib_dir.to_string_lossy()); - } else if is_apple { - cfg.flag("-DSQLCIPHER_CRYPTO_CC"); @@ -255,11 +261,16 @@ index e154a8d..15f0430 100644 - if !win_target() { - cfg.flag("-DHAVE_LOCALTIME_R"); - } -- // Target wasm32-wasi can't compile the default VFS -- if is_compiler("wasm32-wasi") { -- cfg.flag("-DSQLITE_OS_OTHER") +- if env::var("TARGET").map_or(false, |v| v == "wasm32-wasi") { +- cfg.flag("-USQLITE_THREADSAFE") +- .flag("-DSQLITE_THREADSAFE=0") - // https://github.com/rust-lang/rust/issues/74393 -- .flag("-DLONGDOUBLE_TYPE=double"); +- .flag("-DLONGDOUBLE_TYPE=double") +- .flag("-D_WASI_EMULATED_MMAN") +- .flag("-D_WASI_EMULATED_GETPID") +- .flag("-D_WASI_EMULATED_SIGNAL") +- .flag("-D_WASI_EMULATED_PROCESS_CLOCKS"); +- - if cfg!(feature = "wasm32-wasi-vfs") { - cfg.file("sqlite3/wasm32-wasi-vfs.c"); - } @@ -275,21 +286,26 @@ index e154a8d..15f0430 100644 - } - - if let Ok(limit) = env::var("SQLITE_MAX_VARIABLE_NUMBER") { -- cfg.flag(&format!("-DSQLITE_MAX_VARIABLE_NUMBER={}", limit)); +- cfg.flag(&format!("-DSQLITE_MAX_VARIABLE_NUMBER={limit}")); - } - println!("cargo:rerun-if-env-changed=SQLITE_MAX_VARIABLE_NUMBER"); - - if let Ok(limit) = env::var("SQLITE_MAX_EXPR_DEPTH") { -- cfg.flag(&format!("-DSQLITE_MAX_EXPR_DEPTH={}", limit)); +- cfg.flag(&format!("-DSQLITE_MAX_EXPR_DEPTH={limit}")); - } - println!("cargo:rerun-if-env-changed=SQLITE_MAX_EXPR_DEPTH"); - +- if let Ok(limit) = env::var("SQLITE_MAX_COLUMN") { +- cfg.flag(&format!("-DSQLITE_MAX_COLUMN={limit}")); +- } +- println!("cargo:rerun-if-env-changed=SQLITE_MAX_COLUMN"); +- - if let Ok(extras) = env::var("LIBSQLITE3_FLAGS") { - for extra in extras.split_whitespace() { - if extra.starts_with("-D") || extra.starts_with("-U") { - cfg.flag(extra); - } else if extra.starts_with("SQLITE_") { -- cfg.flag(&format!("-D{}", extra)); +- cfg.flag(&format!("-D{extra}")); - } else { - panic!("Don't understand {} in LIBSQLITE3_FLAGS", extra); - } @@ -299,13 +315,13 @@ index e154a8d..15f0430 100644 - - cfg.compile(lib_name); - -- println!("cargo:lib_dir={}", out_dir); +- println!("cargo:lib_dir={out_dir}"); - } - - fn env(name: &str) -> Option { - let prefix = env::var("TARGET").unwrap().to_uppercase().replace('-', "_"); -- let prefixed = format!("{}_{}", prefix, name); -- let var = env::var_os(&prefixed); +- let prefixed = format!("{prefix}_{name}"); +- let var = env::var_os(prefixed); - - match var { - None => env::var_os(name), @@ -326,25 +342,50 @@ index e154a8d..15f0430 100644 "SQLCIPHER" } else { "SQLITE3" -@@ -314,10 +16,8 @@ fn env_prefix() -> &'static str { +@@ -330,7 +16,7 @@ fn env_prefix() -> &'static str { } fn lib_name() -> &'static str { - if cfg!(any(feature = "sqlcipher", feature = "bundled-sqlcipher")) { + if cfg!(feature = "sqlcipher") { "sqlcipher" -- } else if cfg!(all(windows, feature = "winsqlite3")) { -- "winsqlite3" } else { "sqlite3" +@@ -351,27 +37,14 @@ impl From for String { + let mut header = env::var(format!("{prefix}_INCLUDE_DIR")).unwrap_or_else(|_| { + panic!("{prefix}_INCLUDE_DIR must be set if {prefix}_LIB_DIR is set") + }); +- header.push_str(if cfg!(feature = "loadable_extension") { +- "/sqlite3ext.h" +- } else { +- "/sqlite3.h" +- }); ++ header.push_str("/sqlite3.h"); + header + } +- HeaderLocation::Wrapper => if cfg!(feature = "loadable_extension") { +- "wrapper_ext.h" +- } else { +- "wrapper.h" +- } +- .into(), ++ HeaderLocation::Wrapper => "wrapper.h".into(), + HeaderLocation::FromPath(path) => format!( + "{}/{}", + path, +- if cfg!(feature = "loadable_extension") { +- "sqlite3ext.h" +- } else { +- "sqlite3.h" +- } ++ "sqlite3.h", + ), + } } -@@ -350,45 +50,19 @@ impl From for String { - } +@@ -381,39 +54,19 @@ mod build_linked { + #[cfg(feature = "vcpkg")] + extern crate vcpkg; - mod build_linked { -- #[cfg(feature = "vcpkg")] -- extern crate vcpkg; -- - use super::{bindings, env_prefix, is_compiler, lib_name, win_target, HeaderLocation}; + use super::{bindings, env_prefix, lib_name, HeaderLocation}; use std::env; @@ -364,17 +405,14 @@ index e154a8d..15f0430 100644 - // on buildtime_bindgen instead, but this is still supported as we - // have runtime version checks and there are good reasons to not - // want to run bindgen. -- std::fs::copy( -- format!("{}/bindgen_bundled_version.rs", lib_name()), -- out_path, -- ) -- .expect("Could not copy bindings to output directory"); +- super::copy_bindings(lib_name(), "bindgen_bundled_version", out_path); - } else { - bindings::write_to_out_dir(header, out_path); - } + bindings::write_to_out_dir(header, out_path); } +- #[cfg(not(feature = "loadable_extension"))] fn find_link_mode() -> &'static str { - // If the user specifies SQLITE3_STATIC (or SQLCIPHER_STATIC), do static - // linking, unless it's explicitly set to 0. @@ -388,7 +426,7 @@ index e154a8d..15f0430 100644 // Prints the necessary cargo link commands and returns the path to the header. fn find_sqlite() -> HeaderLocation { let link_lib = lib_name(); -@@ -396,9 +70,6 @@ mod build_linked { +@@ -421,15 +74,11 @@ mod build_linked { println!("cargo:rerun-if-env-changed={}_INCLUDE_DIR", env_prefix()); println!("cargo:rerun-if-env-changed={}_LIB_DIR", env_prefix()); println!("cargo:rerun-if-env-changed={}_STATIC", env_prefix()); @@ -398,19 +436,21 @@ index e154a8d..15f0430 100644 // dependents can access `DEP_SQLITE3_LINK_TARGET` (`sqlite3` being the // `links=` value in our Cargo.toml) to get this value. This might be -@@ -406,11 +77,6 @@ mod build_linked { + // useful if you need to ensure whatever crypto library sqlcipher relies // on is available, for example. - println!("cargo:link-target={}", link_lib); +- #[cfg(not(feature = "loadable_extension"))] + println!("cargo:link-target={link_lib}"); -- if win_target() && cfg!(feature = "winsqlite3") { -- println!("cargo:rustc-link-lib=dylib={}", link_lib); -- return HeaderLocation::Wrapper; -- } -- // Allow users to specify where to find SQLite. - if let Ok(dir) = env::var(format!("{}_LIB_DIR", env_prefix())) { +@@ -437,7 +86,6 @@ mod build_linked { // Try to use pkg-config to determine link commands -@@ -424,10 +90,6 @@ mod build_linked { + let pkgconfig_path = Path::new(&dir).join("pkgconfig"); + env::set_var("PKG_CONFIG_PATH", pkgconfig_path); +- #[cfg(not(feature = "loadable_extension"))] + if pkg_config::Config::new().probe(link_lib).is_err() { + // Otherwise just emit the bare minimum link commands. + println!("cargo:rustc-link-lib={}={link_lib}", find_link_mode()); +@@ -446,10 +94,6 @@ mod build_linked { return HeaderLocation::FromEnvironment; } @@ -421,7 +461,12 @@ index e154a8d..15f0430 100644 // See if pkg-config can do everything for us. if let Ok(mut lib) = pkg_config::Config::new() .print_system_libs(false) -@@ -448,48 +110,8 @@ mod build_linked { +@@ -465,43 +109,12 @@ mod build_linked { + // request and hope that the library exists on the system paths. We used to + // output /usr/lib explicitly, but that can introduce other linking problems; + // see https://github.com/rusqlite/rusqlite/issues/207. +- #[cfg(not(feature = "loadable_extension"))] + println!("cargo:rustc-link-lib={}={link_lib}", find_link_mode()); HeaderLocation::Wrapper } } @@ -430,8 +475,7 @@ index e154a8d..15f0430 100644 - if cfg!(feature = "vcpkg") && is_compiler("msvc") { - // See if vcpkg can find it. - if let Ok(mut lib) = vcpkg::Config::new().probe(lib_name()) { -- if let Some(mut header) = lib.include_paths.pop() { -- header.push("sqlite3.h"); +- if let Some(header) = lib.include_paths.pop() { - return Some(HeaderLocation::FromPath(header.to_string_lossy().into())); - } - } @@ -440,46 +484,28 @@ index e154a8d..15f0430 100644 - None - } - } - } - +-} +- -#[cfg(not(feature = "buildtime_bindgen"))] -mod bindings { - #![allow(dead_code)] - use super::HeaderLocation; - -- use std::fs; - use std::path::Path; - -- static PREBUILT_BINDGEN_PATHS: &[&str] = &[ -- "bindgen-bindings/bindgen_3.6.8.rs", -- #[cfg(feature = "min_sqlite_version_3_6_23")] -- "bindgen-bindings/bindgen_3.6.23.rs", -- #[cfg(feature = "min_sqlite_version_3_7_7")] -- "bindgen-bindings/bindgen_3.7.7.rs", -- #[cfg(feature = "min_sqlite_version_3_7_16")] -- "bindgen-bindings/bindgen_3.7.16.rs", -- ]; +- static PREBUILT_BINDGENS: &[&str] = &["bindgen_3.14.0"]; - - pub fn write_to_out_dir(_header: HeaderLocation, out_path: &Path) { -- let in_path = PREBUILT_BINDGEN_PATHS[PREBUILT_BINDGEN_PATHS.len() - 1]; -- fs::copy(in_path, out_path).expect("Could not copy bindings to output directory"); +- let name = PREBUILT_BINDGENS[PREBUILT_BINDGENS.len() - 1]; +- super::copy_bindings("bindgen-bindings", name, out_path); - } --} -- + } + -#[cfg(feature = "buildtime_bindgen")] mod bindings { use super::HeaderLocation; use bindgen::callbacks::{IntKind, ParseCallbacks}; -@@ -498,8 +120,6 @@ mod bindings { - use std::io::Write; - use std::path::Path; - -- use super::win_target; -- - #[derive(Debug)] - struct SqliteTypeChooser; - -@@ -513,18 +133,6 @@ mod bindings { +@@ -523,18 +136,6 @@ mod bindings { } } @@ -497,51 +523,41 @@ index e154a8d..15f0430 100644 - pub fn write_to_out_dir(header: HeaderLocation, out_path: &Path) { let header: String = header.into(); - let mut output = Vec::new(); -@@ -534,7 +142,7 @@ mod bindings { - .parse_callbacks(Box::new(SqliteTypeChooser)) - .rustfmt_bindings(true); + let mut bindings = bindgen::builder() +@@ -543,12 +144,10 @@ mod bindings { + .trust_clang_mangling(false) + .header(header.clone()) + .parse_callbacks(Box::new(SqliteTypeChooser)); +- if cfg!(feature = "loadable_extension") { +- bindings = bindings.ignore_functions(); // see generate_functions +- } else { +- bindings = bindings +- .blocklist_function("sqlite3_auto_extension") +- .raw_line( ++ ++ bindings = bindings ++ .blocklist_function("sqlite3_auto_extension") ++ .raw_line( + r#"extern "C" { + pub fn sqlite3_auto_extension( + xEntryPoint: ::std::option::Option< +@@ -574,10 +173,9 @@ mod bindings { + >, + ) -> ::std::os::raw::c_int; + }"#, +- ); +- } ++ ); - if cfg!(any(feature = "sqlcipher", feature = "bundled-sqlcipher")) { + if cfg!(feature = "sqlcipher") { bindings = bindings.clang_arg("-DSQLITE_HAS_CODEC"); } if cfg!(feature = "unlock_notify") { -@@ -546,65 +154,6 @@ mod bindings { - if cfg!(feature = "session") { +@@ -590,209 +188,13 @@ mod bindings { bindings = bindings.clang_arg("-DSQLITE_ENABLE_SESSION"); } -- if win_target() && cfg!(feature = "winsqlite3") { -- bindings = bindings -- .clang_arg("-DBINDGEN_USE_WINSQLITE3") -- .blocklist_item("NTDDI_.+") -- .blocklist_item("WINAPI_FAMILY.*") -- .blocklist_item("_WIN32_.+") -- .blocklist_item("_VCRT_COMPILER_PREPROCESSOR") -- .blocklist_item("_SAL_VERSION") -- .blocklist_item("__SAL_H_VERSION") -- .blocklist_item("_USE_DECLSPECS_FOR_SAL") -- .blocklist_item("_USE_ATTRIBUTES_FOR_SAL") -- .blocklist_item("_CRT_PACKING") -- .blocklist_item("_HAS_EXCEPTIONS") -- .blocklist_item("_STL_LANG") -- .blocklist_item("_HAS_CXX17") -- .blocklist_item("_HAS_CXX20") -- .blocklist_item("_HAS_NODISCARD") -- .blocklist_item("WDK_NTDDI_VERSION") -- .blocklist_item("OSVERSION_MASK") -- .blocklist_item("SPVERSION_MASK") -- .blocklist_item("SUBVERSION_MASK") -- .blocklist_item("WINVER") -- .blocklist_item("__security_cookie") -- .blocklist_type("size_t") -- .blocklist_type("__vcrt_bool") -- .blocklist_type("wchar_t") -- .blocklist_function("__security_init_cookie") -- .blocklist_function("__report_gsfailure") -- .blocklist_function("__va_start"); -- } -- + - // When cross compiling unless effort is taken to fix the issue, bindgen - // will find the wrong headers. There's only one header included by the - // amalgamated `sqlite.h`: `stdarg.h`. @@ -565,14 +581,189 @@ index e154a8d..15f0430 100644 - .blocklist_function("sqlite3_vsnprintf") - .blocklist_function("sqlite3_str_vappendf") - .blocklist_type("va_list") -- .blocklist_type("__builtin_va_list") -- .blocklist_type("__gnuc_va_list") -- .blocklist_type("__va_list_tag") -- .blocklist_item("__GNUC_VA_LIST"); +- .blocklist_item("__.*"); - } +- + let bindings = bindings + .layout_tests(false) + .generate() + .unwrap_or_else(|_| panic!("could not run bindgen on header {}", header)); +- #[cfg(feature = "loadable_extension")] +- { +- let mut output = Vec::new(); +- bindings +- .write(Box::new(&mut output)) +- .expect("could not write output of bindgen"); +- let mut output = String::from_utf8(output).expect("bindgen output was not UTF-8?!"); +- super::loadable_extension::generate_functions(&mut output); +- std::fs::write(out_path, output.as_bytes()) +- .unwrap_or_else(|_| panic!("Could not write to {:?}", out_path)); +- } +- #[cfg(not(feature = "loadable_extension"))] bindings - .generate() + .write_to_file(out_path) + .unwrap_or_else(|_| panic!("Could not write to {:?}", out_path)); + } + } +- +-#[cfg(all(feature = "buildtime_bindgen", feature = "loadable_extension"))] +-mod loadable_extension { +- /// try to generate similar rust code for all `#define sqlite3_xyz +- /// sqlite3_api->abc` macros` in sqlite3ext.h +- pub fn generate_functions(output: &mut String) { +- // (1) parse sqlite3_api_routines fields from bindgen output +- let ast: syn::File = syn::parse_str(output).expect("could not parse bindgen output"); +- let sqlite3_api_routines: syn::ItemStruct = ast +- .items +- .into_iter() +- .find_map(|i| { +- if let syn::Item::Struct(s) = i { +- if s.ident == "sqlite3_api_routines" { +- Some(s) +- } else { +- None +- } +- } else { +- None +- } +- }) +- .expect("could not find sqlite3_api_routines"); +- let sqlite3_api_routines_ident = sqlite3_api_routines.ident; +- let p_api = quote::format_ident!("p_api"); +- let mut stores = Vec::new(); +- let mut malloc = Vec::new(); +- // (2) `#define sqlite3_xyz sqlite3_api->abc` => `pub unsafe fn +- // sqlite3_xyz(args) -> ty {...}` for each `abc` field: +- for field in sqlite3_api_routines.fields { +- let ident = field.ident.expect("unamed field"); +- let span = ident.span(); +- let name = ident.to_string(); +- if name == "vmprintf" || name == "xvsnprintf" || name == "str_vappendf" { +- continue; // skip va_list +- } else if name == "aggregate_count" +- || name == "expired" +- || name == "global_recover" +- || name == "thread_cleanup" +- || name == "transfer_bindings" +- { +- continue; // omit deprecated +- } +- let sqlite3_name = match name.as_ref() { +- "xthreadsafe" => "sqlite3_threadsafe".to_owned(), +- "interruptx" => "sqlite3_interrupt".to_owned(), +- _ => { +- format!("sqlite3_{name}") +- } +- }; +- let ptr_name = +- syn::Ident::new(format!("__{}", sqlite3_name.to_uppercase()).as_ref(), span); +- let sqlite3_fn_name = syn::Ident::new(&sqlite3_name, span); +- let method = +- extract_method(&field.ty).unwrap_or_else(|| panic!("unexpected type for {name}")); +- let arg_names: syn::punctuated::Punctuated<&syn::Ident, syn::token::Comma> = method +- .inputs +- .iter() +- .map(|i| &i.name.as_ref().unwrap().0) +- .collect(); +- let args = &method.inputs; +- // vtab_config/sqlite3_vtab_config: ok +- let varargs = &method.variadic; +- if varargs.is_some() && "db_config" != name && "log" != name && "vtab_config" != name { +- continue; // skip ... +- } +- let ty = &method.output; +- let tokens = if "db_config" == name { +- quote::quote! { +- static #ptr_name: ::std::sync::atomic::AtomicPtr<()> = ::std::sync::atomic::AtomicPtr::new(::std::ptr::null_mut()); +- pub unsafe fn #sqlite3_fn_name(#args arg3: ::std::os::raw::c_int, arg4: *mut ::std::os::raw::c_int) #ty { +- let ptr = #ptr_name.load(::std::sync::atomic::Ordering::Acquire); +- assert!(!ptr.is_null(), "SQLite API not initialized"); +- let fun: unsafe extern "C" fn(#args #varargs) #ty = ::std::mem::transmute(ptr); +- (fun)(#arg_names, arg3, arg4) +- } +- } +- } else if "log" == name { +- quote::quote! { +- static #ptr_name: ::std::sync::atomic::AtomicPtr<()> = ::std::sync::atomic::AtomicPtr::new(::std::ptr::null_mut()); +- pub unsafe fn #sqlite3_fn_name(#args arg3: *const ::std::os::raw::c_char) #ty { +- let ptr = #ptr_name.load(::std::sync::atomic::Ordering::Acquire); +- assert!(!ptr.is_null(), "SQLite API not initialized"); +- let fun: unsafe extern "C" fn(#args #varargs) #ty = ::std::mem::transmute(ptr); +- (fun)(#arg_names, arg3) +- } +- } +- } else { +- quote::quote! { +- static #ptr_name: ::std::sync::atomic::AtomicPtr<()> = ::std::sync::atomic::AtomicPtr::new(::std::ptr::null_mut()); +- pub unsafe fn #sqlite3_fn_name(#args) #ty { +- let ptr = #ptr_name.load(::std::sync::atomic::Ordering::Acquire); +- assert!(!ptr.is_null(), "SQLite API not initialized or SQLite feature omitted"); +- let fun: unsafe extern "C" fn(#args #varargs) #ty = ::std::mem::transmute(ptr); +- (fun)(#arg_names) +- } +- } +- }; +- output.push_str(&prettyplease::unparse( +- &syn::parse2(tokens).expect("could not parse quote output"), +- )); +- output.push('\n'); +- if name == "malloc" { +- &mut malloc +- } else { +- &mut stores +- } +- .push(quote::quote! { +- if let Some(fun) = (*#p_api).#ident { +- #ptr_name.store( +- fun as usize as *mut (), +- ::std::sync::atomic::Ordering::Release, +- ); +- } +- }); +- } +- // (3) generate rust code similar to SQLITE_EXTENSION_INIT2 macro +- let tokens = quote::quote! { +- /// Like SQLITE_EXTENSION_INIT2 macro +- pub unsafe fn rusqlite_extension_init2(#p_api: *mut #sqlite3_api_routines_ident) -> ::std::result::Result<(),crate::InitError> { +- #(#malloc)* // sqlite3_malloc needed by to_sqlite_error +- if let Some(fun) = (*#p_api).libversion_number { +- let version = fun(); +- if SQLITE_VERSION_NUMBER > version { +- return Err(crate::InitError::VersionMismatch{compile_time: SQLITE_VERSION_NUMBER, runtime: version}); +- } +- } else { +- return Err(crate::InitError::NullFunctionPointer); +- } +- #(#stores)* +- Ok(()) +- } +- }; +- output.push_str(&prettyplease::unparse( +- &syn::parse2(tokens).expect("could not parse quote output"), +- )); +- output.push('\n'); +- } +- +- fn extract_method(ty: &syn::Type) -> Option<&syn::TypeBareFn> { +- match ty { +- syn::Type::Path(tp) => tp.path.segments.last(), +- _ => None, +- } +- .map(|seg| match &seg.arguments { +- syn::PathArguments::AngleBracketed(args) => args.args.first(), +- _ => None, +- })? +- .map(|arg| match arg { +- syn::GenericArgument::Type(t) => Some(t), +- _ => None, +- })? +- .map(|ty| match ty { +- syn::Type::BareFn(r) => Some(r), +- _ => None, +- })? +- } +-} -- -2.39.2 +2.44.0 diff --git a/libsqlite3-sys-fix-metadata.diff b/libsqlite3-sys-fix-metadata.diff index e7bebcf..69670d2 100644 --- a/libsqlite3-sys-fix-metadata.diff +++ b/libsqlite3-sys-fix-metadata.diff @@ -1,6 +1,6 @@ ---- libsqlite3-sys-0.25.2/Cargo.toml 1970-01-01T00:00:01+00:00 -+++ libsqlite3-sys-0.25.2/Cargo.toml 2023-03-07T15:11:16.358560+00:00 -@@ -26,67 +26,28 @@ +--- libsqlite3-sys-0.28.0/Cargo.toml 1970-01-01T00:00:01+00:00 ++++ libsqlite3-sys-0.28.0/Cargo.toml 2024-04-09T16:26:49.840896+00:00 +@@ -26,78 +26,25 @@ categories = ["external-ffi-bindings"] license = "MIT" repository = "https://github.com/rusqlite/rusqlite" @@ -16,8 +16,7 @@ +] [build-dependencies.bindgen] --version = "0.60" -+version = "0.63" + version = "0.69" features = ["runtime"] -optional = true default-features = false @@ -30,6 +29,24 @@ version = "0.3.19" -optional = true - +-[build-dependencies.prettyplease] +-version = "0.2" +-optional = true +- +-[build-dependencies.quote] +-version = "1" +-optional = true +-default-features = false +- +-[build-dependencies.syn] +-version = "2.0" +-features = [ +- "full", +- "extra-traits", +- "visit-mut", +-] +-optional = true +- -[build-dependencies.vcpkg] -version = "0.2" -optional = true @@ -55,35 +72,24 @@ -] -bundled_bindings = [] +buildtime_bindgen = [] - default = ["min_sqlite_version_3_6_8"] + default = ["min_sqlite_version_3_14_0"] -in_gecko = [] --min_sqlite_version_3_6_23 = [ -- "pkg-config", -- "vcpkg", --] --min_sqlite_version_3_6_8 = [ -- "pkg-config", -- "vcpkg", --] --min_sqlite_version_3_7_16 = [ -- "pkg-config", -- "vcpkg", +-loadable_extension = [ +- "prettyplease", +- "quote", +- "syn", -] --min_sqlite_version_3_7_7 = [ +-min_sqlite_version_3_14_0 = [ - "pkg-config", - "vcpkg", -] -+min_sqlite_version_3_6_23 = [] -+min_sqlite_version_3_6_8 = [] -+min_sqlite_version_3_7_16 = [] -+min_sqlite_version_3_7_7 = [] ++min_sqlite_version_3_14_0 = [] preupdate_hook = ["buildtime_bindgen"] session = [ "preupdate_hook", -@@ -94,6 +55,4 @@ +@@ -105,5 +52,4 @@ ] sqlcipher = [] unlock_notify = [] -wasm32-wasi-vfs = [] --winsqlite3 = ["min_sqlite_version_3_7_16"] with-asan = [] diff --git a/rust-libsqlite3-sys.spec b/rust-libsqlite3-sys.spec index 813ce16..b416fea 100644 --- a/rust-libsqlite3-sys.spec +++ b/rust-libsqlite3-sys.spec @@ -1,11 +1,11 @@ -# Generated by rust2rpm 24 +# Generated by rust2rpm 26 %bcond_without check %global debug_package %{nil} %global crate libsqlite3-sys Name: rust-libsqlite3-sys -Version: 0.25.2 +Version: 0.28.0 Release: %autorelease Summary: Native bindings to the libsqlite3 library @@ -13,7 +13,6 @@ License: MIT URL: https://crates.io/crates/libsqlite3-sys Source: %{crates_source} # Manually created patch for downstream crate metadata changes -# * bump bindgen from 0.60 to 0.63 # * remove features for building vendored sqlite3 and sqlcipher sources # * drop Windows- and WASM-specific features # * exclude files that are only useful for upstream development @@ -21,7 +20,9 @@ Patch: libsqlite3-sys-fix-metadata.diff # * unconditionally enable building with bindgen and pkg-config Patch: 0001-unconditionally-enable-building-with-bindgen-and-pkg.patch -BuildRequires: rust-packaging >= 21 +BuildRequires: cargo-rpm-macros >= 24 +BuildRequires: pkgconfig(sqlcipher) +BuildRequires: pkgconfig(sqlite3) >= 3.7.16 %global _description %{expand: Native bindings to the libsqlite3 library.} @@ -67,52 +68,16 @@ use the "buildtime_bindgen" feature of the "%{crate}" crate. %files -n %{name}+buildtime_bindgen-devel %ghost %{crate_instdir}/Cargo.toml -%package -n %{name}+min_sqlite_version_3_6_23-devel +%package -n %{name}+min_sqlite_version_3_14_0-devel Summary: %{summary} BuildArch: noarch -%description -n %{name}+min_sqlite_version_3_6_23-devel %{_description} +%description -n %{name}+min_sqlite_version_3_14_0-devel %{_description} This package contains library source intended for building other packages which -use the "min_sqlite_version_3_6_23" feature of the "%{crate}" crate. +use the "min_sqlite_version_3_14_0" feature of the "%{crate}" crate. -%files -n %{name}+min_sqlite_version_3_6_23-devel -%ghost %{crate_instdir}/Cargo.toml - -%package -n %{name}+min_sqlite_version_3_6_8-devel -Summary: %{summary} -BuildArch: noarch - -%description -n %{name}+min_sqlite_version_3_6_8-devel %{_description} - -This package contains library source intended for building other packages which -use the "min_sqlite_version_3_6_8" feature of the "%{crate}" crate. - -%files -n %{name}+min_sqlite_version_3_6_8-devel -%ghost %{crate_instdir}/Cargo.toml - -%package -n %{name}+min_sqlite_version_3_7_16-devel -Summary: %{summary} -BuildArch: noarch - -%description -n %{name}+min_sqlite_version_3_7_16-devel %{_description} - -This package contains library source intended for building other packages which -use the "min_sqlite_version_3_7_16" feature of the "%{crate}" crate. - -%files -n %{name}+min_sqlite_version_3_7_16-devel -%ghost %{crate_instdir}/Cargo.toml - -%package -n %{name}+min_sqlite_version_3_7_7-devel -Summary: %{summary} -BuildArch: noarch - -%description -n %{name}+min_sqlite_version_3_7_7-devel %{_description} - -This package contains library source intended for building other packages which -use the "min_sqlite_version_3_7_7" feature of the "%{crate}" crate. - -%files -n %{name}+min_sqlite_version_3_7_7-devel +%files -n %{name}+min_sqlite_version_3_14_0-devel %ghost %{crate_instdir}/Cargo.toml %package -n %{name}+preupdate_hook-devel @@ -177,15 +142,13 @@ use the "with-asan" feature of the "%{crate}" crate. %ghost %{crate_instdir}/Cargo.toml %prep -%autosetup -n %{crate}-%{version_no_tilde} -p1 +%autosetup -n %{crate}-%{version} -p1 +%cargo_prep # * remove bundled copies of sqlite and sqlcipher rm -vr sqlite3/ sqlcipher/ -%cargo_prep %generate_buildrequires %cargo_generate_buildrequires -echo 'pkgconfig(sqlcipher)' -echo 'pkgconfig(sqlite3) >= 3.7.16' %build %cargo_build diff --git a/rust2rpm.conf b/rust2rpm.conf deleted file mode 100644 index 4dd287e..0000000 --- a/rust2rpm.conf +++ /dev/null @@ -1,8 +0,0 @@ -[DEFAULT] -buildrequires = - pkgconfig(sqlcipher) - pkgconfig(sqlite3) >= 3.7.16 -lib.requires = - pkgconfig(sqlite3) >= 3.7.16 -lib+sqlcipher.requires = - pkgconfig(sqlcipher) diff --git a/rust2rpm.toml b/rust2rpm.toml new file mode 100644 index 0000000..a4c2594 --- /dev/null +++ b/rust2rpm.toml @@ -0,0 +1,11 @@ +[requires] +build = ["pkgconfig(sqlcipher)", "pkgconfig(sqlite3) >= 3.7.16"] +lib = ["pkgconfig(sqlite3) >= 3.7.16"] +features.sqlcipher = ["pkgconfig(sqlcipher)"] + +[scripts] +prep.post = [ + "# * remove bundled copies of sqlite and sqlcipher", + "rm -vr sqlite3/ sqlcipher/", +] + diff --git a/sources b/sources index 955afe7..2d91306 100644 --- a/sources +++ b/sources @@ -1 +1 @@ -SHA512 (libsqlite3-sys-0.25.2.crate) = 30d688b5e861592160ffecef62fd401b26328a4bcbd692b98af828c7d8c1ca483dd5354e13c874a4b440eb4b1c7006641024f3f575f4231432d4dfe213bef395 +SHA512 (libsqlite3-sys-0.28.0.crate) = 4a3d16eec47c6e3e53e00232501fd50fa77f1ee1370f4ab6c984496f2f897b4acd1c15c697caa8babd635d31a946e147d5d090378615676a3b5c4a9656355016