Skip to content

Commit 5bfa592

Browse files
committed
iOS/Android Support
Add steps for Android PR comments
1 parent 07a679e commit 5bfa592

5 files changed

Lines changed: 69 additions & 2 deletions

File tree

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ libsql-sqlite3/**.o.tmp
99
/libsql-ffi/bundled/SQLite3MultipleCiphers/build/**
1010
# will be copied from bundled/src
1111
/libsql-ffi/bundled/SQLite3MultipleCiphers/src/sqlite3.c
12+
13+
/bindings/c/generated
14+
/bindings/c/**.xcframework
15+
/bindings/**/.DS_Store

bindings/c/Cargo.toml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ cbindgen = "0.24.0"
1313
[dependencies]
1414
bytes = "1.5.0"
1515
lazy_static = "1.4.0"
16-
libsql = { path = "../../libsql", features = ["encryption"] }
1716
tokio = { version = "1.29.1", features = [ "rt-multi-thread" ] }
1817
hyper-rustls = { version = "0.25", features = ["webpki-roots"]}
18+
19+
[target.'cfg(not(any(target_os = "ios", target_os = "android")))'.dependencies]
20+
libsql = { path = "../../libsql", features = ["encryption"] }
21+
22+
# Disable encryption for ios and android targets
23+
[target.'cfg(any(target_os = "ios", target_os = "android"))'.dependencies]
24+
libsql = { path = "../../libsql"}
25+
26+
27+
[profile.release]
28+
strip = "symbols"

bindings/c/Makefile

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
OS := $(shell uname)
22
CFLAGS := -Iinclude
33
LDFLAGS := -lm
4+
ARCHS_IOS = x86_64-apple-ios aarch64-apple-ios aarch64-apple-ios-sim
5+
ARCHS_ANDROID = aarch64-linux-android armv7-linux-androideabi x86_64-linux-android i686-linux-android
6+
LIB = libsql_experimental.a
7+
HEADER = libsql.h
8+
XCFRAMEWORK = libsql.xcframework
49

510
# Set LIBSQL_PATH to the default path if not provided
611
LIBSQL_EXPERIMENTAL_PATH ?= ../../target/release/libsql_experimental.a
@@ -9,8 +14,37 @@ ifeq ($(OS),Darwin)
914
CFLAGS += -framework Security -framework CoreServices
1015
endif
1116

12-
.PHONY: all
17+
.PHONY: all $(ARCHS_IOS) ios $(ARCHS_ANDROID) android
18+
1319
all: example
1420

1521
example: example.c
1622
$(CC) -o $@ $(CFLAGS) $< $(LIBSQL_EXPERIMENTAL_PATH) $(LDFLAGS)
23+
24+
android: $(ARCHS_ANDROID)
25+
rm -rf generated
26+
mkdir -p generated/jniLibs
27+
mkdir -p generated/jniLibs/arm64-v8a
28+
mkdir -p generated/jniLibs/armeabi-v7a
29+
mkdir -p generated/jniLibs/x86_64
30+
mkdir -p generated/jniLibs/x86
31+
32+
cp ../../target/aarch64-linux-android/release/$(LIB) generated/jniLibs/arm64-v8a/$(LIB)
33+
cp ../../target/armv7-linux-androideabi/release/$(LIB) generated/jniLibs/armeabi-v7a/$(LIB)
34+
cp ../../target/x86_64-linux-android/release/$(LIB) generated/jniLibs/x86_64/$(LIB)
35+
cp ../../target/i686-linux-android/release/$(LIB) generated/jniLibs/x86/$(LIB)
36+
37+
$(ARCHS_ANDROID): %:
38+
cargo ndk --target $@ --platform 31 build --release
39+
40+
ios: $(XCFRAMEWORK)
41+
42+
$(ARCHS_IOS): %:
43+
cargo build --release --target $@
44+
45+
$(XCFRAMEWORK): $(ARCHS_IOS)
46+
rm -rf generated
47+
mkdir -p generated/simulator_fat
48+
rm -rf $@
49+
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 $@

libsql-ffi/build.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,24 @@ fn build_multiple_ciphers(out_path: &Path) {
312312
.open(toolchain_path.clone())
313313
.unwrap();
314314

315+
if target.contains("x86_64-apple-ios") {
316+
cmake_opts.push(&cmake_toolchain_opt);
317+
writeln!(toolchain_file, "set(CMAKE_SYSTEM_NAME \"iOS\")").unwrap();
318+
writeln!(toolchain_file, "set(CMAKE_SYSTEM_PROCESSOR \"x86_64\")").unwrap();
319+
}
320+
321+
if target.contains("aarch64-apple-ios-sim") {
322+
cmake_opts.push(&cmake_toolchain_opt);
323+
writeln!(toolchain_file, "set(CMAKE_SYSTEM_NAME \"Darwin\")").unwrap();
324+
writeln!(toolchain_file, "set(CMAKE_SYSTEM_PROCESSOR \"arm64\")").unwrap();
325+
}
326+
327+
if target.contains("aarch64-apple-ios") {
328+
cmake_opts.push(&cmake_toolchain_opt);
329+
writeln!(toolchain_file, "set(CMAKE_SYSTEM_NAME \"iOS\")").unwrap();
330+
writeln!(toolchain_file, "set(CMAKE_SYSTEM_PROCESSOR \"arm64\")").unwrap();
331+
}
332+
315333
if let Some(ref cc) = cc {
316334
let cc = cc.clone().into_string().unwrap();
317335
if cc.contains("aarch64") && cc.contains("linux") {

rust-toolchain.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
[toolchain]
22
profile = "default"
33
channel = "1.78.0"
4+
targets = ["x86_64-apple-ios", "aarch64-apple-ios", "aarch64-apple-ios-sim", "aarch64-linux-android", "armv7-linux-androideabi", "x86_64-linux-android", "i686-linux-android"]

0 commit comments

Comments
 (0)