Skip to content

Commit 7c45d0a

Browse files
committed
iOS dylib
1 parent fa26ac4 commit 7c45d0a

File tree

4 files changed

+147
-40
lines changed

4 files changed

+147
-40
lines changed

bindings/c/Makefile

Lines changed: 56 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,61 @@
1-
OS := $(shell uname)
2-
CFLAGS := -Iinclude
3-
LDFLAGS := -lm
41
ARCHS_IOS = aarch64-apple-ios aarch64-apple-ios-sim
52
ARCHS_ANDROID = aarch64-linux-android armv7-linux-androideabi x86_64-linux-android i686-linux-android
6-
LIB = libsql_experimental.a
3+
IOS_LIB_FILE = libsql_experimental.dylib
4+
IOS_FINAL_LIB_FILE = libsql_experimental
5+
LIB_FILE = libsql_experimental.so
6+
XCFRAMEWORK = libsql_experimental.xcframework
77
HEADER = libsql.h
8-
XCFRAMEWORK = libsql.xcframework
98

10-
# Set LIBSQL_PATH to the default path if not provided
11-
LIBSQL_EXPERIMENTAL_PATH ?= ../../target/release/libsql_experimental.a
9+
notify:
10+
osascript -e 'display notification "Build completed" with title "libsql"'
11+
echo "🟢 Build Completed!"
1212

13-
ifeq ($(OS),Darwin)
14-
CFLAGS += -framework Security -framework CoreServices
15-
endif
13+
lint:
14+
cargo clippy --all-features --all-targets -- --no-deps -D warnings
1615

17-
.PHONY: all $(ARCHS_IOS) ios $(ARCHS_ANDROID) android
16+
fix:
17+
cargo clippy --all-targets --all-features --fix --allow-dirty --allow-staged
18+
cargo fmt --all
1819

19-
all: example
20+
nuke:
21+
rm -rf ./target
2022

21-
example: example.c
22-
$(CC) -o $@ $(CFLAGS) $< $(LIBSQL_EXPERIMENTAL_PATH) $(LDFLAGS)
23+
ios: clean ios-build package-dylibs notify
24+
25+
clean:
26+
rm -rf generated/$(XCFRAMEWORK)
27+
28+
package-dylibs:
29+
mkdir -p generated
30+
# Delete old files
31+
rm -rf generated/libsql*.xcframework
32+
33+
# Reset the .xcframeworks from the templates
34+
cp -r templates/libsql*.xcframework generated
35+
36+
# Pack device dylibs
37+
cp ../../target/aarch64-apple-ios/release/$(IOS_LIB_FILE) generated/$(IOS_FINAL_LIB_FILE)
38+
39+
cp generated/$(IOS_FINAL_LIB_FILE) generated/libsql_experimental.xcframework/ios-arm64/libsql_experimental.framework/
40+
install_name_tool -id @rpath/libsql_experimental.framework/$(IOS_FINAL_LIB_FILE) generated/libsql_experimental.xcframework/ios-arm64/libsql_experimental.framework/$(IOS_FINAL_LIB_FILE)
41+
codesign -f -s - --identifier com.turso.libsql-experimental generated/libsql_experimental.xcframework/ios-arm64/libsql_experimental.framework/$(IOS_FINAL_LIB_FILE)
42+
43+
mkdir -p generated/libsql_experimental.xcframework/ios-arm64/libsql_experimental.framework/Headers
44+
cp include/$(HEADER) generated/libsql_experimental.xcframework/ios-arm64/libsql_experimental.framework/Headers/
45+
46+
# Pack simulator dylibs
47+
cp ../../target/aarch64-apple-ios-sim/release/$(IOS_LIB_FILE) generated/$(IOS_FINAL_LIB_FILE)
48+
49+
cp generated/$(IOS_FINAL_LIB_FILE) generated/libsql_experimental.xcframework/ios-arm64-simulator/libsql_experimental.framework/
50+
install_name_tool -id @rpath/libsql_experimental.framework/$(IOS_FINAL_LIB_FILE) generated/libsql_experimental.xcframework/ios-arm64-simulator/libsql_experimental.framework/$(IOS_FINAL_LIB_FILE)
51+
codesign -f -s - --identifier com.turso.libsql-experimental generated/libsql_experimental.xcframework/ios-arm64-simulator/libsql_experimental.framework/$(IOS_FINAL_LIB_FILE)
52+
53+
mkdir -p generated/libsql_experimental.xcframework/ios-arm64-simulator/libsql_experimental.framework/Headers
54+
cp include/$(HEADER) generated/libsql_experimental.xcframework/ios-arm64-simulator/libsql_experimental.framework/Headers/
55+
56+
ios-build:
57+
cargo build --release --target aarch64-apple-ios
58+
cargo build --release --target aarch64-apple-ios-sim
2359

