Skip to content

Commit f3f1f70

Browse files
oguzkocerjkmassel
andauthored
Move wp_api/cache to new wp_mobile_cache crate (#963)
* Move wp_api/cache to new wp_mobile_cache crate * Fix Swift Bindings --------- Co-authored-by: Jeremy Massel <1123407+jkmassel@users.noreply.github.com>
1 parent 9cb1d3b commit f3f1f70

File tree

18 files changed

+72
-30
lines changed

18 files changed

+72
-30
lines changed

Cargo.lock

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ members = [
1313
"wp_localization_parser",
1414
"wp_localization_validation",
1515
"wp_mobile",
16+
"wp_mobile_cache",
1617
"wp_rs_cli",
1718
"wp_rs_web",
1819
"wp_serde_helper",

Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ _build-apple-%-tvos _build-apple-%-tvos-sim _build-apple-%-watchos _build-apple-
102102

103103
# Build the library for a specific target
104104
_build-apple-%:
105-
cargo $(CARGO_OPTS) $(cargo_config_library) build --target $* --features export-uncancellable-endpoints --package wp_api --profile $(CARGO_PROFILE) --no-default-features
106-
./scripts/swift-bindings.sh target/$*/$(CARGO_PROFILE_DIRNAME)/libwp_api.a
105+
cargo $(CARGO_OPTS) $(cargo_config_library) build --target $* --features export-uncancellable-endpoints --package wp_mobile --profile $(CARGO_PROFILE) --no-default-features
106+
./scripts/swift-bindings.sh target/$*/$(CARGO_PROFILE_DIRNAME)/libwp_mobile.a
107107

108108
# Build the library for one single platform, including real device and simulator.
109109
build-apple-platform-macos := $(addprefix _build-apple-,$(apple-platform-targets-macos))
@@ -141,11 +141,11 @@ docker-image-web:
141141
docker build -t wordpress-rs-web -f wp_rs_web/Dockerfile . --progress=plain
142142

143143
swift-linux-library:
144-
cargo build --release --features export-uncancellable-endpoints --package wp_api
145-
./scripts/swift-bindings.sh target/release/libwp_api.a
144+
cargo build --release --features export-uncancellable-endpoints --package wp_mobile
145+
./scripts/swift-bindings.sh target/release/libwp_mobile.a
146146
mkdir -p target/release/libwordpressFFI-linux
147147
cp target/release/swift-bindings/Headers/* target/release/libwordpressFFI-linux/
148-
cp target/release/libwp_api.a target/release/libwordpressFFI-linux/
148+
cp target/release/libwp_mobile.a target/release/libwordpressFFI-linux/
149149

150150
swift-example-app: swift-example-app-mac swift-example-app-ios
151151

@@ -163,7 +163,7 @@ test-swift-linux:
163163
docker compose run --rm swift make test-swift-linux-in-docker
164164

165165
test-swift-linux-in-docker: swift-linux-library
166-
swift test -Xlinker -Ltarget/release/libwordpressFFI-linux -Xlinker -lwp_api
166+
swift test -Xlinker -Ltarget/release/libwordpressFFI-linux -Xlinker -lwp_mobile
167167

168168
test-swift-darwin: xcframework
169169
swift test

native/kotlin/api/kotlin/src/main/kotlin/rs/wordpress/cache/kotlin/WordPressApiCache.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ package rs.wordpress.cache.kotlin
22

33
import kotlinx.coroutines.asCoroutineDispatcher
44
import kotlinx.coroutines.withContext
5-
import uniffi.wp_api.DatabaseDelegate
6-
import uniffi.wp_api.UpdateHook
7-
import uniffi.wp_api.WpApiCache
5+
import uniffi.wp_mobile_cache.DatabaseDelegate
6+
import uniffi.wp_mobile_cache.UpdateHook
7+
import uniffi.wp_mobile_cache.WpApiCache
88
import java.nio.file.Path
99
import java.util.concurrent.Executors
1010

@@ -13,6 +13,7 @@ class WordPressApiCacheLoggingDelegate : DatabaseDelegate {
1313
println("Received update: $updateHook")
1414
}
1515
}
16+
1617
class WordPressApiCacheDelegate(
1718
private val callback: (updateHook: UpdateHook) -> Unit
1819
) : DatabaseDelegate {
@@ -31,7 +32,10 @@ class WordPressApiCache {
3132
constructor(delegate: WordPressApiCacheDelegate? = null) : this(":memory:", delegate)
3233

3334
// Creates a new cache at the specified file system URL
34-
constructor(path: Path, delegate: WordPressApiCacheDelegate? = null) : this(path.toString(), delegate)
35+
constructor(path: Path, delegate: WordPressApiCacheDelegate? = null) : this(
36+
path.toString(),
37+
delegate
38+
)
3539

3640
// Creates a new cache at the specified path
3741
constructor(string: String, delegate: WordPressApiCacheDelegate? = null) {
@@ -42,6 +46,7 @@ class WordPressApiCache {
4246
suspend fun performMigrations(): Int = withContext(internalDispatcher) {
4347
cache.performMigrations().toInt()
4448
}
49+
4550
fun startListeningForUpdates() {
4651
if (this.delegate != null) {
4752
this.cache.startListeningForUpdates(this.delegate)

native/kotlin/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ allprojects {
3333
exclude("**/wp_api.kt")
3434
exclude("**/wp_localization.kt")
3535
exclude("**/wp_mobile.kt")
36+
exclude("**/wp_mobile_cache.kt")
3637
}
3738

3839
tasks.withType<io.gitlab.arturbosch.detekt.DetektCreateBaselineTask>().configureEach {
@@ -42,6 +43,7 @@ allprojects {
4243
exclude("**/wp_api.kt")
4344
exclude("**/wp_localization.kt")
4445
exclude("**/wp_mobile.kt")
46+
exclude("**/wp_mobile_cache.kt")
4547
}
4648

4749
dependencies {

native/swift/Tests/integration-tests/CancellationTests.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ struct CancellationTests {
1919
throws: WpApiError.RequestExecutionFailed(statusCode: nil, redirects: nil, reason: .cancellationError),
2020
performing: {
2121
let task = Task {
22-
_ = try await api.posts.create(params: .init(title: title, content: content, meta: nil))
22+
let params = PostCreateParams(
23+
title: title,
24+
content: content,
25+
meta: nil
26+
)
27+
_ = try await api.posts.create(postEndpointType: .posts, params: params)
2328
Issue.record("The creating post function should throw")
2429
}
2530

native/swift/Tests/wordpress-api/Support/Extensions.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,6 @@ extension PaginatableResponse {
1919
}
2020
}
2121

22-
// These `Sendable` conformances are **NOT** safe – they're for the test suite only.
23-
//
24-
// Until or unless `WpNetworkRequest` and `WpNetworkRequest` become `uniffi::Record` (thus Structs)
25-
// we can't guarantee that they're thread-safe
26-
27-
extension WpNetworkRequest: @unchecked Sendable {}
28-
extension WpNetworkResponse: @unchecked Sendable {}
29-
3022
// This is only for testing – it's not production-ready
3123
// extension WordPressLoginClientError: Equatable {
3224
// public static func == (lhs: WordPressLoginClientError, rhs: WordPressLoginClientError) -> Bool {

wp_api/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ version = "0.1.0"
44
edition = "2024"
55

66
[features]
7-
default = ["rusqlite/bundled"]
87
export-uncancellable-endpoints = ["wp_derive_request_builder/export-uncancellable-endpoints"]
98
integration-tests = []
109
reqwest-request-executor = ["dep:reqwest", "dep:tokio", "dep:hyper-util", "dep:rustls", "dep:hickory-resolver", "dep:hyper", "dep:h2"]
@@ -49,7 +48,6 @@ wp_localization = { path = "../wp_localization" }
4948
wp_localization_macro = { path = "../wp_localization_macro" }
5049
wp_serde_helper = { path = "../wp_serde_helper" }
5150
x509-cert = { workspace = true }
52-
rusqlite = { version = "0.37.0", features = ["hooks"] }
5351

5452
[dev-dependencies]
5553
rstest = { workspace = true }

wp_api/src/cache/mod.rs

Lines changed: 0 additions & 1 deletion
This file was deleted.

wp_api/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use users::*;
66
use wp_localization::{MessageBundle, WpMessages, WpSupportsLocalization};
77
use wp_localization_macro::WpDeriveLocalizable;
88

9-
pub mod cache;
109
pub mod jetpack;
1110
pub mod wp_com;
1211

0 commit comments

Comments
 (0)