diff --git a/.cargo/config.toml b/.cargo/config.toml index caa816c..4065216 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,4 +1,3 @@ - # Previously we added this to rustflags for all linux builds: # "-C", "link-arg=-lgcc_eh" # It was to fix this error when loading the loadable extension: @@ -86,3 +85,18 @@ rustflags = [ rustflags = [ "-C", "link-arg=-Wl,-soname,libpowersync.so", ] + +[target.aarch64-apple-watchos] +rustflags = [ + "-C", "link-arg=-mwatchos-version-min=7.0", +] + +[target.aarch64-apple-watchos-sim] +rustflags = [ + "-C", "link-arg=-mwatchsimulator-version-min=7.0", +] + +[target.x86_64-apple-watchos-sim] +rustflags = [ + "-C", "link-arg=-mwatchos-version-min=7.0", +] diff --git a/.github/workflows/ios.yml b/.github/workflows/ios.yml index aebd68e..b7dfad5 100644 --- a/.github/workflows/ios.yml +++ b/.github/workflows/ios.yml @@ -21,8 +21,10 @@ jobs: aarch64-apple-darwin \ aarch64-apple-ios \ aarch64-apple-ios-sim \ - x86_64-apple-ios - + x86_64-apple-ios \ + aarch64-apple-watchos \ + aarch64-apple-watchos-sim \ + x86_64-apple-watchos-sim - name: setup-cocoapods uses: maxim-lobanov/setup-cocoapods@v1 with: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 36028f3..ff28632 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -91,8 +91,10 @@ jobs: aarch64-apple-darwin \ aarch64-apple-ios \ aarch64-apple-ios-sim \ - x86_64-apple-ios - + x86_64-apple-ios \ + aarch64-apple-watchos \ + aarch64-apple-watchos-sim \ + x86_64-apple-watchos-sim - name: setup-cocoapods uses: maxim-lobanov/setup-cocoapods@v1 with: diff --git a/Cargo.toml b/Cargo.toml index 3506783..2cb7266 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,3 +39,4 @@ repository = "https://github.com/powersync-ja/powersync-sqlite-core" [workspace.dependencies] sqlite_nostd = { path="./sqlite-rs-embedded/sqlite_nostd" } + diff --git a/crates/shell/build.rs b/crates/shell/build.rs index f753d36..e696125 100644 --- a/crates/shell/build.rs +++ b/crates/shell/build.rs @@ -1,10 +1,10 @@ - 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/sqlite/sqlite3.c"); - cfg.file("../sqlite/sqlite/shell.c"); cfg.include("../sqlite/sqlite"); // General SQLite options @@ -14,8 +14,17 @@ fn main() { // Call core_init() in main.rs cfg.define("SQLITE_EXTRA_INIT", Some("core_init")); - // 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/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"); @@ -23,6 +32,4 @@ fn main() { cfg.flag("-Wno-null-pointer-subtraction"); cfg.compile("sqlite-ps"); - - println!("cargo:rustc-link-lib=readline"); } diff --git a/crates/shell/src/main.rs b/crates/shell/src/main.rs index 6a6d8af..b55f707 100644 --- a/crates/shell/src/main.rs +++ b/crates/shell/src/main.rs @@ -28,7 +28,6 @@ fn panic(_info: &core::panic::PanicInfo) -> ! { #[lang = "eh_personality"] extern "C" fn eh_personality() {} - #[no_mangle] pub extern "C" fn core_init(_dummy: *mut c_char) -> c_int { powersync_init_static() diff --git a/crates/sqlite/build.rs b/crates/sqlite/build.rs index 20b2953..713d6c9 100644 --- a/crates/sqlite/build.rs +++ b/crates/sqlite/build.rs @@ -1,17 +1,27 @@ 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"); @@ -19,6 +29,4 @@ fn main() { cfg.flag("-Wno-null-pointer-subtraction"); cfg.compile("sqlite"); - - println!("cargo:rustc-link-lib=readline"); } diff --git a/powersync-sqlite-core.podspec b/powersync-sqlite-core.podspec index 44f4f95..d8c522e 100644 --- a/powersync-sqlite-core.podspec +++ b/powersync-sqlite-core.podspec @@ -13,7 +13,7 @@ PowerSync extension for SQLite. s.source = { :http => "https://github.com/powersync-ja/powersync-sqlite-core/releases/download/v#{s.version}/powersync-sqlite-core.xcframework.zip" } s.vendored_frameworks = 'powersync-sqlite-core.xcframework' - s.ios.deployment_target = '11.0' s.osx.deployment_target = '10.13' + s.watchos.deployment_target = '7.0' end diff --git a/tool/build_xcframework.sh b/tool/build_xcframework.sh index 2a6334d..e23d30f 100755 --- a/tool/build_xcframework.sh +++ b/tool/build_xcframework.sh @@ -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=$( + cat < @@ -34,10 +33,60 @@ function createXcframework() { EOF -) + ) + + watchos_plist=$( + cat < + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + powersync-sqlite-core + CFBundleIdentifier + co.powersync.sqlitecore + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + FMWK + CFBundleSignature + ???? + MinimumOSVersion + 7.0 + CFBundleVersion + 0.3.12 + CFBundleShortVersionString + 0.3.12 + UIDeviceFamily + + 4 + + DTSDKName + watchos + DTPlatformName + watchos + DTPlatformVersion + 7.0 + DTXcode + 1500 + DTXcodeBuild + 15A240d + DTCompiler + com.apple.compilers.llvm.clang.1_0 + DTPlatformBuild + 21R355 + BuildMachineOSBuild + 23D60 + + +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 @@ -45,7 +94,7 @@ EOF 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 @@ -53,7 +102,7 @@ EOF 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,9 +111,25 @@ 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" \ @@ -72,10 +137,11 @@ EOF -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 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