Skip to content

Commit fb39e14

Browse files
authored
Merge branch 'main' into main
2 parents f704845 + bc5d2eb commit fb39e14

File tree

16 files changed

+277
-104
lines changed

16 files changed

+277
-104
lines changed

Cargo.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,18 @@ exclude = [
2525
]
2626

2727
[workspace.package]
28-
version = "0.9.12"
28+
version = "0.9.19"
2929
authors = ["the libSQL authors"]
3030
edition = "2021"
3131
license = "MIT"
3232
repository = "https://github.com/tursodatabase/libsql"
3333

3434
[workspace.dependencies]
35-
libsql-ffi = { path = "libsql-ffi", version = "0.9.12" }
36-
libsql-sys = { path = "libsql-sys", version = "0.9.12", default-features = false }
37-
libsql-hrana = { path = "libsql-hrana", version = "0.9.12" }
38-
libsql_replication = { path = "libsql-replication", version = "0.9.12" }
39-
rusqlite = { package = "libsql-rusqlite", path = "vendored/rusqlite", version = "0.9.12", default-features = false, features = [
35+
libsql-ffi = { path = "libsql-ffi", version = "0.9.19" }
36+
libsql-sys = { path = "libsql-sys", version = "0.9.19", default-features = false }
37+
libsql-hrana = { path = "libsql-hrana", version = "0.9.19" }
38+
libsql_replication = { path = "libsql-replication", version = "0.9.19" }
39+
rusqlite = { package = "libsql-rusqlite", path = "vendored/rusqlite", version = "0.9.19", default-features = false, features = [
4040
"libsql-experimental",
4141
"column_decltype",
4242
"load_extension",

bindings/c/Cargo.toml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,8 @@ tracing = "0.1.40"
1919
tracing-subscriber = "0.3.18"
2020
http = "1.1.0"
2121
anyhow = "1.0.86"
22-
23-
[target.'cfg(not(any(target_os = "ios", target_os = "android")))'.dependencies]
2422
libsql = { path = "../../libsql", features = ["encryption"] }
2523

26-
# Disable encryption for ios and android targets
27-
[target.'cfg(any(target_os = "ios", target_os = "android"))'.dependencies]
28-
libsql = { path = "../../libsql"}
29-
3024

3125
# The produced binaries are too large for mobiles
3226
# When compiling for iOS or Android, you should turn on symbol stripping, lto and cut debug symbols

bindings/c/Makefile

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
OS := $(shell uname)
22
CFLAGS := -Iinclude
33
LDFLAGS := -lm
4-
ARCHS_IOS = x86_64-apple-ios aarch64-apple-ios aarch64-apple-ios-sim
4+
ARCHS_IOS = aarch64-apple-ios aarch64-apple-ios-sim
55
ARCHS_ANDROID = aarch64-linux-android armv7-linux-androideabi x86_64-linux-android i686-linux-android
66
LIB = libsql_experimental.a
77
HEADER = libsql.h
@@ -40,11 +40,21 @@ $(ARCHS_ANDROID): %:
4040
ios: $(XCFRAMEWORK)
4141

4242
$(ARCHS_IOS): %:
43-
cargo build --release --target $@
44-
45-
$(XCFRAMEWORK): $(ARCHS_IOS)
43+
cargo build --release --target $@
44+
45+
x86_64-apple-ios:
46+
SDKROOT=$$(xcrun --sdk iphonesimulator --show-sdk-path) \
47+
CFLAGS_x86_64_apple_ios="-target x86_64-apple-ios-simulator" \
48+
CXXFLAGS_x86_64_apple_ios="-target x86_64-apple-ios-simulator" \
49+
CC_x86_64_apple_ios=$$(xcrun --sdk iphonesimulator --find clang) \
50+
CXX_x86_64_apple_ios=$$(xcrun --sdk iphonesimulator --find clang++) \
51+
CMAKE_SYSTEM_NAME=iOS \
52+
CMAKE_OSX_SYSROOT=$$(xcrun --sdk iphonesimulator --show-sdk-path) \
53+
cargo build --release --target x86_64-apple-ios
54+
55+
$(XCFRAMEWORK): $(ARCHS_IOS) x86_64-apple-ios
4656
rm -rf generated
4757
mkdir -p generated/simulator_fat
4858
rm -rf $@
4959
lipo -create $(wildcard ../../target/x86_64-apple-ios/release/$(LIB)) $(wildcard ../../target/aarch64-apple-ios-sim/release/$(LIB)) -output generated/simulator_fat/$(LIB)
50-
xcodebuild -create-xcframework -library $(wildcard ../../target/aarch64-apple-ios/release/$(LIB)) -headers include -library generated/simulator_fat/$(LIB) -headers include -output $@
60+
xcodebuild -create-xcframework -library $(wildcard ../../target/aarch64-apple-ios/release/$(LIB)) -headers include -library generated/simulator_fat/$(LIB) -headers include -output $@

bindings/c/include/libsql.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ typedef struct {
4141
int sync_interval;
4242
char with_webpki;
4343
char offline;
44+
const char *remote_encryption_key;
4445
} libsql_config;
4546

4647
typedef const libsql_connection *libsql_connection_t;

bindings/c/src/lib.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ pub unsafe extern "C" fn libsql_open_sync(
9898
sync_interval: 0,
9999
with_webpki: 0,
100100
offline: 0,
101+
remote_encryption_key: std::ptr::null(),
101102
};
102103
libsql_open_sync_with_config(config, out_db, out_err_msg)
103104
}
@@ -121,6 +122,7 @@ pub unsafe extern "C" fn libsql_open_sync_with_webpki(
121122
sync_interval: 0,
122123
with_webpki: 1,
123124
offline: 0,
125+
remote_encryption_key: std::ptr::null(),
124126
};
125127
libsql_open_sync_with_config(config, out_db, out_err_msg)
126128
}
@@ -271,6 +273,19 @@ pub unsafe extern "C" fn libsql_open_sync_with_config(
271273
.build();
272274
builder = builder.connector(https);
273275
}
276+
if !config.remote_encryption_key.is_null() {
277+
let key = unsafe { std::ffi::CStr::from_ptr(config.remote_encryption_key) };
278+
let key = match key.to_str() {
279+
Ok(k) => k,
280+
Err(e) => {
281+
set_err_msg(format!("Wrong encryption key: {e}"), out_err_msg);
282+
return 5;
283+
}
284+
};
285+
builder = builder.remote_encryption(libsql::EncryptionContext {
286+
key: libsql::EncryptionKey::Base64Encoded(key.to_string()),
287+
});
288+
};
274289
match RT.block_on(builder.build()) {
275290
Ok(db) => {
276291
let db = Box::leak(Box::new(libsql_database { db }));
@@ -325,6 +340,19 @@ pub unsafe extern "C" fn libsql_open_sync_with_config(
325340
let config = libsql::EncryptionConfig::new(libsql::Cipher::Aes256Cbc, key);
326341
builder = builder.encryption_config(config)
327342
};
343+
if !config.remote_encryption_key.is_null() {
344+
let key = unsafe { std::ffi::CStr::from_ptr(config.remote_encryption_key) };
345+
let key = match key.to_str() {
346+
Ok(k) => k,
347+
Err(e) => {
348+
set_err_msg(format!("Wrong encryption key: {e}"), out_err_msg);
349+
return 5;
350+
}
351+
};
352+
builder = builder.remote_encryption(libsql::EncryptionContext {
353+
key: libsql::EncryptionKey::Base64Encoded(key.to_string()),
354+
});
355+
};
328356
match RT.block_on(builder.build()) {
329357
Ok(db) => {
330358
let db = Box::leak(Box::new(libsql_database { db }));

bindings/c/src/types.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub struct libsql_config {
1515
pub sync_interval: std::ffi::c_int,
1616
pub with_webpki: std::ffi::c_char,
1717
pub offline: std::ffi::c_char,
18+
pub remote_encryption_key: *const std::ffi::c_char,
1819
}
1920

2021
#[derive(Clone, Debug)]

libsql-ffi/build.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,11 @@ fn build_multiple_ciphers(out_path: &Path) -> PathBuf {
485485
build.compiler(cxx);
486486
config.init_cxx_cfg(build);
487487
}
488+
let target = env::var("TARGET").unwrap();
489+
490+
if target.ends_with("apple-ios") {
491+
config.define("SQLITE3MC_OMIT_AES_HARDWARE_SUPPORT", "ON");
492+
}
488493

489494
if cfg!(feature = "wasmtime-bindings") {
490495
config.define("LIBSQL_ENABLE_WASM_RUNTIME", "1");
@@ -496,6 +501,14 @@ fn build_multiple_ciphers(out_path: &Path) -> PathBuf {
496501
.define("SQLITE_ENABLE_SESSION", "ON");
497502
}
498503

504+
if let Ok(abi) = env::var("CARGO_NDK_ANDROID_TARGET") {
505+
config.define("ANDROID_ABI", abi);
506+
}
507+
508+
if let Ok(platform) = env::var("ANDROID_PLATFORM") {
509+
config.define("ANDROID_PLATFORM", platform);
510+
}
511+
499512
config.build()
500513
}
501514

libsql-ffi/bundled/SQLite3MultipleCiphers/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,12 @@ if (CMAKE_C_COMPILER_ID STREQUAL "Clang" AND NOT (
313313
CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64"
314314
OR CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64"
315315
OR CMAKE_SYSTEM_PROCESSOR STREQUAL "arm"
316+
OR CMAKE_ANDROID_ARCH_ABI STREQUAL "arm64-v8a"
317+
OR CMAKE_ANDROID_ARCH_ABI STREQUAL "armeabi-v7a"
316318
))
317319
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse4.2 -maes -Wno-error=incompatible-function-pointer-types")
318320
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.2 -maes")
319321
endif()
320-
321322
set(_LIB_DIFINITIONS
322323
_LIB
323324
)

libsql/examples/encryption_sync.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ async fn main() {
2525
None
2626
};
2727

28-
let db_builder =
29-
Builder::new_synced_database(db_path, sync_url, auth_token).remote_encryption(encryption);
28+
let mut db_builder = Builder::new_synced_database(db_path, sync_url, auth_token);
29+
30+
if let Some(enc) = encryption {
31+
db_builder = db_builder.remote_encryption(enc);
32+
}
3033

3134
let db = match db_builder.build().await {
3235
Ok(db) => db,

0 commit comments

Comments
 (0)