2460
android: $(ARCHS_ANDROID)
2561
rm -rf generated
@@ -28,33 +64,13 @@ android: $(ARCHS_ANDROID)
2864
mkdir -p generated/jniLibs/armeabi-v7a
2965
mkdir -p generated/jniLibs/x86_64
3066
mkdir -p generated/jniLibs/x86
67+
mkdir -p generated/jniLibs/include
3168

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)
69+
cp ../../target/aarch64-linux-android/release/$(LIB_FILE) generated/jniLibs/arm64-v8a/$(LIB_FILE)
70+
cp ../../target/armv7-linux-androideabi/release/$(LIB_FILE) generated/jniLibs/armeabi-v7a/$(LIB_FILE)
71+
cp ../../target/x86_64-linux-android/release/$(LIB_FILE) generated/jniLibs/x86_64/$(LIB_FILE)
72+
cp ../../target/i686-linux-android/release/$(LIB_FILE) generated/jniLibs/x86/$(LIB_FILE)
73+
cp include/$(HEADER) generated/jniLibs/include/
3674

3775
$(ARCHS_ANDROID): %:
3876
cargo ndk --target $@ --platform 31 build --release
39-
40-
ios: $(XCFRAMEWORK)
41-
42-
$(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
56-
rm -rf generated
57-
mkdir -p generated/simulator_fat
58-
rm -rf $@
59-
lipo -create $(wildcard ../../target/x86_64-apple-ios/release/$(LIB)) $(wildcard ../../target/aarch64-apple-ios-sim/release/$(LIB)) -output generated/simulator_fat/$(LIB)
60-
xcodebuild -create-xcframework -library $(wildcard ../../target/aarch64-apple-ios/release/$(LIB)) -headers include -library generated/simulator_fat/$(LIB) -headers include -output $@
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>AvailableLibraries</key>
6+
<array>
7+
<dict>
8+
<key>LibraryIdentifier</key>
9+
<string>ios-arm64</string>
10+
<key>LibraryPath</key>
11+
<string>libsql_experimental.framework</string>
12+
<key>SupportedArchitectures</key>
13+
<array>
14+
<string>arm64</string>
15+
</array>
16+
<key>SupportedPlatform</key>
17+
<string>ios</string>
18+
</dict>
19+
<dict>
20+
<key>LibraryIdentifier</key>
21+
<string>ios-arm64-simulator</string>
22+
<key>LibraryPath</key>
23+
<string>libsql_experimental.framework</string>
24+
<key>SupportedArchitectures</key>
25+
<array>
26+
<string>arm64</string>
27+
</array>
28+
<key>SupportedPlatform</key>
29+
<string>ios</string>
30+
<key>SupportedPlatformVariant</key>
31+
<string>simulator</string>
32+
</dict>
33+
</array>
34+
<key>CFBundlePackageType</key>
35+
<string>XFWK</string>
36+
<key>XCFrameworkFormatVersion</key>
37+
<string>1.0</string>
38+
<key>CFBundleVersion</key>
39+
<string>1.0.0</string>
40+
<key>CFBundleShortVersionString</key>
41+
<string>1.0.0</string>
42+
</dict>
43+
</plist>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>en</string>
7+
<key>CFBundleExecutable</key>
8+
<string>libsql_experimental</string>
9+
<key>CFBundleIdentifier</key>
10+
<string>com.turso.libsql-experimental</string>
11+
<key>CFBundleInfoDictionaryVersion</key>
12+
<string>6.0</string>
13+
<key>CFBundlePackageType</key>
14+
<string>FMWK</string>
15+
<key>CFBundleSignature</key>
16+
<string>????</string>
17+
<key>CFBundleVersion</key>
18+
<string>1.0.0</string>
19+
<key>CFBundleShortVersionString</key>
20+
<string>1.0.0</string>
21+
<key>MinimumOSVersion</key>
22+
<string>13.0</string>
23+
</dict>
24+
</plist>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>en</string>
7+
<key>CFBundleExecutable</key>
8+
<string>libsql_experimental</string>
9+
<key>CFBundleIdentifier</key>
10+
<string>com.turso.libsql-experimental</string>
11+
<key>CFBundleInfoDictionaryVersion</key>
12+
<string>6.0</string>
13+
<key>CFBundlePackageType</key>
14+
<string>FMWK</string>
15+
<key>CFBundleSignature</key>
16+
<string>????</string>
17+
<key>CFBundleVersion</key>
18+
<string>1.0.0</string>
19+
<key>CFBundleShortVersionString</key>
20+
<string>1.0.0</string>
21+
<key>MinimumOSVersion</key>
22+
<string>13.0</string>
23+
</dict>
24+
</plist>

0 commit comments

Comments
 (0)