From e3eb0f5032c085bbb431d680d94a7518a26244fd Mon Sep 17 00:00:00 2001 From: Teo Stocco Date: Sat, 10 May 2025 20:55:15 -0600 Subject: [PATCH 01/11] feat: add watchos support --- .cargo/config.toml | 16 ++++- .github/workflows/ios.yml | 6 +- .github/workflows/release.yml | 6 +- Cargo.toml | 1 + crates/shell/Cargo.toml | 17 +++++- crates/shell/build.rs | 19 ++++-- crates/shell/src/main.rs | 1 - crates/sqlite/Cargo.toml | 12 ++++ crates/sqlite/build.rs | 18 ++++-- powersync-sqlite-core.podspec | 6 +- tool/build_xcframework.sh | 111 +++++++++++++++++++++++++++++++--- 11 files changed, 182 insertions(+), 31 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index caa816c..ddb98b3 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] +rustflags = [ + "-C", "link-arg=-mwatchos-version-min=7.0", +] diff --git a/.github/workflows/ios.yml b/.github/workflows/ios.yml index 4c6057e..f3bd511 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 - name: setup-cocoapods uses: maxim-lobanov/setup-cocoapods@v1 with: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a9ea494..2291605 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 - name: setup-cocoapods uses: maxim-lobanov/setup-cocoapods@v1 with: diff --git a/Cargo.toml b/Cargo.toml index a802bd4..e0baca7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,3 +38,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/Cargo.toml b/crates/shell/Cargo.toml index eb8200f..28527f8 100644 --- a/crates/shell/Cargo.toml +++ b/crates/shell/Cargo.toml @@ -8,12 +8,23 @@ license.workspace = true authors.workspace = true keywords.workspace = true +[lib] +name = "powersync_sqlite" +path = "src/main.rs" +crate-type = ["staticlib"] + +[[bin]] +name = "powersync_sqlite" +path = "src/main.rs" +required-features = ["shell"] + [dependencies] -powersync_core = { path="../core" } -sqlite_nostd = { workspace=true } +powersync_core = { path="../core", default-features = false, features = ["static", "omit_load_extension"] } +sqlite_nostd = { workspace=true, features = ["static", "omit_load_extension"] } [features] -default = ["powersync_core/static", "powersync_core/omit_load_extension", "sqlite_nostd/static", "sqlite_nostd/omit_load_extension"] +default = [] +shell = [] [build-dependencies] cc = "1.0.46" 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/Cargo.toml b/crates/sqlite/Cargo.toml index 5e6b0d0..09e28ba 100644 --- a/crates/sqlite/Cargo.toml +++ b/crates/sqlite/Cargo.toml @@ -8,9 +8,21 @@ license.workspace = true authors.workspace = true keywords.workspace = true +[lib] +name = "sqlite3" +path = "src/main.rs" +crate-type = ["staticlib"] + +[[bin]] +name = "sqlite3" +path = "src/main.rs" +required-features = ["shell"] + [dependencies] [features] +default = [] +shell = [] [build-dependencies] cc = "1.0.46" 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 27040b5..b3dfe16 100644 --- a/powersync-sqlite-core.podspec +++ b/powersync-sqlite-core.podspec @@ -13,7 +13,11 @@ 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' + + # Ensure no asset catalogs are included for watchOS + s.watchos.resource_bundles = {} + s.watchos.resources = [] end diff --git a/tool/build_xcframework.sh b/tool/build_xcframework.sh index 37619a7..118989b 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,31 @@ 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.dylib" "${BUILD_DIR}/watchos-arm64/powersync-sqlite-core.framework/Versions/A/powersync-sqlite-core" + install_name_tool -id "@rpath/powersync-sqlite-core.framework/powersync-sqlite-core" "${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" + # Generate dSYM for watchOS device + dsymutil "${BUILD_DIR}/watchos-arm64/powersync-sqlite-core.framework/Versions/A/powersync-sqlite-core" -o "${BUILD_DIR}/watchos-arm64/powersync-sqlite-core.framework.dSYM" + + 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" + cp -f "./target/aarch64-apple-watchos-sim/release_apple/libpowersync.dylib" "${BUILD_DIR}/watchos-arm64-simulator/powersync-sqlite-core.framework/Versions/A/powersync-sqlite-core" + install_name_tool -id "@rpath/powersync-sqlite-core.framework/powersync-sqlite-core" "${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" + # Generate dSYM for watchOS simulator + dsymutil "${BUILD_DIR}/watchos-arm64-simulator/powersync-sqlite-core.framework/Versions/A/powersync-sqlite-core" -o "${BUILD_DIR}/watchos-arm64-simulator/powersync-sqlite-core.framework.dSYM" + echo "===================== create xcframework =====================" rm -rf "${BUILD_DIR}/powersync-sqlite-core.xcframework" - # "-debug-symbols" requires the absolute path + # Create iOS/macOS XCFramework 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 +143,19 @@ 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" + # Create watchOS XCFramework + xcodebuild -create-xcframework \ + -framework "${BUILD_DIR}/watchos-arm64/powersync-sqlite-core.framework" \ + -framework "${BUILD_DIR}/watchos-arm64-simulator/powersync-sqlite-core.framework" \ + -output "${BUILD_DIR}/powersync-sqlite-core-watchos.xcframework" + + # Copy the iOS/macOS XCFramework to the final location 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 + + # Create a zip file with both XCFrameworks + zip -r --symlinks powersync-sqlite-core.xcframework.zip powersync-sqlite-core.xcframework powersync-sqlite-core-watchos.xcframework LICENSE README.md rm -rf ${BUILD_DIR} } @@ -92,5 +172,16 @@ 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 +export SDKROOT=$(xcrun --sdk watchos --show-sdk-path) +export CARGO_TARGET_AARCH64_APPLE_WATCHOS_LINKER=$(xcrun --sdk watchos --find clang) +export CARGO_TARGET_AARCH64_APPLE_WATCHOS_AR=$(xcrun --sdk watchos --find ar) +export CARGO_TARGET_AARCH64_APPLE_WATCHOS_RANLIB=$(xcrun --sdk watchos --find ranlib) +cargo build -p powersync_loadable --profile release_apple -Zbuild-std=std,panic_abort --target aarch64-apple-watchos +export SDKROOT=$(xcrun --sdk watchsimulator --show-sdk-path) +export CARGO_TARGET_AARCH64_APPLE_WATCHOS_SIM_LINKER=$(xcrun --sdk watchsimulator --find clang) +export CARGO_TARGET_AARCH64_APPLE_WATCHOS_SIM_AR=$(xcrun --sdk watchsimulator --find ar) +export CARGO_TARGET_AARCH64_APPLE_WATCHOS_SIM_RANLIB=$(xcrun --sdk watchsimulator --find ranlib) +cargo build -p powersync_loadable --profile release_apple -Zbuild-std=std,panic_abort --target aarch64-apple-watchos-sim createXcframework From 3b889884688793578b4d10a5c8dd0e0b89974af7 Mon Sep 17 00:00:00 2001 From: Teo Stocco Date: Sat, 10 May 2025 21:49:25 -0600 Subject: [PATCH 02/11] cleanup --- .cargo/config.toml | 2 +- .github/workflows/ios.yml | 2 +- .github/workflows/release.yml | 2 +- crates/shell/Cargo.toml | 17 +++-------------- crates/sqlite/Cargo.toml | 12 ------------ powersync-sqlite-core.podspec | 4 ---- tool/build_xcframework.sh | 33 ++++++--------------------------- 7 files changed, 12 insertions(+), 60 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index ddb98b3..4065216 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -96,7 +96,7 @@ rustflags = [ "-C", "link-arg=-mwatchsimulator-version-min=7.0", ] -[target.x86_64-apple-watchos] +[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 f3bd511..aef69d8 100644 --- a/.github/workflows/ios.yml +++ b/.github/workflows/ios.yml @@ -24,7 +24,7 @@ jobs: x86_64-apple-ios \ aarch64-apple-watchos \ aarch64-apple-watchos-sim \ - x86_64-apple-watchos + 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 2291605..348d18f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -94,7 +94,7 @@ jobs: x86_64-apple-ios \ aarch64-apple-watchos \ aarch64-apple-watchos-sim \ - x86_64-apple-watchos + x86_64-apple-watchos-sim - name: setup-cocoapods uses: maxim-lobanov/setup-cocoapods@v1 with: diff --git a/crates/shell/Cargo.toml b/crates/shell/Cargo.toml index 28527f8..eb8200f 100644 --- a/crates/shell/Cargo.toml +++ b/crates/shell/Cargo.toml @@ -8,23 +8,12 @@ license.workspace = true authors.workspace = true keywords.workspace = true -[lib] -name = "powersync_sqlite" -path = "src/main.rs" -crate-type = ["staticlib"] - -[[bin]] -name = "powersync_sqlite" -path = "src/main.rs" -required-features = ["shell"] - [dependencies] -powersync_core = { path="../core", default-features = false, features = ["static", "omit_load_extension"] } -sqlite_nostd = { workspace=true, features = ["static", "omit_load_extension"] } +powersync_core = { path="../core" } +sqlite_nostd = { workspace=true } [features] -default = [] -shell = [] +default = ["powersync_core/static", "powersync_core/omit_load_extension", "sqlite_nostd/static", "sqlite_nostd/omit_load_extension"] [build-dependencies] cc = "1.0.46" diff --git a/crates/sqlite/Cargo.toml b/crates/sqlite/Cargo.toml index 09e28ba..5e6b0d0 100644 --- a/crates/sqlite/Cargo.toml +++ b/crates/sqlite/Cargo.toml @@ -8,21 +8,9 @@ license.workspace = true authors.workspace = true keywords.workspace = true -[lib] -name = "sqlite3" -path = "src/main.rs" -crate-type = ["staticlib"] - -[[bin]] -name = "sqlite3" -path = "src/main.rs" -required-features = ["shell"] - [dependencies] [features] -default = [] -shell = [] [build-dependencies] cc = "1.0.46" diff --git a/powersync-sqlite-core.podspec b/powersync-sqlite-core.podspec index b3dfe16..1b8129b 100644 --- a/powersync-sqlite-core.podspec +++ b/powersync-sqlite-core.podspec @@ -16,8 +16,4 @@ PowerSync extension for SQLite. s.ios.deployment_target = '11.0' s.osx.deployment_target = '10.13' s.watchos.deployment_target = '7.0' - - # Ensure no asset catalogs are included for watchOS - s.watchos.resource_bundles = {} - s.watchos.resources = [] end diff --git a/tool/build_xcframework.sh b/tool/build_xcframework.sh index 118989b..26d1442 100755 --- a/tool/build_xcframework.sh +++ b/tool/build_xcframework.sh @@ -114,28 +114,22 @@ EOF 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.dylib" "${BUILD_DIR}/watchos-arm64/powersync-sqlite-core.framework/Versions/A/powersync-sqlite-core" - install_name_tool -id "@rpath/powersync-sqlite-core.framework/powersync-sqlite-core" "${BUILD_DIR}/watchos-arm64/powersync-sqlite-core.framework/Versions/A/powersync-sqlite-core" + 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" - # Generate dSYM for watchOS device - dsymutil "${BUILD_DIR}/watchos-arm64/powersync-sqlite-core.framework/Versions/A/powersync-sqlite-core" -o "${BUILD_DIR}/watchos-arm64/powersync-sqlite-core.framework.dSYM" 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" - cp -f "./target/aarch64-apple-watchos-sim/release_apple/libpowersync.dylib" "${BUILD_DIR}/watchos-arm64-simulator/powersync-sqlite-core.framework/Versions/A/powersync-sqlite-core" - install_name_tool -id "@rpath/powersync-sqlite-core.framework/powersync-sqlite-core" "${BUILD_DIR}/watchos-arm64-simulator/powersync-sqlite-core.framework/Versions/A/powersync-sqlite-core" + 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" - # Generate dSYM for watchOS simulator - dsymutil "${BUILD_DIR}/watchos-arm64-simulator/powersync-sqlite-core.framework/Versions/A/powersync-sqlite-core" -o "${BUILD_DIR}/watchos-arm64-simulator/powersync-sqlite-core.framework.dSYM" echo "===================== create xcframework =====================" rm -rf "${BUILD_DIR}/powersync-sqlite-core.xcframework" - # Create iOS/macOS XCFramework + 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" \ @@ -145,17 +139,9 @@ EOF -debug-symbols "$(pwd -P)/${BUILD_DIR}/macos-arm64_x86_64/powersync-sqlite-core.framework.dSYM" \ -output "${BUILD_DIR}/powersync-sqlite-core.xcframework" - # Create watchOS XCFramework - xcodebuild -create-xcframework \ - -framework "${BUILD_DIR}/watchos-arm64/powersync-sqlite-core.framework" \ - -framework "${BUILD_DIR}/watchos-arm64-simulator/powersync-sqlite-core.framework" \ - -output "${BUILD_DIR}/powersync-sqlite-core-watchos.xcframework" - - # Copy the iOS/macOS XCFramework to the final location - cp -Rf "${BUILD_DIR}/powersync-sqlite-core.xcframework" "powersync-sqlite-core.xcframework" + # how to create a watchOS XCFramework with static libraries, possible? - # Create a zip file with both XCFrameworks - zip -r --symlinks powersync-sqlite-core.xcframework.zip powersync-sqlite-core.xcframework powersync-sqlite-core-watchos.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} } @@ -173,15 +159,8 @@ cargo build -p powersync_loadable --profile release_apple --target x86_64-apple- 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 -export SDKROOT=$(xcrun --sdk watchos --show-sdk-path) -export CARGO_TARGET_AARCH64_APPLE_WATCHOS_LINKER=$(xcrun --sdk watchos --find clang) -export CARGO_TARGET_AARCH64_APPLE_WATCHOS_AR=$(xcrun --sdk watchos --find ar) -export CARGO_TARGET_AARCH64_APPLE_WATCHOS_RANLIB=$(xcrun --sdk watchos --find ranlib) cargo build -p powersync_loadable --profile release_apple -Zbuild-std=std,panic_abort --target aarch64-apple-watchos -export SDKROOT=$(xcrun --sdk watchsimulator --show-sdk-path) -export CARGO_TARGET_AARCH64_APPLE_WATCHOS_SIM_LINKER=$(xcrun --sdk watchsimulator --find clang) -export CARGO_TARGET_AARCH64_APPLE_WATCHOS_SIM_AR=$(xcrun --sdk watchsimulator --find ar) -export CARGO_TARGET_AARCH64_APPLE_WATCHOS_SIM_RANLIB=$(xcrun --sdk watchsimulator --find ranlib) 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 From 3113adeeade8ee12427a51ec8fbd2ff426a53796 Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Fri, 13 Jun 2025 10:53:13 +0200 Subject: [PATCH 03/11] Refactor creating xcframework --- tool/build_xcframework.sh | 152 ++++++++++++++++++-------------------- 1 file changed, 70 insertions(+), 82 deletions(-) diff --git a/tool/build_xcframework.sh b/tool/build_xcframework.sh index 26d1442..19fdafa 100755 --- a/tool/build_xcframework.sh +++ b/tool/build_xcframework.sh @@ -4,39 +4,47 @@ set -e # Adapted from https://github.com/vlcn-io/cr-sqlite/blob/main/core/all-ios-loadable.sh BUILD_DIR=./build - -function createXcframework() { - ios_plist=$( - cat < - - - - CFBundleDevelopmentRegion - en - CFBundleExecutable - powersync-sqlite-core - CFBundleIdentifier - co.powersync.sqlitecore - CFBundleInfoDictionaryVersion - 6.0 - CFBundlePackageType - FMWK - CFBundleSignature - ???? - MinimumOSVersion - 11.0 - CFBundleVersion - 0.4.0 - CFBundleShortVersionString - 0.4.0 - - +TARGETS=( + # iOS and simulator + aarch64-apple-ios + aarch64-apple-ios-sim + x86_64-apple-ios + + # macOS + aarch64-apple-darwin + x86_64-apple-darwin + + # watchOS and simulator + aarch64-apple-watchos + aarch64-apple-watchos-sim + x86_64-apple-watchos-sim + arm64_32-apple-watchos +) +VERSION=0.4.0 + +function generatePlist() { + min_os_version=0 + additional_keys="" + # We support versions 11.0 or later for iOS and macOS. For watchOS, we need 9.0 or later. + case $1 in + *"watchos"*) + additional_keys=$(cat <CFBundleSupportedPlatforms + + WatchOS + + UIDeviceFamily + + 4 + EOF - ) + ) + min_os_version="9.0";; + *) + min_os_version="11.0";; + esac - watchos_plist=$( - cat < @@ -54,35 +62,21 @@ EOF CFBundleSignature ???? MinimumOSVersion - 7.0 + $min_os_version CFBundleVersion - 0.3.12 + $VERSION 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 + $VERSION +$additional_keys EOF - ) +} + +function createXcframework() { + ios_plist=$(generatePlist "ios") + macos_plist=$(generatePlist "macos") + watchos_plist=$(generatePlist "watchos") echo "===================== create ios device framework =====================" mkdir -p "${BUILD_DIR}/ios-arm64/powersync-sqlite-core.framework" @@ -112,20 +106,22 @@ EOF 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" + mkdir -p "${BUILD_DIR}/watchos-arm64_arm64_32_armv7k/powersync-sqlite-core.framework/Versions/A/Resources" + echo "${watchos_plist}" >"${BUILD_DIR}/watchos-arm64_arm64_32_armv7k/powersync-sqlite-core.framework/Versions/A/Resources/Info.plist" + 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" + # install_name_tool isn't necessary, we use a statically-linked library + ln -sf A "${BUILD_DIR}/watchos-arm64_arm64_32_armv7k/powersync-sqlite-core.framework/Versions/Current" + ln -sf Versions/Current/powersync-sqlite-core "${BUILD_DIR}/watchos-arm64_arm64_32_armv7k/powersync-sqlite-core.framework/powersync-sqlite-core" + ln -sf Versions/Current/Resources "${BUILD_DIR}/watchos-arm64_arm64_32_armv7k/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" + mkdir -p "${BUILD_DIR}/watchos-arm64_x86_64-simulator/powersync-sqlite-core.framework/Versions/A/Resources" + echo "${watchos_plist}" >"${BUILD_DIR}/watchos-arm64_x86_64-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_x86_64-simulator/powersync-sqlite-core.framework/Versions/A/powersync-sqlite-core" + # install_name_tool isn't necessary, we use a statically-linked library + ln -sf A "${BUILD_DIR}/watchos-arm64_x86_64-simulator/powersync-sqlite-core.framework/Versions/Current" + ln -sf Versions/Current/powersync-sqlite-core "${BUILD_DIR}/watchos-arm64_x86_64-simulator/powersync-sqlite-core.framework/powersync-sqlite-core" + ln -sf Versions/Current/Resources "${BUILD_DIR}/watchos-arm64_x86_64-simulator/powersync-sqlite-core.framework/Resources" echo "===================== create xcframework =====================" rm -rf "${BUILD_DIR}/powersync-sqlite-core.xcframework" @@ -137,11 +133,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" \ + -framework "${BUILD_DIR}/watchos-arm64_arm64_32_armv7k/powersync-sqlite-core.framework" \ + -framework "${BUILD_DIR}/watchos-arm64_x86_64-simulator/powersync-sqlite-core.framework" \ -output "${BUILD_DIR}/powersync-sqlite-core.xcframework" - # how to create a watchOS XCFramework with static libraries, possible? - - 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 + zip -r --symlinks powersync-sqlite-core.xcframework.zip powersync-sqlite-core.xcframework LICENSE README.md rm -rf ${BUILD_DIR} } @@ -150,17 +146,9 @@ EOF rm -rf powersync-sqlite-core.xcframework -# iOS -cargo build -p powersync_loadable --profile release_apple --target aarch64-apple-ios -Zbuild-std -# Simulator -cargo build -p powersync_loadable --profile release_apple --target aarch64-apple-ios-sim -Zbuild-std -cargo build -p powersync_loadable --profile release_apple --target x86_64-apple-ios -Zbuild-std -# 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 +for TARGET in ${TARGETS[@]}; do + echo "Building PowerSync loadable extension for $TARGET" + #cargo build -p powersync_loadable --profile release_apple --target $TARGET -Zbuild-std +done createXcframework From 78a56cc5884df661e8b0fb009ea666dab456f9eb Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Fri, 13 Jun 2025 10:55:43 +0200 Subject: [PATCH 04/11] Remove unecessary changes --- .cargo/config.toml | 6 +++--- crates/shell/build.rs | 19 ++++++------------- crates/shell/src/main.rs | 1 + crates/sqlite/build.rs | 18 +++++------------- tool/build_xcframework.sh | 3 ++- 5 files changed, 17 insertions(+), 30 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 4065216..abb061f 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -88,15 +88,15 @@ rustflags = [ [target.aarch64-apple-watchos] rustflags = [ - "-C", "link-arg=-mwatchos-version-min=7.0", + "-C", "link-arg=-mwatchos-version-min=9.0", ] [target.aarch64-apple-watchos-sim] rustflags = [ - "-C", "link-arg=-mwatchsimulator-version-min=7.0", + "-C", "link-arg=-mwatchsimulator-version-min=9.0", ] [target.x86_64-apple-watchos-sim] rustflags = [ - "-C", "link-arg=-mwatchos-version-min=7.0", + "-C", "link-arg=-mwatchos-version-min=9.0", ] diff --git a/crates/shell/build.rs b/crates/shell/build.rs index e696125..f753d36 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,17 +14,8 @@ fn main() { // Call core_init() in main.rs cfg.define("SQLITE_EXTRA_INIT", Some("core_init")); - 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"); - } + // Compile with readline support (also requires -lreadline / cargo:rustc-link-lib=readline below) + cfg.define("HAVE_READLINE", Some("1")); // Silence warnings generated for SQLite cfg.flag("-Wno-implicit-fallthrough"); @@ -32,4 +23,6 @@ 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 b55f707..6a6d8af 100644 --- a/crates/shell/src/main.rs +++ b/crates/shell/src/main.rs @@ -28,6 +28,7 @@ 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 713d6c9..20b2953 100644 --- a/crates/sqlite/build.rs +++ b/crates/sqlite/build.rs @@ -1,27 +1,17 @@ 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")); - 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"); - } + // Compile with readline support (also requires -lreadline / cargo:rustc-link-lib=readline below) + cfg.define("HAVE_READLINE", Some("1")); // Silence warnings generated for SQLite cfg.flag("-Wno-implicit-fallthrough"); @@ -29,4 +19,6 @@ fn main() { cfg.flag("-Wno-null-pointer-subtraction"); cfg.compile("sqlite"); + + println!("cargo:rustc-link-lib=readline"); } diff --git a/tool/build_xcframework.sh b/tool/build_xcframework.sh index 19fdafa..0710118 100755 --- a/tool/build_xcframework.sh +++ b/tool/build_xcframework.sh @@ -137,6 +137,7 @@ function createXcframework() { -framework "${BUILD_DIR}/watchos-arm64_x86_64-simulator/powersync-sqlite-core.framework" \ -output "${BUILD_DIR}/powersync-sqlite-core.xcframework" + 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 rm -rf ${BUILD_DIR} } @@ -148,7 +149,7 @@ rm -rf powersync-sqlite-core.xcframework for TARGET in ${TARGETS[@]}; do echo "Building PowerSync loadable extension for $TARGET" - #cargo build -p powersync_loadable --profile release_apple --target $TARGET -Zbuild-std + cargo build -p powersync_loadable --profile release_apple --target $TARGET -Zbuild-std done createXcframework From 3a35dea325769cf925042f22c34b3dd079638500 Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Fri, 13 Jun 2025 11:41:41 +0200 Subject: [PATCH 05/11] Add static build as separate target --- Cargo.lock | 8 ++++++++ crates/static/Cargo.toml | 24 ++++++++++++++++++++++++ crates/static/README.md | 1 + crates/static/src/lib.rs | 31 +++++++++++++++++++++++++++++++ tool/build_wasm.sh | 12 +++--------- tool/build_xcframework.sh | 11 ++++++++++- 6 files changed, 77 insertions(+), 10 deletions(-) create mode 100644 crates/static/Cargo.toml create mode 100644 crates/static/README.md create mode 100644 crates/static/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 303b7ec..4c08108 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -273,6 +273,14 @@ dependencies = [ "sqlite_nostd", ] +[[package]] +name = "powersync_static" +version = "0.4.0" +dependencies = [ + "powersync_core", + "sqlite_nostd", +] + [[package]] name = "prettyplease" version = "0.2.32" diff --git a/crates/static/Cargo.toml b/crates/static/Cargo.toml new file mode 100644 index 0000000..cc7e0f3 --- /dev/null +++ b/crates/static/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "powersync_static" +edition.workspace = true +version.workspace = true +homepage.workspace = true +repository.workspace = true +license.workspace = true +authors.workspace = true +keywords.workspace = true + +[lib] +name = "powersync" +crate-type = ["staticlib"] + +[dependencies] +sqlite_nostd = { workspace=true } + +[dependencies.powersync_core] +path = "../core" +default-features = false +features = [] + +[features] +default = ["powersync_core/static", "powersync_core/omit_load_extension", "sqlite_nostd/omit_load_extension"] diff --git a/crates/static/README.md b/crates/static/README.md new file mode 100644 index 0000000..07aefdd --- /dev/null +++ b/crates/static/README.md @@ -0,0 +1 @@ +Builds the core extension as a static library, exposing the `powersync_init_static` function to load it. diff --git a/crates/static/src/lib.rs b/crates/static/src/lib.rs new file mode 100644 index 0000000..9e5a9de --- /dev/null +++ b/crates/static/src/lib.rs @@ -0,0 +1,31 @@ +#![no_std] +#![feature(vec_into_raw_parts)] +#![feature(core_intrinsics)] +#![allow(internal_features)] +#![feature(lang_items)] + +extern crate alloc; + +// Defines sqlite3_powersync_init +#[allow(unused_imports)] +use powersync_core; + +// Use the SQLite allocator, allowing us to freely transfer memory between SQLite and Rust. +#[cfg(not(test))] +use sqlite_nostd::SQLite3Allocator; + +#[cfg(not(test))] +#[global_allocator] +static ALLOCATOR: SQLite3Allocator = SQLite3Allocator {}; + +// Custom Panic handler for WASM and other no_std builds +#[cfg(not(test))] +#[panic_handler] +fn panic(_info: &core::panic::PanicInfo) -> ! { + core::intrinsics::abort() +} + +#[cfg(not(target_family = "wasm"))] +#[cfg(not(test))] +#[lang = "eh_personality"] +extern "C" fn eh_personality() {} diff --git a/tool/build_wasm.sh b/tool/build_wasm.sh index f40d8ed..5c8c9ac 100755 --- a/tool/build_wasm.sh +++ b/tool/build_wasm.sh @@ -6,10 +6,8 @@ emcc --version # target/wasm32-unknown-emscripten/wasm/powersync.wasm RUSTFLAGS="-C link-arg=-sSIDE_MODULE=2" \ cargo build \ - -p powersync_loadable \ + -p powersync_static \ --profile wasm \ - --no-default-features \ - --features "powersync_core/static powersync_core/omit_load_extension sqlite_nostd/omit_load_extension" \ -Z build-std=panic_abort,core,alloc \ --target wasm32-unknown-emscripten @@ -19,10 +17,8 @@ cp "target/wasm32-unknown-emscripten/wasm/powersync.wasm" "libpowersync.wasm" # target/wasm32-unknown-emscripten/wasm_asyncify/powersync.wasm RUSTFLAGS="-C link-arg=-sSIDE_MODULE=2 -C link-arg=-sASYNCIFY=1 -C link-arg=-sJSPI_IMPORTS=@wasm/asyncify_imports.json" \ cargo build \ - -p powersync_loadable \ + -p powersync_static \ --profile wasm_asyncify \ - --no-default-features \ - --features "powersync_core/static powersync_core/omit_load_extension sqlite_nostd/omit_load_extension" \ -Z build-std=panic_abort,core,alloc \ --target wasm32-unknown-emscripten @@ -34,10 +30,8 @@ cp "target/wasm32-unknown-emscripten/wasm_asyncify/powersync.wasm" "libpowersync # Works for both emscripten and wasi. # target/wasm32-wasip1/wasm/libpowersync.a cargo build \ - -p powersync_loadable \ + -p powersync_static \ --profile wasm \ - --no-default-features \ - --features "powersync_core/static powersync_core/omit_load_extension sqlite_nostd/omit_load_extension" \ -Z build-std=panic_abort,core,alloc \ --target wasm32-wasip1 diff --git a/tool/build_xcframework.sh b/tool/build_xcframework.sh index 0710118..b04c1a0 100755 --- a/tool/build_xcframework.sh +++ b/tool/build_xcframework.sh @@ -149,7 +149,16 @@ rm -rf powersync-sqlite-core.xcframework for TARGET in ${TARGETS[@]}; do echo "Building PowerSync loadable extension for $TARGET" - cargo build -p powersync_loadable --profile release_apple --target $TARGET -Zbuild-std + + if [[ $TARGET == *"watchos"* ]]; then + cargo build \ + -p powersync_static \ + --profile release_apple \ + --target $TARGET \ + -Zbuild-std + else + cargo build -p powersync_loadable --profile release_apple --target $TARGET -Zbuild-std + fi done createXcframework From 01c06043b36456f72fa20b1680c0b7e0d85957a1 Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Fri, 13 Jun 2025 12:11:05 +0200 Subject: [PATCH 06/11] Add swift package for overrides --- .gitignore | 1 + Package.swift | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 Package.swift diff --git a/.gitignore b/.gitignore index 5fee65f..f7f55d4 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ target/ *.tar.gz *.tar.xz *.zip +.build diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..498c829 --- /dev/null +++ b/Package.swift @@ -0,0 +1,26 @@ +// swift-tools-version: 5.7 + +// NOTE! This is never released, we're only using this to support local builds builds for the +// Swift SDK. +import PackageDescription +let packageName = "PowerSyncSQLiteCore" + +let package = Package( + name: packageName, + platforms: [ + .iOS(.v13), + .macOS(.v10_15), + .watchOS(.v9) + ], + products: [ + .library( + name: packageName, + targets: [packageName]), + ], + targets: [ + .binaryTarget( + name: packageName, + path: "powersync-sqlite-core.xcframework" + ) + ] +) From eadfde27f043919b1b7aa9834306c98e4abdf533 Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Fri, 13 Jun 2025 12:25:02 +0200 Subject: [PATCH 07/11] Raise minimum version in podspec --- powersync-sqlite-core.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powersync-sqlite-core.podspec b/powersync-sqlite-core.podspec index 1b8129b..5075a6c 100644 --- a/powersync-sqlite-core.podspec +++ b/powersync-sqlite-core.podspec @@ -15,5 +15,5 @@ PowerSync extension for SQLite. s.ios.deployment_target = '11.0' s.osx.deployment_target = '10.13' - s.watchos.deployment_target = '7.0' + s.watchos.deployment_target = '9.0' end From e96b79752a1bfd736aaf2de13960458be4287887 Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Fri, 13 Jun 2025 12:26:01 +0200 Subject: [PATCH 08/11] Add missing space back --- tool/build_xcframework.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tool/build_xcframework.sh b/tool/build_xcframework.sh index b04c1a0..d377f9d 100755 --- a/tool/build_xcframework.sh +++ b/tool/build_xcframework.sh @@ -80,7 +80,7 @@ function createXcframework() { echo "===================== create ios device framework =====================" mkdir -p "${BUILD_DIR}/ios-arm64/powersync-sqlite-core.framework" - echo "${ios_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 @@ -88,7 +88,7 @@ function createXcframework() { echo "===================== create ios simulator framework =====================" mkdir -p "${BUILD_DIR}/ios-arm64_x86_64-simulator/powersync-sqlite-core.framework" - echo "${ios_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 @@ -96,7 +96,7 @@ function createXcframework() { echo "===================== create macos framework =====================" mkdir -p "${BUILD_DIR}/macos-arm64_x86_64/powersync-sqlite-core.framework/Versions/A/Resources" - echo "${ios_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" @@ -107,7 +107,7 @@ function createXcframework() { echo "===================== create watchos device framework =====================" mkdir -p "${BUILD_DIR}/watchos-arm64_arm64_32_armv7k/powersync-sqlite-core.framework/Versions/A/Resources" - echo "${watchos_plist}" >"${BUILD_DIR}/watchos-arm64_arm64_32_armv7k/powersync-sqlite-core.framework/Versions/A/Resources/Info.plist" + echo "${watchos_plist}" > "${BUILD_DIR}/watchos-arm64_arm64_32_armv7k/powersync-sqlite-core.framework/Versions/A/Resources/Info.plist" 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" # install_name_tool isn't necessary, we use a statically-linked library ln -sf A "${BUILD_DIR}/watchos-arm64_arm64_32_armv7k/powersync-sqlite-core.framework/Versions/Current" @@ -116,7 +116,7 @@ function createXcframework() { echo "===================== create watchos simulator framework =====================" mkdir -p "${BUILD_DIR}/watchos-arm64_x86_64-simulator/powersync-sqlite-core.framework/Versions/A/Resources" - echo "${watchos_plist}" >"${BUILD_DIR}/watchos-arm64_x86_64-simulator/powersync-sqlite-core.framework/Versions/A/Resources/Info.plist" + echo "${watchos_plist}" > "${BUILD_DIR}/watchos-arm64_x86_64-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_x86_64-simulator/powersync-sqlite-core.framework/Versions/A/powersync-sqlite-core" # install_name_tool isn't necessary, we use a statically-linked library ln -sf A "${BUILD_DIR}/watchos-arm64_x86_64-simulator/powersync-sqlite-core.framework/Versions/Current" From d9801461b60294a36ec921d419da9505c8b4d47a Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Fri, 13 Jun 2025 15:10:14 +0200 Subject: [PATCH 09/11] Revert wasm build changes --- tool/build_wasm.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tool/build_wasm.sh b/tool/build_wasm.sh index 5c8c9ac..f40d8ed 100755 --- a/tool/build_wasm.sh +++ b/tool/build_wasm.sh @@ -6,8 +6,10 @@ emcc --version # target/wasm32-unknown-emscripten/wasm/powersync.wasm RUSTFLAGS="-C link-arg=-sSIDE_MODULE=2" \ cargo build \ - -p powersync_static \ + -p powersync_loadable \ --profile wasm \ + --no-default-features \ + --features "powersync_core/static powersync_core/omit_load_extension sqlite_nostd/omit_load_extension" \ -Z build-std=panic_abort,core,alloc \ --target wasm32-unknown-emscripten @@ -17,8 +19,10 @@ cp "target/wasm32-unknown-emscripten/wasm/powersync.wasm" "libpowersync.wasm" # target/wasm32-unknown-emscripten/wasm_asyncify/powersync.wasm RUSTFLAGS="-C link-arg=-sSIDE_MODULE=2 -C link-arg=-sASYNCIFY=1 -C link-arg=-sJSPI_IMPORTS=@wasm/asyncify_imports.json" \ cargo build \ - -p powersync_static \ + -p powersync_loadable \ --profile wasm_asyncify \ + --no-default-features \ + --features "powersync_core/static powersync_core/omit_load_extension sqlite_nostd/omit_load_extension" \ -Z build-std=panic_abort,core,alloc \ --target wasm32-unknown-emscripten @@ -30,8 +34,10 @@ cp "target/wasm32-unknown-emscripten/wasm_asyncify/powersync.wasm" "libpowersync # Works for both emscripten and wasi. # target/wasm32-wasip1/wasm/libpowersync.a cargo build \ - -p powersync_static \ + -p powersync_loadable \ --profile wasm \ + --no-default-features \ + --features "powersync_core/static powersync_core/omit_load_extension sqlite_nostd/omit_load_extension" \ -Z build-std=panic_abort,core,alloc \ --target wasm32-wasip1 From 9d3a1d19f6567b10f8f4273155d5eeb74f748009 Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Fri, 13 Jun 2025 15:15:41 +0200 Subject: [PATCH 10/11] Don't add no-std targets --- .github/workflows/ios.yml | 5 +---- .github/workflows/release.yml | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ios.yml b/.github/workflows/ios.yml index aef69d8..da645ae 100644 --- a/.github/workflows/ios.yml +++ b/.github/workflows/ios.yml @@ -21,10 +21,7 @@ jobs: aarch64-apple-darwin \ aarch64-apple-ios \ aarch64-apple-ios-sim \ - x86_64-apple-ios \ - aarch64-apple-watchos \ - aarch64-apple-watchos-sim \ - x86_64-apple-watchos-sim + x86_64-apple-ios - name: setup-cocoapods uses: maxim-lobanov/setup-cocoapods@v1 with: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 348d18f..85afa90 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -91,10 +91,7 @@ jobs: aarch64-apple-darwin \ aarch64-apple-ios \ aarch64-apple-ios-sim \ - x86_64-apple-ios \ - aarch64-apple-watchos \ - aarch64-apple-watchos-sim \ - x86_64-apple-watchos-sim + x86_64-apple-ios - name: setup-cocoapods uses: maxim-lobanov/setup-cocoapods@v1 with: From 9e94504a41d6d5869e373663c7d1cedf12d4c06e Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Fri, 13 Jun 2025 15:20:58 +0200 Subject: [PATCH 11/11] Add back missing whitespace --- .github/workflows/ios.yml | 1 + .github/workflows/release.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/ios.yml b/.github/workflows/ios.yml index da645ae..4c6057e 100644 --- a/.github/workflows/ios.yml +++ b/.github/workflows/ios.yml @@ -22,6 +22,7 @@ jobs: aarch64-apple-ios \ aarch64-apple-ios-sim \ x86_64-apple-ios + - name: setup-cocoapods uses: maxim-lobanov/setup-cocoapods@v1 with: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 85afa90..a9ea494 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -92,6 +92,7 @@ jobs: aarch64-apple-ios \ aarch64-apple-ios-sim \ x86_64-apple-ios + - name: setup-cocoapods uses: maxim-lobanov/setup-cocoapods@v1 with: