Skip to content

Commit 4b7d303

Browse files
authored
Re-add liveview-channels feature flag (#101)
* Initial parts for re-adding phoenix-channels-client in * Add PhoenixChannelClient to swift release
1 parent dea33eb commit 4b7d303

File tree

8 files changed

+59
-74
lines changed

8 files changed

+59
-74
lines changed

.github/workflows/ci.yml

Lines changed: 44 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ jobs:
4343
target
4444
key: ${{ github.workflow }}-${{ github.job }}-toolchain-${{ env.TOOLCHAIN }}-cargo-${{ hashFiles('**/Cargo.lock') }}
4545

46+
- name: Set up Elixir
47+
run: brew install elixir
48+
49+
- name: Install test server dependencies, compile and run in background
50+
working-directory: ./tests/support/test_server
51+
run: |
52+
mix deps.get
53+
mix compile
54+
mix phx.server &
55+
4656
- name: Set up JDK 17
4757
uses: actions/setup-java@v4
4858
with:
@@ -97,6 +107,16 @@ jobs:
97107
target
98108
key: ${{ github.workflow }}-${{ github.job }}-toolchain-${{ env.TOOLCHAIN }}-cargo-${{ hashFiles('**/Cargo.lock') }}
99109

110+
- name: Set up Elixir
111+
run: brew install elixir
112+
113+
- name: Install test server dependencies, compile and run in background
114+
working-directory: ./tests/support/test_server
115+
run: |
116+
mix deps.get
117+
mix compile
118+
mix phx.server &
119+
100120
- name: Build swift package
101121
run: cargo make uniffi-swift-package
102122

@@ -122,6 +142,16 @@ jobs:
122142
target
123143
key: ${{ github.workflow }}-${{ github.job }}-toolchain-${{ env.TOOLCHAIN }}-cargo-${{ hashFiles('**/Cargo.lock') }}
124144

145+
- name: Set up Elixir
146+
run: brew install elixir
147+
148+
- name: Install test server dependencies, compile and run in background
149+
working-directory: ./tests/support/test_server
150+
run: |
151+
mix deps.get
152+
mix compile
153+
mix phx.server &
154+
125155
- name: Get the JNA jar for testing kotlin.
126156
run: wget 'https://repo1.maven.org/maven2/net/java/dev/jna/jna/5.14.0/jna-5.14.0.jar'
127157
- name: Test
@@ -169,19 +199,6 @@ jobs:
169199
with:
170200
os: ${{ matrix.apple-sim }}
171201

172-
- name: Build tests
173-
run: |
174-
cargo -Zbuild-std test --target ${{ matrix.rust-target }} --no-run
175-
176-
- name: Run Rust tests on simulator for ${{ matrix.rust-target }}
177-
env:
178-
DINGHY_LOG: debug
179-
timeout-minutes: 20
180-
run: |
181-
cargo dinghy all-platforms
182-
cargo dinghy all-devices
183-
cargo -Zbuild-std test --target ${{ matrix.rust-target }}
184-
185202
- name: Set up Elixir
186203
run: brew install elixir
187204

@@ -192,25 +209,15 @@ jobs:
192209
mix compile
193210
mix phx.server &
194211
195-
- name: Build tests with liveview-channels
196-
run: cargo -Zbuild-std test --target ${{ matrix.rust-target }} --features liveview-channels --no-run
197-
198-
- name: Run Rust tests on simulator for ${{ matrix.rust-target }} with liveview-channels
199-
env:
200-
DINGHY_LOG: debug
201-
timeout-minutes: 20
202-
run: |
203-
cargo -Zbuild-std test --target ${{ matrix.rust-target }} --features liveview-channels -- --test-threads 1
204-
205212
- name: Build tests with liveview-channels-tls
206-
run: cargo -Zbuild-std test --target ${{ matrix.rust-target }} --features liveview-channels-tls --no-run
213+
run: cargo -Zbuild-std test --target ${{ matrix.rust-target }} --no-run
207214

208-
- name: Run Rust tests on simulator for ${{ matrix.rust-target }} with liveview-channels-tls
215+
- name: Run Rust tests on simulator for ${{ matrix.rust-target }}
209216
env:
210217
DINGHY_LOG: debug
211218
timeout-minutes: 20
212219
run: |
213-
cargo -Zbuild-std test --target ${{ matrix.rust-target }} --features liveview-channels-tls -- --test-threads 1
220+
cargo -Zbuild-std test --target ${{ matrix.rust-target }} -- --test-threads 1
214221
215222
android_simulator_tests:
216223
# rust cross-compilation
@@ -238,36 +245,17 @@ jobs:
238245
with:
239246
240247

241-
# TODO: Fix this when enabling live-channels feature flag.
242-
# - name: Cache deps
243-
# id: cache-deps
244-
# uses: actions/cache@v4
245-
# env:
246-
# cache-name: cache-elixir-deps
247-
# with:
248-
# path: tests/support/test_server/deps
249-
# key: ${{ runner.os }}-mix-${{ env.cache-name }}-deps-${{ hashFiles('**/mix.lock') }}
250-
#
251-
# - name: Cache compiled build
252-
# id: cache-build
253-
# uses: actions/cache@v4
254-
# env:
255-
# cache-name: cache-compiled-build
256-
# with:
257-
# path: tests/support/test_server/_build
258-
# key: ${{ runner.os }}-mix-${{ env.cache-name }}-build-${{ hashFiles('**/mix.lock') }}
259-
#
260-
# - uses: erlef/setup-beam@v1
261-
# with:
262-
# elixir-version: 1.15
263-
# otp-version: 25
264-
#
265-
# - name: Install test server dependencies, compile and run in background
266-
# working-directory: ./tests/support/test_server
267-
# run: |
268-
# mix deps.get
269-
# mix compile
270-
# mix phx.server &
248+
- uses: erlef/setup-beam@v1
249+
with:
250+
elixir-version: 1.15
251+
otp-version: 25
252+
253+
- name: Install test server dependencies, compile and run in background
254+
working-directory: ./tests/support/test_server
255+
run: |
256+
mix deps.get
257+
mix compile
258+
mix phx.server &
271259
272260
- name: Set up JDK 17
273261
uses: actions/setup-java@v4

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,14 @@ jobs:
8989
sed -i "" -E "s/(let releaseChecksum = \")[^\"]+(\")/\1$checksum\2/g" Package.swift
9090
sed -i "" -E "s/let useLocalFramework = true/let useLocalFramework = false/g" Package.swift
9191
git add Package.swift
92-
git add -f ./crates/core/liveview-native-core-swift/Sources/LiveViewNativeCore/LiveViewNativeCore.swift
92+
git add -f ./crates/core/liveview-native-core-swift/Sources/LiveViewNativeCore/*.swift
9393
git diff --staged
9494
9595
- name: Commit, tag and push swift package
9696
if: github.event_name == 'release'
9797
run: |
9898
git add Package.swift
99-
git add ./crates/core/liveview-native-core-swift/Sources/LiveViewNativeCore/LiveViewNativeCore.swift
99+
git add ./crates/core/liveview-native-core-swift/Sources/LiveViewNativeCore/*.swift
100100
git commit -m "Update Package.swift and add generated LiveViewNativeCore.swift to tracking"
101101
git tag -fa ${{ github.event.release.tag_name }} -m "Swift Package Release ${{ github.event.release.tag_name }}"
102102
git push origin ${{ github.event.release.tag_name }} --force

Makefile.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,18 +296,17 @@ description = ""
296296
script_runner = "@shell"
297297
script = '''
298298
cat ${CARGO_TARGET_DIR}/uniffi/swift/generated/LiveViewNativeCoreFFI.modulemap \
299+
${CARGO_TARGET_DIR}/uniffi/swift/generated/PhoenixChannelsClientFFI.modulemap \
299300
> \
300301
${CARGO_TARGET_DIR}/uniffi/swift/generated/module.modulemap
301302
'''
302-
# TODO: Put this back in the cat statment
303-
#${CARGO_TARGET_DIR}/uniffi/swift/generated/PhoenixChannelsClientFFI.modulemap \
304303
dependencies = ["uniffi-swift-generate"]
305304

306305
[tasks.uniffi-swift-package]
307306
workspace = false
308307
category = "Packaging"
309308
description = "Generates the swift package from the liveview native core and phoenix-channels-clients bindings"
310-
dependencies = ["uniffi-swift-modulemap", "uniffi-swift-package-lvn"]# TODO add this back when adding channels clients, "uniffi-swift-package-phoenix"
309+
dependencies = ["uniffi-swift-modulemap", "uniffi-swift-package-lvn", "uniffi-swift-package-phoenix"]
311310

312311
[tasks.uniffi-swift-package-lvn]
313312
workspace = false

crates/core/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ crate-type = [
2323
name = "liveview_native_core"
2424

2525
[features]
26-
default = []
26+
default = ["liveview-channels-tls"]
2727
liveview-channels = [
2828
"phoenix_channels_client",
2929
"reqwest",
@@ -33,6 +33,7 @@ liveview-channels = [
3333
]
3434
liveview-channels-tls = [
3535
"liveview-channels",
36+
"reqwest/native-tls-vendored",
3637
"phoenix_channels_client/native-tls",
3738
]
3839

@@ -43,19 +44,18 @@ cranelift-entity = { version = "0.107" }
4344
fixedbitset = { version = "0.4" }
4445
fxhash = { version = "0.2" }
4546
html5gum = { git = "https://github.com/liveviewnative/html5gum", branch = "lvn" }
46-
indexmap = { version = "2.1", features = ["std"] }
4747
petgraph = { version = "0.6", default-features = false, features = ["graphmap"] }
4848
serde = { version = "1.0", features = ["derive"] }
4949
serde_json = { version = "1.0" }
5050
smallstr = { version = "0.3", features = ["union"] }
5151
smallvec = { version = "1.10", features = ["union", "const_generics", "specialization"] }
5252
thiserror = "1.0"
5353
log = "0.4"
54-
reqwest = { version = "0.12.3", features = ["native-tls-vendored"], optional = true }
54+
reqwest = { version = "0.12.3", default-features = false, optional = true }
5555
uniffi = { version = "0.27" }
56-
phoenix_channels_client = { git = "https://github.com/liveview-native/phoenix-channels-client", branch = "simlay/fix-native-tls-feature-flag", optional = true }
5756
async-compat = { version = "0.2.3", optional = true }
5857
futures = { version = "0.3.29", optional = true }
58+
phoenix_channels_client = { git = "https://github.com/liveview-native/phoenix-channels-client", branch = "main", optional = true }
5959

6060
[build-dependencies]
6161
Inflector = "0.11"

crates/core/liveview-native-core-jetpack/core/src/test/java/org/phoenixframework/liveview_jetpack/DocumentTest.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import kotlinx.coroutines.test.runTest;
1515
import kotlin.system.*;
1616
import java.util.Base64;
1717

18-
/*
1918
import org.phoenixframework.liveviewnative.core.LiveSocket;
2019
import org.phoenixframework.liveviewnative.core.LiveFile;
2120
class SocketTest {
@@ -32,7 +31,6 @@ class SocketTest {
3231
live_channel.uploadFile(live_file)
3332
}
3433
}
35-
*/
3634

3735
class SimpleChangeHandler: DocumentChangeHandler {
3836
constructor() {

crates/core/liveview-native-core-swift/Tests/LiveViewNativeCoreTests/LiveViewNativeCoreSocketTests.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,18 @@ import XCTest
44
import SystemConfiguration
55
#endif
66

7-
/*
87
let url = "http://127.0.0.1:4001/upload?_lvn[format]=swiftui";
98
let timeout = TimeInterval(10.0)
109

1110

1211
final class LiveViewNativeCoreSocketTests: XCTestCase {
1312
func testConnect() async throws {
14-
let live_socket = try LiveSocket(url, timeout)
13+
let live_socket = try await LiveSocket(url, timeout)
1514
let _lvn_channel = try await live_socket.joinLiveviewChannel()
1615
}
1716

1817
func testStatus() async throws {
19-
let live_socket = try LiveSocket(url, timeout)
18+
let live_socket = try await LiveSocket(url, timeout)
2019
let _lvn_channel = try await live_socket.joinLiveviewChannel()
2120
let socket = live_socket.socket()
2221

@@ -38,7 +37,7 @@ let base64TileImg = "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABmJLR0QA/wD
3837

3938
final class LiveViewNativeCoreUploadTests: XCTestCase {
4039
func testConnect() async throws {
41-
let live_socket = try LiveSocket(url, timeout)
40+
let live_socket = try await LiveSocket(url, timeout)
4241
let live_channel = try await live_socket.joinLiveviewChannel()
4342

4443
let phx_id = try live_channel.getPhxRefFromUploadJoinPayload()
@@ -48,4 +47,3 @@ final class LiveViewNativeCoreUploadTests: XCTestCase {
4847
try await live_channel.uploadFile(live_file)
4948
}
5049
}
51-
*/

crates/core/src/live_socket/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ impl LiveSocket {
395395
#[uniffi::constructor]
396396
pub fn new(url: String, timeout: Duration) -> Result<Self, LiveSocketError> {
397397
let url = url.parse::<Url>()?;
398+
//let resp = reqwest::get(url.clone()).await?;
398399
let resp = futures::executor::block_on(async_compat::Compat::new(async {
399400
reqwest::get(url.clone()).await
400401
}))?;
@@ -407,6 +408,7 @@ impl LiveSocket {
407408
let resp_text = futures::executor::block_on(async_compat::Compat::new(async {
408409
resp.text().await
409410
}))?;
411+
//let resp_text = resp.text().await?;
410412

411413
let document = parse(&resp_text)?;
412414
debug!("document: {document}\n\n\n");
@@ -484,6 +486,7 @@ impl LiveSocket {
484486
debug!("websocket url: {websocket_url}");
485487

486488
let websocket_url = websocket_url.parse::<Url>()?;
489+
//let socket = Socket::spawn(websocket_url.clone(), Some(cookies))?;
487490
let socket = futures::executor::block_on(async_compat::Compat::new(async {
488491
Socket::spawn(websocket_url.clone(), Some(cookies))
489492
}))?;

crates/core/tests/bindings/simple.kts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
import org.phoenixframework.liveviewnative.core.*;
2-
// TODO: Uncomment this when adding live-channel support.
3-
//import org.phoenixframework.liveviewnative.channel.*;
2+
import org.phoenixframework.liveviewnative.channel.*;

0 commit comments

Comments
 (0)