Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion core/rs/sqlite-rs-embedded
Submodule sqlite-rs-embedded deleted from aba562
2 changes: 2 additions & 0 deletions core/rs/sqlite-rs-embedded/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sqlite3_capi/deps/* linguist-vendored

3 changes: 3 additions & 0 deletions core/rs/sqlite-rs-embedded/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
target/
.DS_Store
node_modules/
Empty file.
1 change: 1 addition & 0 deletions core/rs/sqlite-rs-embedded/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
wa-sqlite/
5 changes: 5 additions & 0 deletions core/rs/sqlite-rs-embedded/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"trailingComma": "es5",
"tabWidth": 2,
"singleQuote": false
}
7 changes: 7 additions & 0 deletions core/rs/sqlite-rs-embedded/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"rust-analyzer.checkOnSave.overrideCommand": [
"./cargo",
"xcheck",
"--json-output"
]
}
14 changes: 14 additions & 0 deletions core/rs/sqlite-rs-embedded/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# SQLite no_std

> Note: these bindings are faithful to the base SQLite C-API as much as possible for minimum rust<->c overhead. This, however, means that the bindings are not entirely safe. E.g., the SQLite statement object will clear returned values out from under you if you step or finalize it while those references exist in your Rust program.

SQLite is lite. Its bindings should be lite too. They should be able to be used _anywhere_ SQLite is used, _not_ incur any performance impact, _not_ include any extra dependencies, and be usable against _any_ SQLite version.

Thus this repository was born.

These bindings:

- Do not require the rust standard library
- Use the SQLite memory subsystem if no allocator exists
- Can be used to write SQLite extensions that compile to WASM and run in the browser
- Does 0 copying. E.g., through some tricks, Rust strings are passed directly to SQLite with no conversion to or copying to CString.
2 changes: 2 additions & 0 deletions core/rs/sqlite-rs-embedded/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[toolchain]
channel = "nightly-2023-10-05"
249 changes: 249 additions & 0 deletions core/rs/sqlite-rs-embedded/sqlite3_allocator/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions core/rs/sqlite-rs-embedded/sqlite3_allocator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "sqlite3_allocator"
version = "0.1.0"
edition = "2021"
authors = ["Matt Wonlaw"]
description = "Rust allocator backed by the sqlite3 memory system"
keywords = ["sqlite"]
license = "MIT"

[lib]
name = "sqlite3_allocator"
crate-type = ["rlib"]

[dependencies]
sqlite3_capi = {version="0.1.0", path="../sqlite3_capi"}

# dev dependencies for examples
[dev-dependencies]
8 changes: 8 additions & 0 deletions core/rs/sqlite-rs-embedded/sqlite3_allocator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# sqlite3_allocator

Installs the sqlite3 memory system as the Rust default global allocator. Useful in no_std environments where there is no allocator and, if you want to use collections, you must bring your own.

https://docs.rust-embedded.org/book/intro/no-std.html

Reference:
https://github.com/rust-embedded/embedded-alloc
12 changes: 12 additions & 0 deletions core/rs/sqlite-rs-embedded/sqlite3_allocator/src/allocator.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use core::alloc::{GlobalAlloc, Layout};
pub struct SQLite3Allocator {}

unsafe impl GlobalAlloc for SQLite3Allocator {
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
sqlite3_capi::malloc(layout.size())
}

unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {
sqlite3_capi::free(ptr as *mut core::ffi::c_void);
}
}
4 changes: 4 additions & 0 deletions core/rs/sqlite-rs-embedded/sqlite3_allocator/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#![no_std]

mod allocator;
pub use allocator::*;
Loading
Loading