Skip to content

Commit e3c73cf

Browse files
authored
Mobile target cross-compilation of sqlite3mc (#2100)
Used in OP-Engineering/op-sqlite#286
2 parents 02333dc + d032786 commit e3c73cf

File tree

4 files changed

+30
-12
lines changed

4 files changed

+30
-12
lines changed

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 $@

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
)

0 commit comments

Comments
 (0)