diff --git a/.github/workflows/apple-devices.yml b/.github/workflows/apple-devices.yml index 9fdc37e6..f79f9a48 100644 --- a/.github/workflows/apple-devices.yml +++ b/.github/workflows/apple-devices.yml @@ -24,15 +24,6 @@ jobs: - rust-target: "aarch64-apple-watchos-sim" os: macos-14 apple-sim: "watchOS" - - rust-target: "x86_64-apple-watchos-sim" - os: macos-13 - apple-sim: "watchOS" - - rust-target: "x86_64-apple-tvos" - os: macos-13 - apple-sim: "tvOS" - - rust-target: "x86_64-apple-ios" - os: macos-13 - apple-sim: "iOS" steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@master @@ -54,37 +45,6 @@ jobs: cargo install --git https://github.com/sonos/dinghy.git --force --rev ${CARGO_DINGHY_REV} cargo-dinghy fi - - name: Cache deps - id: cache-deps - uses: actions/cache@v4 - env: - cache-name: cache-elixir-deps - with: - path: tests/support/test_server/deps - key: ${{ runner.os }}-${{ runner.arch }}-mix-${{ env.cache-name }}-2-${{ hashFiles('**/mix.lock') }} - restore-keys: | - ${{ runner.os }}-${{ runner.arch }}-mix-${{ env.cache-name }}- - - name: Cache compiled build - id: cache-build - uses: actions/cache@v4 - env: - cache-name: cache-compiled-build - with: - path: tests/support/test_server/_build - key: ${{ runner.os }}-${{ runner.arch }}-mix-${{ env.cache-name }}-2-${{ hashFiles('**/mix.lock') }} - restore-keys: | - ${{ runner.os }}-${{ runner.arch }}-mix-${{ env.cache-name }}- - ${{ runner.os }}-${{ runner.arch }}-mix- - - name: Set up Elixir - run: brew install elixir - - - name: Install test server dependencies, compile and run in background - working-directory: ./tests/support/test_server - run: | - mix deps.get - mix compile - mix phx.server & - - name: Start Simulator uses: futureware-tech/simulator-action@v3 with: @@ -104,3 +64,23 @@ jobs: cargo dinghy all-platforms cargo dinghy all-devices cargo -Zbuild-std test --target ${{ matrix.rust-target }} + + - name: Set up Elixir + run: brew install elixir + + - name: Install test server dependencies, compile and run in background + working-directory: ./tests/support/test_server + run: | + mix deps.get + mix compile + mix phx.server & + + - name: Run Rust tests on simulator for ${{ matrix.rust-target }} + env: + DINGHY_LOG: debug + timeout-minutes: 20 + run: | + cargo dinghy all-platforms + cargo dinghy all-devices + cargo -Zbuild-std test --target ${{ matrix.rust-target }} --features liveview-channels + cargo -Zbuild-std test --target ${{ matrix.rust-target }} --features liveview-channels-tls diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 8f49230d..89571faf 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -27,35 +27,36 @@ jobs: target key: ${{ github.workflow }}-${{ github.job }}-toolchain-${{ env.TOOLCHAIN }}-cargo-${{ hashFiles('**/Cargo.lock') }} - - name: Cache deps - id: cache-deps - uses: actions/cache@v4 - env: - cache-name: cache-elixir-deps - with: - path: tests/support/test_server/deps - key: ${{ runner.os }}-mix-${{ env.cache-name }}-2-${{ hashFiles('**/mix.lock') }} - restore-keys: | - ${{ runner.os }}-mix-${{ env.cache-name }}- - - name: Cache compiled build - id: cache-build - uses: actions/cache@v4 - env: - cache-name: cache-compiled-build - with: - path: tests/support/test_server/_build - key: ${{ runner.os }}-mix-${{ env.cache-name }}-2-${{ hashFiles('**/mix.lock') }} - restore-keys: | - ${{ runner.os }}-mix-${{ env.cache-name }}- - ${{ runner.os }}-mix- - - name: Set up Elixir, kotlin and ktlint - run: brew install elixir kotlin ktlint - - name: Install test server dependencies, compile and run in background - working-directory: ./tests/support/test_server - run: | - mix deps.get - mix compile - mix phx.server & +# TODO: Fix this when enabling live-channels feature flag. +# - name: Cache deps +# id: cache-deps +# uses: actions/cache@v4 +# env: +# cache-name: cache-elixir-deps +# with: +# path: tests/support/test_server/deps +# key: ${{ runner.os }}-mix-${{ env.cache-name }}-2-${{ hashFiles('**/mix.lock') }} +# restore-keys: | +# ${{ runner.os }}-mix-${{ env.cache-name }}- +# - name: Cache compiled build +# id: cache-build +# uses: actions/cache@v4 +# env: +# cache-name: cache-compiled-build +# with: +# path: tests/support/test_server/_build +# key: ${{ runner.os }}-mix-${{ env.cache-name }}-2-${{ hashFiles('**/mix.lock') }} +# restore-keys: | +# ${{ runner.os }}-mix-${{ env.cache-name }}- +# ${{ runner.os }}-mix- +# - name: Set up Elixir, kotlin and ktlint +# run: brew install elixir kotlin ktlint +# - name: Install test server dependencies, compile and run in background +# working-directory: ./tests/support/test_server +# run: | +# mix deps.get +# mix compile +# mix phx.server & - name: Get the JNA jar for testing kotlin. run: wget 'https://repo1.maven.org/maven2/net/java/dev/jna/jna/5.14.0/jna-5.14.0.jar' diff --git a/.github/workflows/uniffi-kotlin-tests.yml b/.github/workflows/uniffi-kotlin-tests.yml index 2a7564fa..248b5637 100644 --- a/.github/workflows/uniffi-kotlin-tests.yml +++ b/.github/workflows/uniffi-kotlin-tests.yml @@ -35,36 +35,37 @@ jobs: target key: ${{ github.workflow }}-${{ github.job }}-toolchain-${{ env.TOOLCHAIN }}-cargo-${{ hashFiles('**/Cargo.lock') }} - - name: Cache deps - id: cache-deps - uses: actions/cache@v4 - env: - cache-name: cache-elixir-deps - with: - path: tests/support/test_server/deps - key: ${{ runner.os }}-mix-${{ env.cache-name }}-2-${{ hashFiles('**/mix.lock') }} - restore-keys: | - ${{ runner.os }}-mix-${{ env.cache-name }}- - - name: Cache compiled build - id: cache-build - uses: actions/cache@v4 - env: - cache-name: cache-compiled-build - with: - path: tests/support/test_server/_build - key: ${{ runner.os }}-mix-${{ env.cache-name }}-2-${{ hashFiles('**/mix.lock') }} - restore-keys: | - ${{ runner.os }}-mix-${{ env.cache-name }}- - ${{ runner.os }}-mix- - - name: Set up Elixir - run: brew install elixir - - - name: Install test server dependencies, compile and run in background - working-directory: ./tests/support/test_server - run: | - mix deps.get - mix compile - mix phx.server & +# TODO: Fix this when enabling live-channels feature flag. +# - name: Cache deps +# id: cache-deps +# uses: actions/cache@v4 +# env: +# cache-name: cache-elixir-deps +# with: +# path: tests/support/test_server/deps +# key: ${{ runner.os }}-mix-${{ env.cache-name }}-2-${{ hashFiles('**/mix.lock') }} +# restore-keys: | +# ${{ runner.os }}-mix-${{ env.cache-name }}- +# - name: Cache compiled build +# id: cache-build +# uses: actions/cache@v4 +# env: +# cache-name: cache-compiled-build +# with: +# path: tests/support/test_server/_build +# key: ${{ runner.os }}-mix-${{ env.cache-name }}-2-${{ hashFiles('**/mix.lock') }} +# restore-keys: | +# ${{ runner.os }}-mix-${{ env.cache-name }}- +# ${{ runner.os }}-mix- +# - name: Set up Elixir +# run: brew install elixir +# +# - name: Install test server dependencies, compile and run in background +# working-directory: ./tests/support/test_server +# run: | +# mix deps.get +# mix compile +# mix phx.server & - name: Set up JDK 17 uses: actions/setup-java@v4 @@ -73,7 +74,7 @@ jobs: distribution: 'temurin' - name: Install gradle - uses: gradle/gradle-build-action@v3.1.0 + uses: gradle/gradle-build-action@v3.2.1 # https://github.com/actions/runner-images/blob/5a9870800dc54127d22ee36c303b47314d231c69/images/macos/macos-14-arm64-Readme.md # There's no python in the m1 macos runners. diff --git a/.github/workflows/uniffi-swift-test.yml b/.github/workflows/uniffi-swift-test.yml index be4e1a75..857dfb3b 100644 --- a/.github/workflows/uniffi-swift-test.yml +++ b/.github/workflows/uniffi-swift-test.yml @@ -25,36 +25,37 @@ jobs: aarch64-apple-darwin x86_64-apple-darwin - - name: Cache deps - id: cache-deps - uses: actions/cache@v4 - env: - cache-name: cache-elixir-deps - with: - path: tests/support/test_server/deps - key: ${{ runner.os }}-mix-${{ env.cache-name }}-2-${{ hashFiles('**/mix.lock') }} - restore-keys: | - ${{ runner.os }}-mix-${{ env.cache-name }}- - - name: Cache compiled build - id: cache-build - uses: actions/cache@v4 - env: - cache-name: cache-compiled-build - with: - path: tests/support/test_server/_build - key: ${{ runner.os }}-mix-${{ env.cache-name }}-2-${{ hashFiles('**/mix.lock') }} - restore-keys: | - ${{ runner.os }}-mix-${{ env.cache-name }}- - ${{ runner.os }}-mix- - - name: Set up Elixir - run: brew install elixir - - - name: Install test server dependencies, compile and run in background - working-directory: ./tests/support/test_server - run: | - mix deps.get - mix compile - mix phx.server & +# TODO: Fix this when enabling live-channels feature flag. +# - name: Cache deps +# id: cache-deps +# uses: actions/cache@v4 +# env: +# cache-name: cache-elixir-deps +# with: +# path: tests/support/test_server/deps +# key: ${{ runner.os }}-mix-${{ env.cache-name }}-2-${{ hashFiles('**/mix.lock') }} +# restore-keys: | +# ${{ runner.os }}-mix-${{ env.cache-name }}- +# - name: Cache compiled build +# id: cache-build +# uses: actions/cache@v4 +# env: +# cache-name: cache-compiled-build +# with: +# path: tests/support/test_server/_build +# key: ${{ runner.os }}-mix-${{ env.cache-name }}-2-${{ hashFiles('**/mix.lock') }} +# restore-keys: | +# ${{ runner.os }}-mix-${{ env.cache-name }}- +# ${{ runner.os }}-mix- +# - name: Set up Elixir +# run: brew install elixir +# +# - name: Install test server dependencies, compile and run in background +# working-directory: ./tests/support/test_server +# run: | +# mix deps.get +# mix compile +# mix phx.server & - uses: taiki-e/install-action@v2 with: diff --git a/.github/workflows/x86_64-linux-android.yml b/.github/workflows/x86_64-linux-android.yml index 6bd07755..77751345 100644 --- a/.github/workflows/x86_64-linux-android.yml +++ b/.github/workflows/x86_64-linux-android.yml @@ -39,35 +39,36 @@ jobs: cargo install --git https://github.com/sonos/dinghy.git --force --rev ${CARGO_DINGHY_REV} cargo-dinghy fi - - name: Cache deps - id: cache-deps - uses: actions/cache@v4 - env: - cache-name: cache-elixir-deps - with: - path: tests/support/test_server/deps - key: ${{ runner.os }}-mix-${{ env.cache-name }}-deps-${{ hashFiles('**/mix.lock') }} - - - name: Cache compiled build - id: cache-build - uses: actions/cache@v4 - env: - cache-name: cache-compiled-build - with: - path: tests/support/test_server/_build - key: ${{ runner.os }}-mix-${{ env.cache-name }}-build-${{ hashFiles('**/mix.lock') }} - - - uses: erlef/setup-beam@v1 - with: - elixir-version: 1.15 - otp-version: 25 - - - name: Install test server dependencies, compile and run in background - working-directory: ./tests/support/test_server - run: | - mix deps.get - mix compile - mix phx.server & +# TODO: Fix this when enabling live-channels feature flag. +# - name: Cache deps +# id: cache-deps +# uses: actions/cache@v4 +# env: +# cache-name: cache-elixir-deps +# with: +# path: tests/support/test_server/deps +# key: ${{ runner.os }}-mix-${{ env.cache-name }}-deps-${{ hashFiles('**/mix.lock') }} +# +# - name: Cache compiled build +# id: cache-build +# uses: actions/cache@v4 +# env: +# cache-name: cache-compiled-build +# with: +# path: tests/support/test_server/_build +# key: ${{ runner.os }}-mix-${{ env.cache-name }}-build-${{ hashFiles('**/mix.lock') }} +# +# - uses: erlef/setup-beam@v1 +# with: +# elixir-version: 1.15 +# otp-version: 25 +# +# - name: Install test server dependencies, compile and run in background +# working-directory: ./tests/support/test_server +# run: | +# mix deps.get +# mix compile +# mix phx.server & - name: Set up JDK 17 uses: actions/setup-java@v4 diff --git a/Cargo.toml b/Cargo.toml index ade1a79c..a98669b3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [workspace] resolver = "2" members = [ - "crates/core", + "crates/core", "crates/uniffi-bindgen", ] [workspace.package] @@ -25,10 +25,15 @@ split-debuginfo = "unpacked" debug = 2 [profile.release] -opt-level = 1 +opt-level = 'z' # Optimize for size +lto = true # Enable link-time optimization +codegen-units = 1 # Reduce number of codegen units to increase optimizations +panic = 'abort' # Abort on panic +strip = 'debuginfo' # Strip symbols from binary* split-debuginfo = "packed" debug = 1 + [patch.crates-io] # Work for https://github.com/sfackler/rust-native-tls/pull/285 hasn't been published to crates.io yet. native-tls = { git = "https://github.com/sfackler/rust-native-tls", rev = "0b69ce6a3c4bfe973ede44f6862fc13f3f09c773" } diff --git a/Makefile.toml b/Makefile.toml index dfa5c372..7b588558 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -124,10 +124,11 @@ args = [ "${CARGO_TARGET_DIR}/universal/macos/", "${CARGO_TARGET_DIR}/universal/ios-sim/", "${CARGO_TARGET_DIR}/universal/watchos-sim/", + "${CARGO_TARGET_DIR}/universal/watchos/", "${CARGO_TARGET_DIR}/universal/tvos-sim/", ] -[tasks.build-macos] +[tasks.build-apple-std-targets] workspace = false category = "Build" description = "Compiles for all targets needed to produce a universal library for macOS" @@ -138,114 +139,102 @@ args = [ "@@remove-empty(CARGO_MAKE_CARGO_VERBOSE_FLAGS)", "--target", "aarch64-apple-darwin", "--target", "x86_64-apple-darwin", - "-p", "liveview-native-core" -] -dependencies = ["install-targets"] -[tasks.build-ios] -workspace = false -category = "Build" -description = "Compiles for all targets needed to produce a universal library for iOS" -command = "rustup" -args = [ - "run", "${CARGO_MAKE_TOOLCHAIN}", - "cargo", "build", - "@@remove-empty(CARGO_MAKE_CARGO_VERBOSE_FLAGS)", "--target", "aarch64-apple-ios", "--target", "aarch64-apple-ios-sim", - "--target", "x86_64-apple-ios", "-p", - "liveview-native-core" + "--target", "x86_64-apple-ios", + "-p", "liveview-native-core" ] dependencies = ["install-targets"] -[tasks.build-watchos] + +[tasks.build-apple-no-std-targets] workspace = false category = "Build" -description = "Compiles for all targets needed to produce a universal library for watchOS" +description = "Compiles for all targets needed to produce a universal library for watchOS and tvOS" command = "rustup" args = [ "run", "${CARGO_MAKE_TOOLCHAIN}", "cargo", "build", "@@remove-empty(CARGO_MAKE_CARGO_VERBOSE_FLAGS)", "-Z", "build-std", + "--target", "arm64_32-apple-watchos", "--target", "aarch64-apple-watchos-sim", + "--target", "aarch64-apple-watchos", "--target", "x86_64-apple-watchos-sim", - "-p", "liveview-native-core" -] -dependencies = ["install-targets"] -[tasks.build-tvos] -workspace = false -category = "Build" -description = "Compiles for all targets needed to produce a universal library for tvOS" -command = "rustup" -args = [ - "run", "${CARGO_MAKE_TOOLCHAIN}", - "cargo", "build", - "@@remove-empty(CARGO_MAKE_CARGO_VERBOSE_FLAGS)", - "-Z", "build-std", "--target", "aarch64-apple-tvos", "--target", "aarch64-apple-tvos-sim", "--target", "x86_64-apple-tvos", "-p", "liveview-native-core" ] -dependencies = ["install-targets"] [tasks.lipo-macos] -dependencies = ["create-lipo-universal-directories", "build-macos"] +dependencies = ["create-lipo-universal-directories", "build-apple-std-targets"] workspace = false category = "Build" description = "Combines macOS targets into a universal binary" command = "xcrun" args = [ - "lipo", "-create", - "${CARGO_TARGET_DIR}/aarch64-apple-darwin/debug/libliveview_native_core.a", - "${CARGO_TARGET_DIR}/x86_64-apple-darwin/debug/libliveview_native_core.a", - "-output", "${CARGO_TARGET_DIR}/universal/macos/libliveview_native_core.a" + "lipo", "-create", + "${CARGO_TARGET_DIR}/aarch64-apple-darwin/debug/libliveview_native_core.a", + "${CARGO_TARGET_DIR}/x86_64-apple-darwin/debug/libliveview_native_core.a", + "-output", "${CARGO_TARGET_DIR}/universal/macos/libliveview_native_core.a" ] [tasks.lipo-ios-sim] -dependencies = ["create-lipo-universal-directories", "build-ios"] +dependencies = ["create-lipo-universal-directories", "build-apple-std-targets"] workspace = false category = "Build" description = "Combines iOS simulator targets into a universal binary" command = "xcrun" args = [ - "lipo", - "-create", - "${CARGO_TARGET_DIR}/aarch64-apple-ios-sim/debug/libliveview_native_core.a", - "${CARGO_TARGET_DIR}/x86_64-apple-ios/debug/libliveview_native_core.a", - "-output", "${CARGO_TARGET_DIR}/universal/ios-sim/libliveview_native_core.a" + "lipo", + "-create", + "${CARGO_TARGET_DIR}/aarch64-apple-ios-sim/debug/libliveview_native_core.a", + "${CARGO_TARGET_DIR}/x86_64-apple-ios/debug/libliveview_native_core.a", + "-output", "${CARGO_TARGET_DIR}/universal/ios-sim/libliveview_native_core.a" ] [tasks.lipo-tvos-sim] -dependencies = ["create-lipo-universal-directories", "build-tvos"] +dependencies = ["create-lipo-universal-directories", "build-apple-no-std-targets"] workspace = false category = "Build" description = "Combines iOS simulator targets into a universal binary" command = "xcrun" args = [ - "lipo", - "-create", - "${CARGO_TARGET_DIR}/aarch64-apple-tvos-sim/debug/libliveview_native_core.a", - "${CARGO_TARGET_DIR}/x86_64-apple-tvos/debug/libliveview_native_core.a", - "-output", "${CARGO_TARGET_DIR}/universal/tvos-sim/libliveview_native_core.a" + "lipo", + "-create", + "${CARGO_TARGET_DIR}/aarch64-apple-tvos-sim/debug/libliveview_native_core.a", + "${CARGO_TARGET_DIR}/x86_64-apple-tvos/debug/libliveview_native_core.a", + "-output", "${CARGO_TARGET_DIR}/universal/tvos-sim/libliveview_native_core.a" ] -[tasks.lipo-watchos-sim] -dependencies = ["create-lipo-universal-directories", "build-watchos"] +[tasks.lipo-watchos] +dependencies = ["create-lipo-universal-directories", "build-apple-no-std-targets"] workspace = false category = "Build" description = "Combines watchOS simulator targets into a universal binary" command = "xcrun" args = [ - "lipo", "-create", - "${CARGO_TARGET_DIR}/aarch64-apple-watchos-sim/debug/libliveview_native_core.a", - "${CARGO_TARGET_DIR}/x86_64-apple-watchos-sim/debug/libliveview_native_core.a", - # This isn't a simulator but putting it in the xcframework task doesn't work. + "lipo", "-create", + "${CARGO_TARGET_DIR}/aarch64-apple-watchos/debug/libliveview_native_core.a", "${CARGO_TARGET_DIR}/arm64_32-apple-watchos/debug/libliveview_native_core.a", - "-output", "${CARGO_TARGET_DIR}/universal/watchos-sim/libliveview_native_core.a" + "-output", "${CARGO_TARGET_DIR}/universal/watchos/libliveview_native_core.a" +] + +[tasks.lipo-watchos-sim] +dependencies = ["create-lipo-universal-directories", "build-apple-no-std-targets"] +workspace = false +category = "Build" +description = "Combines watchOS simulator targets into a universal binary" +command = "xcrun" +args = [ + "lipo", "-create", + "${CARGO_TARGET_DIR}/aarch64-apple-watchos-sim/debug/libliveview_native_core.a", + "${CARGO_TARGET_DIR}/x86_64-apple-watchos-sim/debug/libliveview_native_core.a", + "-output", "${CARGO_TARGET_DIR}/universal/watchos-sim/libliveview_native_core.a" ] [tasks.install-targets] @@ -295,22 +284,6 @@ description = "Run cargo-bloat" command = "cargo" args = ["bloat", "${@}"] -[tasks.uniffi-swift-generate-from-udl] -workspace = false -category = "Packaging" -description = "" -command = "cargo" -args = [ - "run", - "--bin", - "uniffi-bindgen", - "--", - "generate", - "${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/crates/core/src/uniffi.udl", - "--language=swift", - "--out-dir=${CARGO_TARGET_DIR}/uniffi/swift/generated", -] - [tasks.uniffi-swift-generate] workspace = false category = "Packaging" @@ -318,7 +291,7 @@ description = "" command = "cargo" args = [ "run", - "--bin", + "-p", "uniffi-bindgen", "--", "generate", @@ -327,58 +300,41 @@ args = [ "--language=swift", "--out-dir=${CARGO_TARGET_DIR}/uniffi/swift/generated", ] -dependencies = ["build-macos"] - -[tasks.uniffi-kotlin-generate] -workspace = false -category = "Packaging" -description = "" -command = "cargo" -args = [ - "run", - "--bin", - "uniffi-bindgen", - "--", - "generate", - "--library", - "${CARGO_TARGET_DIR}/aarch64-apple-darwin/debug/libliveview_native_core.dylib", - "--language=kotlin", - "--out-dir=${CARGO_TARGET_DIR}/uniffi/kotlin/generated", -] -dependencies = ["build-macos"] +dependencies = ["build-apple-std-targets"] [tasks.uniffi-swift-modulemap] workspace = false -category = "Packaging" +category = "Packaging the module maps for FFIs" description = "" script_runner = "@shell" script = ''' cat ${CARGO_TARGET_DIR}/uniffi/swift/generated/LiveViewNativeCoreFFI.modulemap \ - ${CARGO_TARGET_DIR}/uniffi/swift/generated/PhoenixChannelsClientFFI.modulemap \ > \ ${CARGO_TARGET_DIR}/uniffi/swift/generated/module.modulemap ''' +# TODO: Put this back in the cat statment +#${CARGO_TARGET_DIR}/uniffi/swift/generated/PhoenixChannelsClientFFI.modulemap \ dependencies = ["uniffi-swift-generate"] [tasks.uniffi-swift-package] workspace = false category = "Packaging" -description = "Generates the LiveViewNativeCore.xcframework package" -dependencies = ["uniffi-swift-modulemap", "uniffi-swift-package-lvn", "uniffi-swift-package-phx"] +description = "Generates the swift package from the liveview native core and phoenix-channels-clients bindings" +dependencies = ["uniffi-swift-modulemap", "uniffi-swift-package-lvn"]# TODO add this back when adding channels clients, "uniffi-swift-package-phoenix" [tasks.uniffi-swift-package-lvn] workspace = false category = "Packaging" -description = "Generates the LiveViewNativeCore.xcframework package" +description = "Copy the generated swift bindings for LiveViewNativeCore to the correct location." command = "cp" args = [ "${CARGO_TARGET_DIR}/uniffi/swift/generated/LiveViewNativeCore.swift", "${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/crates/core/liveview-native-core-swift/Sources/LiveViewNativeCore/LiveViewNativeCore.swift", ] -[tasks.uniffi-swift-package-phx] +[tasks.uniffi-swift-package-phoenix] workspace = false category = "Packaging" -description = "Generates the LiveViewNativeCore.xcframework package" +description = "Copy the swift bindings for PhoenixChannelsClient to the right location." command = "cp" args = [ "${CARGO_TARGET_DIR}/uniffi/swift/generated/PhoenixChannelsClient.swift", @@ -394,23 +350,27 @@ args = [ "-create-xcframework", "-output", "${CARGO_TARGET_DIR}/uniffi/swift/RustFramework.xcframework", - # macOS + # macOS "-library", "${CARGO_TARGET_DIR}/universal/macos/libliveview_native_core.a", "-headers", "${CARGO_TARGET_DIR}/uniffi/swift/generated", - # iOS + # iOS "-library", "${CARGO_TARGET_DIR}/aarch64-apple-ios/debug/libliveview_native_core.a", "-headers", "${CARGO_TARGET_DIR}/uniffi/swift/generated", - # iOS sim + # iOS sim "-library", "${CARGO_TARGET_DIR}/universal/ios-sim/libliveview_native_core.a", "-headers", "${CARGO_TARGET_DIR}/uniffi/swift/generated", - # watchOS sim + # watchOS sim "-library", "${CARGO_TARGET_DIR}/universal/watchos-sim/libliveview_native_core.a", "-headers", "${CARGO_TARGET_DIR}/uniffi/swift/generated", - # tvOS + # watchOS + "-library", "${CARGO_TARGET_DIR}/universal/watchos/libliveview_native_core.a", + "-headers", "${CARGO_TARGET_DIR}/uniffi/swift/generated", + + # tvOS "-library", "${CARGO_TARGET_DIR}/aarch64-apple-tvos/debug/libliveview_native_core.a", "-headers", "${CARGO_TARGET_DIR}/uniffi/swift/generated", @@ -419,16 +379,15 @@ args = [ "-headers", "${CARGO_TARGET_DIR}/uniffi/swift/generated", ] dependencies = [ - "build-macos", + "build-apple-std-targets", "lipo-macos", - "build-ios", "lipo-ios-sim", - "build-watchos", + "build-apple-no-std-targets", "lipo-watchos-sim", - "build-tvos", + "lipo-watchos", "lipo-tvos-sim", "remove-existing-uniffi-xcframework", - "uniffi-swift-package" + "uniffi-swift-generate", ] [tasks.remove-existing-uniffi-xcframework] @@ -443,7 +402,8 @@ dependencies = [ "uniffi-swift-test-tvos", "uniffi-swift-test-ios", "uniffi-swift-test-macos", - "uniffi-swift-test-watchos", +# TODO: When https://github.com/rust-lang/rust/pull/124089 lands, re-enable the watchOS tests. +#"uniffi-swift-test-watchos", ] [tasks.uniffi-swift-test-package] diff --git a/crates/core/Cargo.toml b/crates/core/Cargo.toml index 693b44d3..78b58182 100644 --- a/crates/core/Cargo.toml +++ b/crates/core/Cargo.toml @@ -13,7 +13,6 @@ license-file.workspace = true readme.workspace = true publish.workspace = true -build = "build.rs" [lib] crate-type = [ @@ -23,41 +22,52 @@ crate-type = [ ] name = "liveview_native_core" +[features] +default = [] +liveview-channels = [ + "phoenix_channels_client", + "reqwest", + "uniffi/tokio", + "async-compat", + "futures", +] +liveview-channels-tls = [ + "liveview-channels", + "phoenix_channels_client/native-tls", +] + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -cranelift-entity = { version = "0.104" } +cranelift-entity = { version = "0.106" } fixedbitset = { version = "0.4" } fxhash = { version = "0.2" } html5gum = { git = "https://github.com/liveviewnative/html5gum", branch = "lvn" } -intrusive-collections = { version = "0.9", features = ["nightly"] } indexmap = { version = "2.1", features = ["std"] } petgraph = { version = "0.6", default-features = false, features = ["graphmap"] } -phoenix_channels_client = { git = "https://github.com/liveview-native/phoenix-channels-client", branch = "main" } serde = { version = "1.0", features = ["derive"] } serde_json = { version = "1.0" } smallstr = { version = "0.3", features = ["union"] } smallvec = { version = "1.10", features = ["union", "const_generics", "specialization"] } thiserror = "1.0" -uniffi = { version = "0.26", features = ["cli", "tokio"] } -async-compat = "0.2.3" -futures = "0.3.29" log = "0.4" -reqwest = { version = "0.11.23", features = ["native-tls-vendored"] } -tokio = { version = "1.35", features = ["full"] } +reqwest = { version = "0.12.3", features = ["native-tls-vendored"], optional = true } +uniffi = { version = "0.27" } +phoenix_channels_client = { git = "https://github.com/liveview-native/phoenix-channels-client", branch = "simlay/fix-native-tls-feature-flag", optional = true } +async-compat = { version = "0.2.3", optional = true } +futures = { version = "0.3.29", optional = true } [build-dependencies] Inflector = "0.11" -uniffi = { version = "0.26", features = [ "build" ] } [dev-dependencies] paste = { version = "1.0" } pretty_assertions = { version = "1.4.0" } text-diff = { version = "0.4.0" } -uniffi = { version = "0.26", features = ["bindgen-tests", "tokio", "cli"]} +uniffi = { version = "0.27", features = ["bindgen-tests", "tokio"]} tokio = { version = "1.35", features = ["full"] } env_logger = "0.11.1" # For image generation for tests -image = "0.24.8" +image = "0.25.1" tempfile = "3.9.0" diff --git a/crates/core/examples/streaming.rs b/crates/core/examples/streaming.rs deleted file mode 100644 index b920f02e..00000000 --- a/crates/core/examples/streaming.rs +++ /dev/null @@ -1,26 +0,0 @@ - -use std::time::Duration; -use liveview_native_core::live_socket::LiveSocket; - -#[cfg(target_os = "android")] -const HOST: &str = "10.0.2.2"; - -#[cfg(not(target_os = "android"))] -const HOST: &str = "127.0.0.1"; -const TIME_OUT : Duration = Duration::from_secs(2); - -#[tokio::main] -async fn main() { - - let url = format!("http://{HOST}:4000/simple_stream?_lvn[format]=swiftui"); - - let live_socket = LiveSocket::new( - url.to_string(), TIME_OUT - ).expect("Failed to get liveview socket"); - let live_channel = live_socket - .join_liveview_channel() - .await - .expect("Failed to join the liveview channel"); - live_channel.merge_diffs().await.expect("Failed to merge diffs"); - -} diff --git a/crates/core/liveview-native-core-jetpack/core/build.gradle.kts b/crates/core/liveview-native-core-jetpack/core/build.gradle.kts index eeaddc87..2b3fd9d1 100644 --- a/crates/core/liveview-native-core-jetpack/core/build.gradle.kts +++ b/crates/core/liveview-native-core-jetpack/core/build.gradle.kts @@ -74,7 +74,7 @@ android { commandLine( "cargo", "run", - "--bin", + "-p", "uniffi-bindgen", "--", "generate", @@ -115,6 +115,7 @@ cargo { tasks.configureEach { if ((name == "javaPreCompileDebug" || name == "javaPreCompileRelease")) { dependsOn("cargoBuild") + dependsOn("generateDebugUniFFIBindings") } if (name == "cargoBuild") { dependsOn("generateDebugUniFFIBindings") @@ -146,7 +147,7 @@ publishing { register("release") { groupId = "org.phoenixframework" artifactId = "liveview-native-core-jetpack" - version = "0.1.0-pre-alpha-08" + version = "0.2.0-pre-alpha-01" afterEvaluate { from(components["release"]) diff --git a/crates/core/liveview-native-core-jetpack/core/src/test/java/org/phoenixframework/liveview_jetpack/DocumentTest.kt b/crates/core/liveview-native-core-jetpack/core/src/test/java/org/phoenixframework/liveview_jetpack/DocumentTest.kt index c7dcaa0a..19ea4d91 100644 --- a/crates/core/liveview-native-core-jetpack/core/src/test/java/org/phoenixframework/liveview_jetpack/DocumentTest.kt +++ b/crates/core/liveview-native-core-jetpack/core/src/test/java/org/phoenixframework/liveview_jetpack/DocumentTest.kt @@ -6,8 +6,7 @@ import org.phoenixframework.liveviewnative.core.Document; import org.phoenixframework.liveviewnative.core.DocumentChangeHandler; import org.phoenixframework.liveviewnative.core.ChangeType; import org.phoenixframework.liveviewnative.core.NodeRef; -import org.phoenixframework.liveviewnative.core.LiveSocket; -import org.phoenixframework.liveviewnative.core.LiveFile; +import org.phoenixframework.liveviewnative.core.NodeData; import java.time.Duration; import kotlinx.coroutines.*; @@ -16,10 +15,13 @@ import kotlinx.coroutines.test.runTest; import kotlin.system.*; import java.util.Base64; +/* +import org.phoenixframework.liveviewnative.core.LiveSocket; +import org.phoenixframework.liveviewnative.core.LiveFile; class SocketTest { @Test fun simple_connect() = runTest { - var live_socket = LiveSocket("http://127.0.0.1:4000/upload?_lvn[format]=swiftui", Duration.ofDays(10)); + var live_socket = LiveSocket("http://127.0.0.1:4001/upload?_lvn[format]=swiftui", Duration.ofDays(10)); var live_channel = live_socket.joinLiveviewChannel() var phx_id = live_channel.getPhxRefFromUploadJoinPayload() // This is a PNG located at crates/core/tests/support/tinycross.png @@ -30,15 +32,16 @@ class SocketTest { live_channel.uploadFile(live_file) } } +*/ class SimpleChangeHandler: DocumentChangeHandler { constructor() { } override fun `handle`( - `context`: String, `changeType`: ChangeType, `nodeRef`: NodeRef, + `nodeData`: NodeData, `optionNodeRef`: NodeRef?, ) { println("${changeType}") @@ -68,6 +71,47 @@ class DocumentTest { var rendered = doc.render(); assertEquals(input, rendered) } + @Test + fun json_merging_from_empty() { + var doc = Document.empty(); + var input = """ + { + "0":"0", + "1":"0", + "2":"", + "s":[ + "\n \n \n Static Text \n Counter 1: ", + " \n Counter 2: ", + " \n", + "\n" + ] + } + """ + doc.mergeFragmentJson(input) + var expected = """ + + + + Static Text + + + Counter 1: 0 + + + Counter 2: 0 + +""" + var rendered = doc.render(); + assertEquals(expected, rendered) + } @Test fun json_merging() { @@ -141,8 +185,9 @@ class DocumentTest { } } """ - var simple = SimpleChangeHandler() - doc.mergeFragmentJson(first_increment, simple); + var simple = SimpleChangeHandler(); + doc.setEventHandler(simple); + doc.mergeFragmentJson(first_increment); rendered = doc.render(); expected = """ \\n \\n" + ], + "r" : 1 + } + } + """ + let doc = try Document.parseFragmentJson(initial_json) + let simple = SimpleHandler() + doc.setEventHandler(simple) + print("initial:\n", doc.render()) + var expected = """ + + + + + """ + XCTAssertEqual(expected, doc.render()) + + let first_increment = """ + { + "0" : { + "0" : { + "s" : [ + " Temperature: ", + " " + ], + "d" : [ + ["Increment"] + ] + } + } + } + """ + try doc.mergeFragmentJson(first_increment) + expected = """ + + + Temperature: Increment + + + + + """ + print("first:\n", doc.render()) + XCTAssertEqual(expected, doc.render()) + let second_increment = """ + { + "0" : { + "0" : { + "d" : [ ] + } + } + } + """ + try doc.mergeFragmentJson(second_increment) + print("second:\n", doc.render()) + let third_increment = """ + { "0" : { "0" : { "d" : [ [ "Increment" ] ] } } } + """ + try doc.mergeFragmentJson(third_increment) + print("third:\n", doc.render()) + } func testIntegration() throws { let input = """ @@ -50,8 +132,10 @@ final class LiveViewNativeCoreTests: XCTestCase { ] } """ - let initial_document = try Document.parseFragmentJson(initial_json) - let initial_rendered = initial_document.render() + let simple = SimpleHandler() + let doc = try Document.parseFragmentJson(initial_json) + doc.setEventHandler(simple) + let initial_rendered = doc.render() var expected = """