-
Notifications
You must be signed in to change notification settings - Fork 6
feat: add watchOS support (tentative) #73
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,32 @@ | ||
fn main() { | ||
let mut cfg = cc::Build::new(); | ||
let target = std::env::var("TARGET").unwrap(); | ||
let is_watchos = target.contains("watchos") || target.contains("watchsimulator"); | ||
|
||
// Compile the SQLite source | ||
cfg.file("./sqlite/sqlite3.c"); | ||
cfg.file("./sqlite/shell.c"); | ||
cfg.include("./sqlite"); | ||
|
||
// General SQLite options | ||
cfg.define("SQLITE_THREADSAFE", Some("0")); | ||
cfg.define("SQLITE_ENABLE_BYTECODE_VTAB", Some("1")); | ||
|
||
// Compile with readline support (also requires -lreadline / cargo:rustc-link-lib=readline below) | ||
cfg.define("HAVE_READLINE", Some("1")); | ||
if is_watchos { | ||
// For watchOS, don't build the shell and disable readline | ||
cfg.define("HAVE_READLINE", Some("0")); | ||
cfg.define("HAVE_EDITLINE", Some("0")); | ||
cfg.define("SQLITE_OMIT_SYSTEM", Some("1")); | ||
} else { | ||
// For other platforms, build the shell with readline | ||
cfg.file("./sqlite/shell.c"); | ||
cfg.define("HAVE_READLINE", Some("1")); | ||
println!("cargo:rustc-link-lib=readline"); | ||
} | ||
|
||
// Silence warnings generated for SQLite | ||
cfg.flag("-Wno-implicit-fallthrough"); | ||
cfg.flag("-Wno-unused-parameter"); | ||
cfg.flag("-Wno-null-pointer-subtraction"); | ||
|
||
cfg.compile("sqlite"); | ||
|
||
println!("cargo:rustc-link-lib=readline"); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,12 +3,11 @@ set -e | |
|
||
# Adapted from https://github.com/vlcn-io/cr-sqlite/blob/main/core/all-ios-loadable.sh | ||
|
||
|
||
BUILD_DIR=./build | ||
DIST_PACKAGE_DIR=./dist | ||
|
||
function createXcframework() { | ||
plist=$(cat << EOF | ||
ios_plist=$( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's technically not just ios, we're using this for macOS too. I don't know what a better name would be either though, maybe |
||
cat <<EOF | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
|
@@ -34,26 +33,76 @@ function createXcframework() { | |
</dict> | ||
</plist> | ||
EOF | ||
) | ||
) | ||
|
||
watchos_plist=$( | ||
cat <<EOF | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CFBundleDevelopmentRegion</key> | ||
<string>en</string> | ||
<key>CFBundleExecutable</key> | ||
<string>powersync-sqlite-core</string> | ||
<key>CFBundleIdentifier</key> | ||
<string>co.powersync.sqlitecore</string> | ||
<key>CFBundleInfoDictionaryVersion</key> | ||
<string>6.0</string> | ||
<key>CFBundlePackageType</key> | ||
<string>FMWK</string> | ||
<key>CFBundleSignature</key> | ||
<string>????</string> | ||
<key>MinimumOSVersion</key> | ||
<string>7.0</string> | ||
<key>CFBundleVersion</key> | ||
<string>0.3.12</string> | ||
<key>CFBundleShortVersionString</key> | ||
<string>0.3.12</string> | ||
Comment on lines
+58
to
+61
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be nice if we could extract the common prefix of those files into a shared variable, e.g. this one uses 0.3.12 while our other builds are at 0.3.14. Keeping those in sync would be easier that way. |
||
<key>UIDeviceFamily</key> | ||
<array> | ||
<integer>4</integer> | ||
</array> | ||
<key>DTSDKName</key> | ||
<string>watchos</string> | ||
<key>DTPlatformName</key> | ||
<string>watchos</string> | ||
<key>DTPlatformVersion</key> | ||
<string>7.0</string> | ||
<key>DTXcode</key> | ||
<string>1500</string> | ||
<key>DTXcodeBuild</key> | ||
<string>15A240d</string> | ||
<key>DTCompiler</key> | ||
<string>com.apple.compilers.llvm.clang.1_0</string> | ||
<key>DTPlatformBuild</key> | ||
<string>21R355</string> | ||
<key>BuildMachineOSBuild</key> | ||
<string>23D60</string> | ||
</dict> | ||
</plist> | ||
EOF | ||
) | ||
|
||
echo "===================== create ios device framework =====================" | ||
mkdir -p "${BUILD_DIR}/ios-arm64/powersync-sqlite-core.framework" | ||
echo "${plist}" > "${BUILD_DIR}/ios-arm64/powersync-sqlite-core.framework/Info.plist" | ||
echo "${ios_plist}" >"${BUILD_DIR}/ios-arm64/powersync-sqlite-core.framework/Info.plist" | ||
cp -f "./target/aarch64-apple-ios/release_apple/libpowersync.dylib" "${BUILD_DIR}/ios-arm64/powersync-sqlite-core.framework/powersync-sqlite-core" | ||
install_name_tool -id "@rpath/powersync-sqlite-core.framework/powersync-sqlite-core" "${BUILD_DIR}/ios-arm64/powersync-sqlite-core.framework/powersync-sqlite-core" | ||
# Generate dSYM for iOS Device | ||
dsymutil "${BUILD_DIR}/ios-arm64/powersync-sqlite-core.framework/powersync-sqlite-core" -o "${BUILD_DIR}/ios-arm64/powersync-sqlite-core.framework.dSYM" | ||
|
||
echo "===================== create ios simulator framework =====================" | ||
mkdir -p "${BUILD_DIR}/ios-arm64_x86_64-simulator/powersync-sqlite-core.framework" | ||
echo "${plist}" > "${BUILD_DIR}/ios-arm64_x86_64-simulator/powersync-sqlite-core.framework/Info.plist" | ||
echo "${ios_plist}" >"${BUILD_DIR}/ios-arm64_x86_64-simulator/powersync-sqlite-core.framework/Info.plist" | ||
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" | ||
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" | ||
# Generate dSYM for iOS Simulator | ||
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" | ||
|
||
echo "===================== create macos framework =====================" | ||
mkdir -p "${BUILD_DIR}/macos-arm64_x86_64/powersync-sqlite-core.framework/Versions/A/Resources" | ||
echo "${plist}" > "${BUILD_DIR}/macos-arm64_x86_64/powersync-sqlite-core.framework/Versions/A/Resources/Info.plist" | ||
echo "${ios_plist}" >"${BUILD_DIR}/macos-arm64_x86_64/powersync-sqlite-core.framework/Versions/A/Resources/Info.plist" | ||
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" | ||
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" | ||
ln -sf A "${BUILD_DIR}/macos-arm64_x86_64/powersync-sqlite-core.framework/Versions/Current" | ||
|
@@ -62,20 +111,37 @@ EOF | |
# Generate dSYM for macOS | ||
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" | ||
|
||
echo "===================== create watchos device framework =====================" | ||
mkdir -p "${BUILD_DIR}/watchos-arm64/powersync-sqlite-core.framework/Versions/A/Resources" | ||
echo "${watchos_plist}" >"${BUILD_DIR}/watchos-arm64/powersync-sqlite-core.framework/Versions/A/Resources/Info.plist" | ||
cp -f "./target/aarch64-apple-watchos/release_apple/libpowersync.a" "${BUILD_DIR}/watchos-arm64/powersync-sqlite-core.framework/Versions/A/powersync-sqlite-core" | ||
ln -sf A "${BUILD_DIR}/watchos-arm64/powersync-sqlite-core.framework/Versions/Current" | ||
ln -sf Versions/Current/powersync-sqlite-core "${BUILD_DIR}/watchos-arm64/powersync-sqlite-core.framework/powersync-sqlite-core" | ||
ln -sf Versions/Current/Resources "${BUILD_DIR}/watchos-arm64/powersync-sqlite-core.framework/Resources" | ||
|
||
echo "===================== create watchos simulator framework =====================" | ||
mkdir -p "${BUILD_DIR}/watchos-arm64-simulator/powersync-sqlite-core.framework/Versions/A/Resources" | ||
echo "${watchos_plist}" >"${BUILD_DIR}/watchos-arm64-simulator/powersync-sqlite-core.framework/Versions/A/Resources/Info.plist" | ||
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-simulator/powersync-sqlite-core.framework/Versions/A/powersync-sqlite-core" | ||
ln -sf A "${BUILD_DIR}/watchos-arm64-simulator/powersync-sqlite-core.framework/Versions/Current" | ||
ln -sf Versions/Current/powersync-sqlite-core "${BUILD_DIR}/watchos-arm64-simulator/powersync-sqlite-core.framework/powersync-sqlite-core" | ||
ln -sf Versions/Current/Resources "${BUILD_DIR}/watchos-arm64-simulator/powersync-sqlite-core.framework/Resources" | ||
|
||
echo "===================== create xcframework =====================" | ||
rm -rf "${BUILD_DIR}/powersync-sqlite-core.xcframework" | ||
# "-debug-symbols" requires the absolute path | ||
|
||
xcodebuild -create-xcframework \ | ||
-framework "${BUILD_DIR}/ios-arm64/powersync-sqlite-core.framework" \ | ||
-debug-symbols "$(pwd -P)/${BUILD_DIR}/ios-arm64/powersync-sqlite-core.framework.dSYM" \ | ||
-framework "${BUILD_DIR}/ios-arm64_x86_64-simulator/powersync-sqlite-core.framework" \ | ||
-debug-symbols "$(pwd -P)/${BUILD_DIR}/ios-arm64_x86_64-simulator/powersync-sqlite-core.framework.dSYM" \ | ||
-framework "${BUILD_DIR}/macos-arm64_x86_64/powersync-sqlite-core.framework" \ | ||
-debug-symbols "$(pwd -P)/${BUILD_DIR}/macos-arm64_x86_64/powersync-sqlite-core.framework.dSYM" \ | ||
-output "${BUILD_DIR}/powersync-sqlite-core.xcframework" \ | ||
-output "${BUILD_DIR}/powersync-sqlite-core.xcframework" | ||
|
||
# how to create a watchOS XCFramework with static libraries, possible? | ||
|
||
cp -Rf "${BUILD_DIR}/powersync-sqlite-core.xcframework" "powersync-sqlite-core.xcframework" | ||
zip -r --symlinks powersync-sqlite-core.xcframework.zip powersync-sqlite-core.xcframework LICENSE README.md | ||
zip -r --symlinks powersync-sqlite-core.xcframework.zip powersync-sqlite-core.xcframework "${BUILD_DIR}/watchos-arm64/powersync-sqlite-core.framework/libpowersync.a" "${BUILD_DIR}/watchos-arm64-simulator/powersync-sqlite-core.framework/libpowersync.a" LICENSE README.md | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm also not a watchOS expert, but is there a reason for requiring static libraries here? Why would the regular framework not work? |
||
rm -rf ${BUILD_DIR} | ||
} | ||
|
||
|
@@ -92,5 +158,9 @@ cargo build -p powersync_loadable --profile release_apple --target x86_64-apple- | |
# macOS | ||
cargo build -p powersync_loadable --profile release_apple --target aarch64-apple-darwin -Zbuild-std | ||
cargo build -p powersync_loadable --profile release_apple --target x86_64-apple-darwin -Zbuild-std | ||
# watchOS | ||
cargo build -p powersync_loadable --profile release_apple -Zbuild-std=std,panic_abort --target aarch64-apple-watchos | ||
cargo build -p powersync_loadable --profile release_apple -Zbuild-std=std,panic_abort --target aarch64-apple-watchos-sim | ||
cargo build -p powersync_loadable --profile release_apple -Zbuild-std=std,panic_abort --target x86_64-apple-watchos-sim | ||
|
||
createXcframework |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we building
crates/shell
andcrates/sqlite
for watchOS somewhere? These are mostly used for testing and development, IIRC we don't ship them for iOS either. So I wonder if the changes are necessary.