Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React Native support #1423

Merged
merged 2 commits into from
Jun 25, 2024
Merged
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ libsql-sqlite3/**.o.tmp
/libsql-ffi/bundled/SQLite3MultipleCiphers/build/**
# will be copied from bundled/src
/libsql-ffi/bundled/SQLite3MultipleCiphers/src/sqlite3.c

/bindings/c/generated
/bindings/c/**.xcframework
/bindings/**/.DS_Store
17 changes: 16 additions & 1 deletion bindings/c/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,21 @@ cbindgen = "0.24.0"
[dependencies]
bytes = "1.5.0"
lazy_static = "1.4.0"
libsql = { path = "../../libsql", features = ["encryption"] }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not an acceptable change. Most of our projects that use C bindings depend on the encryption feature.

tokio = { version = "1.29.1", features = [ "rt-multi-thread" ] }
hyper-rustls = { version = "0.25", features = ["webpki-roots"]}

[target.'cfg(not(any(target_os = "ios", target_os = "android")))'.dependencies]
libsql = { path = "../../libsql", features = ["encryption"] }

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


# The produced binaries are too large for mobiles
# When compiling for iOS or Android, you should turn on symbol stripping, lto and cut debug symbols
# [profile.release]
# debug = false # Exclude debug symbols
# strip = "symbols" # Exclude the rest of the symbols
# # opt-level = "z" # Did not use this, but it equals C++'s optimize for size (O3?)
# lto = true # Link time optimization, not sure what this does but it helps reduce the size
36 changes: 35 additions & 1 deletion bindings/c/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
OS := $(shell uname)
CFLAGS := -Iinclude
LDFLAGS := -lm
ARCHS_IOS = x86_64-apple-ios aarch64-apple-ios aarch64-apple-ios-sim
ARCHS_ANDROID = aarch64-linux-android armv7-linux-androideabi x86_64-linux-android i686-linux-android
LIB = libsql_experimental.a
HEADER = libsql.h
XCFRAMEWORK = libsql.xcframework

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

.PHONY: all
.PHONY: all $(ARCHS_IOS) ios $(ARCHS_ANDROID) android

all: example

example: example.c
$(CC) -o $@ $(CFLAGS) $< $(LIBSQL_EXPERIMENTAL_PATH) $(LDFLAGS)

android: $(ARCHS_ANDROID)
rm -rf generated
mkdir -p generated/jniLibs
mkdir -p generated/jniLibs/arm64-v8a
mkdir -p generated/jniLibs/armeabi-v7a
mkdir -p generated/jniLibs/x86_64
mkdir -p generated/jniLibs/x86

cp ../../target/aarch64-linux-android/release/$(LIB) generated/jniLibs/arm64-v8a/$(LIB)
cp ../../target/armv7-linux-androideabi/release/$(LIB) generated/jniLibs/armeabi-v7a/$(LIB)
cp ../../target/x86_64-linux-android/release/$(LIB) generated/jniLibs/x86_64/$(LIB)
cp ../../target/i686-linux-android/release/$(LIB) generated/jniLibs/x86/$(LIB)

$(ARCHS_ANDROID): %:
cargo ndk --target $@ --platform 31 build --release

ios: $(XCFRAMEWORK)

$(ARCHS_IOS): %:
cargo build --release --target $@

$(XCFRAMEWORK): $(ARCHS_IOS)
rm -rf generated
mkdir -p generated/simulator_fat
rm -rf $@
lipo -create $(wildcard ../../target/x86_64-apple-ios/release/$(LIB)) $(wildcard ../../target/aarch64-apple-ios-sim/release/$(LIB)) -output generated/simulator_fat/$(LIB)
xcodebuild -create-xcframework -library $(wildcard ../../target/aarch64-apple-ios/release/$(LIB)) -headers include -library generated/simulator_fat/$(LIB) -headers include -output $@
1 change: 1 addition & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[toolchain]
profile = "default"
channel = "1.78.0"
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"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we need a desktop targets for linux and macos as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want, it makes it easier to set up cross compilation on new machines as you don't have to run the rustup install target ... commands but this is entirely optional

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This force the installation of too many toolchains that are useless most of the time, and it just broke my installation by creating conflicts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to remove it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did it create conflicts? It seems pretty harmless except for using some disk space, no?

Loading