Skip to content

Commit b07e3e1

Browse files
authored
Merge pull request #73 from zifeo/main
feat: add watchOS support (tentative)
2 parents 3285e39 + 9e94504 commit b07e3e1

File tree

10 files changed

+197
-23
lines changed

10 files changed

+197
-23
lines changed

.cargo/config.toml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# Previously we added this to rustflags for all linux builds:
32
# "-C", "link-arg=-lgcc_eh"
43
# It was to fix this error when loading the loadable extension:
@@ -86,3 +85,18 @@ rustflags = [
8685
rustflags = [
8786
"-C", "link-arg=-Wl,-soname,libpowersync.so",
8887
]
88+
89+
[target.aarch64-apple-watchos]
90+
rustflags = [
91+
"-C", "link-arg=-mwatchos-version-min=9.0",
92+
]
93+
94+
[target.aarch64-apple-watchos-sim]
95+
rustflags = [
96+
"-C", "link-arg=-mwatchsimulator-version-min=9.0",
97+
]
98+
99+
[target.x86_64-apple-watchos-sim]
100+
rustflags = [
101+
"-C", "link-arg=-mwatchos-version-min=9.0",
102+
]

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ target/
99
*.tar.gz
1010
*.tar.xz
1111
*.zip
12+
.build

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,4 @@ repository = "https://github.com/powersync-ja/powersync-sqlite-core"
3838

3939
[workspace.dependencies]
4040
sqlite_nostd = { path="./sqlite-rs-embedded/sqlite_nostd" }
41+

Package.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// swift-tools-version: 5.7
2+
3+
// NOTE! This is never released, we're only using this to support local builds builds for the
4+
// Swift SDK.
5+
import PackageDescription
6+
let packageName = "PowerSyncSQLiteCore"
7+
8+
let package = Package(
9+
name: packageName,
10+
platforms: [
11+
.iOS(.v13),
12+
.macOS(.v10_15),
13+
.watchOS(.v9)
14+
],
15+
products: [
16+
.library(
17+
name: packageName,
18+
targets: [packageName]),
19+
],
20+
targets: [
21+
.binaryTarget(
22+
name: packageName,
23+
path: "powersync-sqlite-core.xcframework"
24+
)
25+
]
26+
)

crates/static/Cargo.toml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[package]
2+
name = "powersync_static"
3+
edition.workspace = true
4+
version.workspace = true
5+
homepage.workspace = true
6+
repository.workspace = true
7+
license.workspace = true
8+
authors.workspace = true
9+
keywords.workspace = true
10+
11+
[lib]
12+
name = "powersync"
13+
crate-type = ["staticlib"]
14+
15+
[dependencies]
16+
sqlite_nostd = { workspace=true }
17+
18+
[dependencies.powersync_core]
19+
path = "../core"
20+
default-features = false
21+
features = []
22+
23+
[features]
24+
default = ["powersync_core/static", "powersync_core/omit_load_extension", "sqlite_nostd/omit_load_extension"]

crates/static/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Builds the core extension as a static library, exposing the `powersync_init_static` function to load it.

crates/static/src/lib.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#![no_std]
2+
#![feature(vec_into_raw_parts)]
3+
#![feature(core_intrinsics)]
4+
#![allow(internal_features)]
5+
#![feature(lang_items)]
6+
7+
extern crate alloc;
8+
9+
// Defines sqlite3_powersync_init
10+
#[allow(unused_imports)]
11+
use powersync_core;
12+
13+
// Use the SQLite allocator, allowing us to freely transfer memory between SQLite and Rust.
14+
#[cfg(not(test))]
15+
use sqlite_nostd::SQLite3Allocator;
16+
17+
#[cfg(not(test))]
18+
#[global_allocator]
19+
static ALLOCATOR: SQLite3Allocator = SQLite3Allocator {};
20+
21+
// Custom Panic handler for WASM and other no_std builds
22+
#[cfg(not(test))]
23+
#[panic_handler]
24+
fn panic(_info: &core::panic::PanicInfo) -> ! {
25+
core::intrinsics::abort()
26+
}
27+
28+
#[cfg(not(target_family = "wasm"))]
29+
#[cfg(not(test))]
30+
#[lang = "eh_personality"]
31+
extern "C" fn eh_personality() {}

powersync-sqlite-core.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ PowerSync extension for SQLite.
1313
s.source = { :http => "https://github.com/powersync-ja/powersync-sqlite-core/releases/download/v#{s.version}/powersync-sqlite-core.xcframework.zip" }
1414
s.vendored_frameworks = 'powersync-sqlite-core.xcframework'
1515

16-
1716
s.ios.deployment_target = '11.0'
1817
s.osx.deployment_target = '10.13'
18+
s.watchos.deployment_target = '9.0'
1919
end

tool/build_xcframework.sh

Lines changed: 89 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,48 @@ set -e
33

44
# Adapted from https://github.com/vlcn-io/cr-sqlite/blob/main/core/all-ios-loadable.sh
55

6-
76
BUILD_DIR=./build
8-
DIST_PACKAGE_DIR=./dist
7+
TARGETS=(
8+
# iOS and simulator
9+
aarch64-apple-ios
10+
aarch64-apple-ios-sim
11+
x86_64-apple-ios
912

10-
function createXcframework() {
11-
plist=$(cat << EOF
13+
# macOS
14+
aarch64-apple-darwin
15+
x86_64-apple-darwin
16+
17+
# watchOS and simulator
18+
aarch64-apple-watchos
19+
aarch64-apple-watchos-sim
20+
x86_64-apple-watchos-sim
21+
arm64_32-apple-watchos
22+
)
23+
VERSION=0.4.0
24+
25+
function generatePlist() {
26+
min_os_version=0
27+
additional_keys=""
28+
# We support versions 11.0 or later for iOS and macOS. For watchOS, we need 9.0 or later.
29+
case $1 in
30+
*"watchos"*)
31+
additional_keys=$(cat <<EOF
32+
<key>CFBundleSupportedPlatforms</key>
33+
<array>
34+
<string>WatchOS</string>
35+
</array>
36+
<key>UIDeviceFamily</key>
37+
<array>
38+
<integer>4</integer>
39+
</array>
40+
EOF
41+
)
42+
min_os_version="9.0";;
43+
*)
44+
min_os_version="11.0";;
45+
esac
46+
47+
cat <<EOF
1248
<?xml version="1.0" encoding="UTF-8"?>
1349
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
1450
<plist version="1.0">
@@ -26,34 +62,41 @@ function createXcframework() {
2662
<key>CFBundleSignature</key>
2763
<string>????</string>
2864
<key>MinimumOSVersion</key>
29-
<string>11.0</string>
65+
<string>$min_os_version</string>
3066
<key>CFBundleVersion</key>
31-
<string>0.4.0</string>
67+
<string>$VERSION</string>
3268
<key>CFBundleShortVersionString</key>
33-
<string>0.4.0</string>
69+
<string>$VERSION</string>
70+
$additional_keys
3471
</dict>
3572
</plist>
3673
EOF
37-
)
74+
}
75+
76+
function createXcframework() {
77+
ios_plist=$(generatePlist "ios")
78+
macos_plist=$(generatePlist "macos")
79+
watchos_plist=$(generatePlist "watchos")
80+
3881
echo "===================== create ios device framework ====================="
3982
mkdir -p "${BUILD_DIR}/ios-arm64/powersync-sqlite-core.framework"
40-
echo "${plist}" > "${BUILD_DIR}/ios-arm64/powersync-sqlite-core.framework/Info.plist"
83+
echo "${ios_plist}" > "${BUILD_DIR}/ios-arm64/powersync-sqlite-core.framework/Info.plist"
4184
cp -f "./target/aarch64-apple-ios/release_apple/libpowersync.dylib" "${BUILD_DIR}/ios-arm64/powersync-sqlite-core.framework/powersync-sqlite-core"
4285
install_name_tool -id "@rpath/powersync-sqlite-core.framework/powersync-sqlite-core" "${BUILD_DIR}/ios-arm64/powersync-sqlite-core.framework/powersync-sqlite-core"
4386
# Generate dSYM for iOS Device
4487
dsymutil "${BUILD_DIR}/ios-arm64/powersync-sqlite-core.framework/powersync-sqlite-core" -o "${BUILD_DIR}/ios-arm64/powersync-sqlite-core.framework.dSYM"
4588

4689
echo "===================== create ios simulator framework ====================="
4790
mkdir -p "${BUILD_DIR}/ios-arm64_x86_64-simulator/powersync-sqlite-core.framework"
48-
echo "${plist}" > "${BUILD_DIR}/ios-arm64_x86_64-simulator/powersync-sqlite-core.framework/Info.plist"
91+
echo "${ios_plist}" > "${BUILD_DIR}/ios-arm64_x86_64-simulator/powersync-sqlite-core.framework/Info.plist"
4992
lipo ./target/aarch64-apple-ios-sim/release_apple/libpowersync.dylib ./target/x86_64-apple-ios/release_apple/libpowersync.dylib -create -output "${BUILD_DIR}/ios-arm64_x86_64-simulator/powersync-sqlite-core.framework/powersync-sqlite-core"
5093
install_name_tool -id "@rpath/powersync-sqlite-core.framework/powersync-sqlite-core" "${BUILD_DIR}/ios-arm64_x86_64-simulator/powersync-sqlite-core.framework/powersync-sqlite-core"
5194
# Generate dSYM for iOS Simulator
5295
dsymutil "${BUILD_DIR}/ios-arm64_x86_64-simulator/powersync-sqlite-core.framework/powersync-sqlite-core" -o "${BUILD_DIR}/ios-arm64_x86_64-simulator/powersync-sqlite-core.framework.dSYM"
5396

5497
echo "===================== create macos framework ====================="
5598
mkdir -p "${BUILD_DIR}/macos-arm64_x86_64/powersync-sqlite-core.framework/Versions/A/Resources"
56-
echo "${plist}" > "${BUILD_DIR}/macos-arm64_x86_64/powersync-sqlite-core.framework/Versions/A/Resources/Info.plist"
99+
echo "${ios_plist}" > "${BUILD_DIR}/macos-arm64_x86_64/powersync-sqlite-core.framework/Versions/A/Resources/Info.plist"
57100
lipo ./target/x86_64-apple-darwin/release_apple/libpowersync.dylib ./target/aarch64-apple-darwin/release_apple/libpowersync.dylib -create -output "${BUILD_DIR}/macos-arm64_x86_64/powersync-sqlite-core.framework/Versions/A/powersync-sqlite-core"
58101
install_name_tool -id "@rpath/powersync-sqlite-core.framework/powersync-sqlite-core" "${BUILD_DIR}/macos-arm64_x86_64/powersync-sqlite-core.framework/Versions/A/powersync-sqlite-core"
59102
ln -sf A "${BUILD_DIR}/macos-arm64_x86_64/powersync-sqlite-core.framework/Versions/Current"
@@ -62,17 +105,37 @@ EOF
62105
# Generate dSYM for macOS
63106
dsymutil "${BUILD_DIR}/macos-arm64_x86_64/powersync-sqlite-core.framework/Versions/A/powersync-sqlite-core" -o "${BUILD_DIR}/macos-arm64_x86_64/powersync-sqlite-core.framework.dSYM"
64107

108+
echo "===================== create watchos device framework ====================="
109+
mkdir -p "${BUILD_DIR}/watchos-arm64_arm64_32_armv7k/powersync-sqlite-core.framework/Versions/A/Resources"
110+
echo "${watchos_plist}" > "${BUILD_DIR}/watchos-arm64_arm64_32_armv7k/powersync-sqlite-core.framework/Versions/A/Resources/Info.plist"
111+
lipo ./target/aarch64-apple-watchos/release_apple/libpowersync.a ./target/arm64_32-apple-watchos/release_apple/libpowersync.a -create -output "${BUILD_DIR}/watchos-arm64_arm64_32_armv7k/powersync-sqlite-core.framework/Versions/A/powersync-sqlite-core"
112+
# install_name_tool isn't necessary, we use a statically-linked library
113+
ln -sf A "${BUILD_DIR}/watchos-arm64_arm64_32_armv7k/powersync-sqlite-core.framework/Versions/Current"
114+
ln -sf Versions/Current/powersync-sqlite-core "${BUILD_DIR}/watchos-arm64_arm64_32_armv7k/powersync-sqlite-core.framework/powersync-sqlite-core"
115+
ln -sf Versions/Current/Resources "${BUILD_DIR}/watchos-arm64_arm64_32_armv7k/powersync-sqlite-core.framework/Resources"
116+
117+
echo "===================== create watchos simulator framework ====================="
118+
mkdir -p "${BUILD_DIR}/watchos-arm64_x86_64-simulator/powersync-sqlite-core.framework/Versions/A/Resources"
119+
echo "${watchos_plist}" > "${BUILD_DIR}/watchos-arm64_x86_64-simulator/powersync-sqlite-core.framework/Versions/A/Resources/Info.plist"
120+
lipo ./target/aarch64-apple-watchos-sim/release_apple/libpowersync.a ./target/x86_64-apple-watchos-sim/release_apple/libpowersync.a -create -output "${BUILD_DIR}/watchos-arm64_x86_64-simulator/powersync-sqlite-core.framework/Versions/A/powersync-sqlite-core"
121+
# install_name_tool isn't necessary, we use a statically-linked library
122+
ln -sf A "${BUILD_DIR}/watchos-arm64_x86_64-simulator/powersync-sqlite-core.framework/Versions/Current"
123+
ln -sf Versions/Current/powersync-sqlite-core "${BUILD_DIR}/watchos-arm64_x86_64-simulator/powersync-sqlite-core.framework/powersync-sqlite-core"
124+
ln -sf Versions/Current/Resources "${BUILD_DIR}/watchos-arm64_x86_64-simulator/powersync-sqlite-core.framework/Resources"
125+
65126
echo "===================== create xcframework ====================="
66127
rm -rf "${BUILD_DIR}/powersync-sqlite-core.xcframework"
67-
# "-debug-symbols" requires the absolute path
128+
68129
xcodebuild -create-xcframework \
69130
-framework "${BUILD_DIR}/ios-arm64/powersync-sqlite-core.framework" \
70131
-debug-symbols "$(pwd -P)/${BUILD_DIR}/ios-arm64/powersync-sqlite-core.framework.dSYM" \
71132
-framework "${BUILD_DIR}/ios-arm64_x86_64-simulator/powersync-sqlite-core.framework" \
72133
-debug-symbols "$(pwd -P)/${BUILD_DIR}/ios-arm64_x86_64-simulator/powersync-sqlite-core.framework.dSYM" \
73134
-framework "${BUILD_DIR}/macos-arm64_x86_64/powersync-sqlite-core.framework" \
74135
-debug-symbols "$(pwd -P)/${BUILD_DIR}/macos-arm64_x86_64/powersync-sqlite-core.framework.dSYM" \
75-
-output "${BUILD_DIR}/powersync-sqlite-core.xcframework" \
136+
-framework "${BUILD_DIR}/watchos-arm64_arm64_32_armv7k/powersync-sqlite-core.framework" \
137+
-framework "${BUILD_DIR}/watchos-arm64_x86_64-simulator/powersync-sqlite-core.framework" \
138+
-output "${BUILD_DIR}/powersync-sqlite-core.xcframework"
76139

77140
cp -Rf "${BUILD_DIR}/powersync-sqlite-core.xcframework" "powersync-sqlite-core.xcframework"
78141
zip -r --symlinks powersync-sqlite-core.xcframework.zip powersync-sqlite-core.xcframework LICENSE README.md
@@ -84,13 +147,18 @@ EOF
84147

85148
rm -rf powersync-sqlite-core.xcframework
86149

87-
# iOS
88-
cargo build -p powersync_loadable --profile release_apple --target aarch64-apple-ios -Zbuild-std
89-
# Simulator
90-
cargo build -p powersync_loadable --profile release_apple --target aarch64-apple-ios-sim -Zbuild-std
91-
cargo build -p powersync_loadable --profile release_apple --target x86_64-apple-ios -Zbuild-std
92-
# macOS
93-
cargo build -p powersync_loadable --profile release_apple --target aarch64-apple-darwin -Zbuild-std
94-
cargo build -p powersync_loadable --profile release_apple --target x86_64-apple-darwin -Zbuild-std
150+
for TARGET in ${TARGETS[@]}; do
151+
echo "Building PowerSync loadable extension for $TARGET"
152+
153+
if [[ $TARGET == *"watchos"* ]]; then
154+
cargo build \
155+
-p powersync_static \
156+
--profile release_apple \
157+
--target $TARGET \
158+
-Zbuild-std
159+
else
160+
cargo build -p powersync_loadable --profile release_apple --target $TARGET -Zbuild-std
161+
fi
162+
done
95163

96164
createXcframework

0 commit comments

Comments
 (0)