Always bundle Sqlite if required

main
Ziyang Hu 2 years ago
parent 6beaeb3fdb
commit 118faf7a5d

1
Cargo.lock generated

@ -531,6 +531,7 @@ dependencies = [
"smallvec", "smallvec",
"smartstring", "smartstring",
"sqlite", "sqlite",
"sqlite3-src",
"thiserror", "thiserror",
"tikv-client", "tikv-client",
"tikv-jemallocator-global", "tikv-jemallocator-global",

@ -26,7 +26,7 @@ minimal = ["storage-sqlite"]
## also allows backup and restore with Sqlite data files. ## also allows backup and restore with Sqlite data files.
## Sqlite is easy to compile, has very low resource requirements and reasonable performance, ## Sqlite is easy to compile, has very low resource requirements and reasonable performance,
## but does not support much concurrency. ## but does not support much concurrency.
storage-sqlite = ["dep:sqlite"] storage-sqlite = ["dep:sqlite", "dep:sqlite3-src"]
## Enables the [RocksDB](http://rocksdb.org/) backend. ## Enables the [RocksDB](http://rocksdb.org/) backend.
## RocksDB is hard (even impossible) to compile on some platforms, uses quite a lot of resources ## RocksDB is hard (even impossible) to compile on some platforms, uses quite a lot of resources
## including background threads, but is very performant and supports a high level of concurrency. ## including background threads, but is very performant and supports a high level of concurrency.
@ -132,6 +132,7 @@ sled = { version = "0.34.7", optional = true }
tikv-client = { version = "0.1.0", optional = true } tikv-client = { version = "0.1.0", optional = true }
tokio = { version = "1.21.2", optional = true } tokio = { version = "1.21.2", optional = true }
sqlite = { version = "0.30.1", optional = true } sqlite = { version = "0.30.1", optional = true }
sqlite3-src = { version = "0.4.0", optional = true, features = ["bundled"] }
js-sys = { version = "0.3.60", optional = true } js-sys = { version = "0.3.60", optional = true }
#redb = "0.9.0" #redb = "0.9.0"
#ouroboros = "0.15.5" #ouroboros = "0.15.5"

@ -208,7 +208,9 @@ impl<'s, S: Storage<'s>> Db<S> {
} }
Ok(JsonValue::Object(ret)) Ok(JsonValue::Object(ret))
} }
/// Import relations /// Import relations. The argument `data` accepts data in the shape of
/// what was returned by [Self::export_relations].
/// The target stored relations must already exist in the database.
pub fn import_relations(&'s self, data: &Map<String, JsonValue>) -> Result<()> { pub fn import_relations(&'s self, data: &Map<String, JsonValue>) -> Result<()> {
#[derive(Debug, Diagnostic, Error)] #[derive(Debug, Diagnostic, Error)]
#[error("cannot import data for relation '{0}': {1}")] #[error("cannot import data for relation '{0}': {1}")]
@ -418,7 +420,8 @@ impl<'s, S: Storage<'s>> Db<S> {
#[cfg(not(feature = "storage-sqlite"))] #[cfg(not(feature = "storage-sqlite"))]
bail!("backup requires the 'storage-sqlite' feature to be enabled") bail!("backup requires the 'storage-sqlite' feature to be enabled")
} }
/// Import data from relations in a backup file /// Import data from relations in a backup file.
/// The target stored relations must already exist in the database.
pub fn import_from_backup(&'s self, in_file: &str, relations: &[String]) -> Result<()> { pub fn import_from_backup(&'s self, in_file: &str, relations: &[String]) -> Result<()> {
#[cfg(not(feature = "storage-sqlite"))] #[cfg(not(feature = "storage-sqlite"))]
bail!("backup requires the 'storage-sqlite' feature to be enabled"); bail!("backup requires the 'storage-sqlite' feature to be enabled");

@ -15,13 +15,34 @@ crate-type = ["staticlib"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features] [features]
## Enables the `minimal`, `requests` and `graph-algo` features
compact = ["minimal", "requests", "graph-algo", "rayon"]
## Enables the `storage-sqlite` and `graph-algo` features
mobile = ["storage-sqlite", "graph-algo", "rayon"]
## Enables the `minimal`, `requests` and `graph-algo` features in single threaded mode
compact-single-threaded = ["minimal", "requests", "graph-algo"]
## Enables the `storage-sqlite` feature
minimal = ["storage-sqlite"]
## Enables the [Sqlite](https://www.sqlite.org/index.html) backend, also allows backup and restore with Sqlite data files.
storage-sqlite = ["cozo/storage-sqlite"]
## Enables the [RocksDB](http://rocksdb.org/) backend
storage-rocksdb = ["cozo/storage-rocksdb"] storage-rocksdb = ["cozo/storage-rocksdb"]
## Enables the graph algorithms
graph-algo = ["cozo/graph-algo"]
## Allows the utilities to make web requests to fetch data
requests = ["cozo/requests"]
## Uses jemalloc as the global allocator, can make a difference in performance
jemalloc = ["cozo/jemalloc"] jemalloc = ["cozo/jemalloc"]
## Enables io-uring option for the RocksDB storage
io-uring = ["cozo/io-uring"] io-uring = ["cozo/io-uring"]
## Allows threading and enables the use of the `rayon` library for parallelizing algorithms
rayon = ["cozo/rayon"]
## Disallows the use of threads
nothread = ["cozo/nothread"]
[build-dependencies] [build-dependencies]
swift-bridge-build = "0.1.41" swift-bridge-build = "0.1.41"
[dependencies] [dependencies]
cozo = { version = "0.2.1", path = "../cozo-core", default-features = false, features = ["compact"] } cozo = { version = "0.2.1", path = "../cozo-core", default-features = false }
swift-bridge = "0.1.41" swift-bridge = "0.1.41"

@ -0,0 +1,34 @@
# Cozo for Swift on Apple
Only the `storage-sqlite` engine is enabled for the Swift prebuilt binaries, as using
other storage engines on desktop or mobile does not make too much sense. If you disagree,
see the Building section below.
## Using the library
TODO
## Building
First, install the [Rust toolchain](https://rustup.rs).
Then run the [build script](build-rust.sh) in this directory.
It is recommended to also set the environment variable `CARGO_PROFILE_RELEASE_LTO=fat`:
this makes the building process much longer, but in turn the library runs a little bit faster.
When everything goes well, you should find the compiled Swift package in a directory called
`CozoSwiftBridge`.
If you want to use the RocksDB engine on Desktop, in the build script change the two lines
```bash
cargo build -p cozo-swift -F compact --target x86_64-apple-darwin --release
cargo build -p cozo-swift -F compact --target aarch64-apple-darwin --release
```
to
```bash
cargo build -p cozo-swift -F compact -F storage-rocksdb --target x86_64-apple-darwin --release
cargo build -p cozo-swift -F compact -F storage-rocksdb --target aarch64-apple-darwin --release
```
Then you also need to link your executable with `libc++`: in XCode, click on your project
in the left drawer, then on the right go to `Build phases > Link Binary With Libraries`,
click the plus sign, search for `libc++`, then add `libc++.tbd` found under Apple SDKs.

@ -6,8 +6,8 @@ cd $THISDIR
export SWIFT_BRIDGE_OUT_DIR="$(pwd)/generated" export SWIFT_BRIDGE_OUT_DIR="$(pwd)/generated"
# Build the project for the desired platforms: # Build the project for the desired platforms:
cargo build -p cozo-swift -F storage-rocksdb --target x86_64-apple-darwin --release cargo build -p cozo-swift -F compact --target x86_64-apple-darwin --release
cargo build -p cozo-swift -F storage-rocksdb --target aarch64-apple-darwin --release cargo build -p cozo-swift -F compact --target aarch64-apple-darwin --release
mkdir -p ../target/universal-macos/release mkdir -p ../target/universal-macos/release
lipo \ lipo \
@ -15,9 +15,9 @@ lipo \
../target/x86_64-apple-darwin/release/libcozo_swift.a -create -output \ ../target/x86_64-apple-darwin/release/libcozo_swift.a -create -output \
../target/universal-macos/release/libcozo_swift.a ../target/universal-macos/release/libcozo_swift.a
cargo build -p cozo-swift --target aarch64-apple-ios --release cargo build -p cozo-swift -F compact --target aarch64-apple-ios --release
cargo build -p cozo-swift --target x86_64-apple-ios --release cargo build -p cozo-swift -F compact --target x86_64-apple-ios --release
cargo build -p cozo-swift --target aarch64-apple-ios-sim --release cargo build -p cozo-swift -F compact --target aarch64-apple-ios-sim --release
mkdir -p ../target/universal-ios/release mkdir -p ../target/universal-ios/release

Loading…
Cancel
Save