Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: CI

# Builds and tests the published libraries and the sample on every pull request and on
# main. The Linux job covers the JVM and Android targets (including apiCheck); the macOS
# job runs the iOS simulator tests of the two libraries.
on:
pull_request:
push:
branches: [main]
workflow_dispatch:

permissions:
contents: read

concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true

jobs:
jvm-android:
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 21
- uses: gradle/actions/setup-gradle@v4
- name: Validate Gradle wrapper
uses: gradle/actions/wrapper-validation@v4
- name: Libraries (tests, apiCheck, Android lint)
run: ./gradlew :crdt:check :sync:check
- name: Sample (JVM tests)
run: ./gradlew :shared:jvmTest :server:test
- name: Sample app compiles (desktop and Android)
run: ./gradlew :composeApp:jvmJar :composeApp:assembleDebug

ios:
runs-on: macos-latest
timeout-minutes: 45
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 21
- uses: gradle/actions/setup-gradle@v4
- name: Library iOS simulator tests
run: ./gradlew :crdt:iosSimulatorArm64Test :sync:iosSimulatorArm64Test
4 changes: 3 additions & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ jobs:
build:
# macOS so that Dokka can analyse the iOS source sets.
runs-on: macos-latest
timeout-minutes: 45
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
# :composeApp requires a JDK 21 toolchain at configuration time.
java-version: 21
- uses: gradle/actions/setup-gradle@v4
- run: ./gradlew dokkaGenerate
- uses: actions/upload-pages-artifact@v3
Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Publish

# Publishes :crdt and :sync to Maven Central (Central Portal) when a v* tag is pushed.
# The tag gives the version: v0.1.0 publishes 0.1.0.
#
# Required repository secrets:
# MAVEN_CENTRAL_USERNAME / MAVEN_CENTRAL_PASSWORD Central Portal user token
# SIGNING_KEY ASCII-armored GPG private key
# SIGNING_KEY_PASSWORD its passphrase
on:
push:
tags: ["v*"]
workflow_dispatch:

permissions:
contents: read

jobs:
publish:
# macOS so that the iOS klibs are built and published too.
runs-on: macos-latest
timeout-minutes: 60
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 21
- uses: gradle/actions/setup-gradle@v4
- name: Version from tag
if: startsWith(github.ref, 'refs/tags/v')
run: echo "VERSION_NAME=${GITHUB_REF_NAME#v}" >> "$GITHUB_ENV"
- name: Publish to Maven Central
env:
ORG_GRADLE_PROJECT_VERSION_NAME: ${{ env.VERSION_NAME }}
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_KEY }}
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_KEY_PASSWORD }}
run: ./gradlew :crdt:publishToMavenCentral :sync:publishToMavenCentral --no-configuration-cache
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,11 @@ captures
!*.xcworkspace/contents.xcworkspacedata
**/xcshareddata/WorkspaceSettings.xcsettings

server/src/main/resources/audio
# Runtime state written by the sample server (JsonFileStorage, default ./data)
data/
server/data/

# Per-user Claude Code files
.claude/settings.local.json
.claude/worktrees/

7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ public API may evolve; breaking changes are called out below.
`api` dependency.

### Fixed
- `:sync` no longer compiles with `-Xexplicit-backing-fields`, which flagged every
class of the published artifact as built by a pre-release Kotlin compiler and
forced consumers to pass `-Xskip-prerelease-check`.
- Both libraries now pin the JVM bytecode level of their `-jvm` artifact to
Java 11 (previously inherited from the JDK running Gradle), enable Kotlin's
explicit API mode, and are configured for Maven Central (Central Portal,
signed publications).
- The server no longer sends the full state after every push: an up-to-date
client now gets no catch-up message.
- A client further behind than the server's delta log now receives the full
Expand Down
6 changes: 3 additions & 3 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ domain-agnostic. Todo-specific concepts belong in `:shared`.
- `SyncMessage<D>` - sealed: `PushDelta`, `PullRequest`, `PullResponse`. Serialize
with `SyncMessage.serializer(deltaSerializer)`.
- `SyncEngine<D : ClockedState<D>>` - client WebSocket engine. Constructor takes a
`KSerializer<D>`, four suspending callbacks (`onRemoteDelta`,
`getPendingDelta`, `restorePendingDelta`, `getLocalClock`), and an optional
`KSerializer<D>`, four callbacks (`onRemoteDelta`, `getPendingDelta` and
`restorePendingDelta` are suspending, `getLocalClock` is not), and an optional
`SyncLogger` (defaults to `Noop`). `stop()` is suspending and joins the
connect loop before returning. Exponential backoff reconnect.
- `SyncLogger` - `fun interface` sink for diagnostics. Replaces all internal
Expand Down Expand Up @@ -98,5 +98,5 @@ domain-agnostic. Todo-specific concepts belong in `:shared`.

## `design.pen`

Pencil design file at the repo root. Read only via the Pencil MCP tools, not
Pencil design file at `design/design.pen`. Read only via the Pencil MCP tools, not
standard file tools.
5 changes: 4 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ To run the demo end-to-end locally:

- One logical change per PR.
- Run `./gradlew check` before opening - it covers tests and `apiCheck` for the
published libraries.
published libraries. CI (`.github/workflows/ci.yml`) runs the same on every
pull request, plus the iOS simulator tests of both libraries on macOS.
- `:crdt` and `:sync` compile in Kotlin's explicit API mode: every public
declaration needs a `public` modifier and an explicit return type.
- If your change touches `:crdt` or `:sync` public surface, mention it in the
PR description and include the `apiDump` diff.

Expand Down
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ Architecture deep-dive: [docs/crdt-implementation.md](docs/crdt-implementation.m

## Using the libraries

The libraries are not on Maven Central yet. Until the first release, publish them
locally with `./gradlew :crdt:publishToMavenLocal :sync:publishToMavenLocal` and
consume them from `mavenLocal()`:

```kotlin
// settings.gradle.kts
dependencyResolutionManagement {
Expand All @@ -65,8 +69,9 @@ Quickstarts: [`:crdt` README](crdt/README.md) (build a CRDT aggregate),

## Running the sample app

Prereqs: JDK 11+, Android Studio / IntelliJ with KMP plugin, two devices or
emulators for the sync demo.
Prereqs: JDK 17+ to run Gradle (the desktop app asks for a JDK 21 toolchain,
provisioned automatically), Android Studio / IntelliJ with KMP plugin, two devices
or emulators for the sync demo.

```shell
./gradlew :server:run # Port 8080
Expand All @@ -78,7 +83,9 @@ emulators for the sync demo.
Server config (env vars):

- `SYNCDO_PORT` - bind port (default `8080`).
- `SYNCDO_STATE_DIR` - directory for the persisted JSON state (default `./data`).
- `SYNCDO_STATE_DIR` - directory for the persisted JSON state (default `./data`,
relative to the working directory, so `server/data/` under `./gradlew :server:run`;
not tracked in version control).

On first launch each client asks for the server host. Enter:

Expand Down
4 changes: 0 additions & 4 deletions composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ plugins {
}

kotlin {
compilerOptions {
freeCompilerArgs.add("-Xexplicit-backing-fields")
}

androidTarget {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_11)
Expand Down
2 changes: 1 addition & 1 deletion composeApp/src/jvmMain/kotlin/com/doppio/syncdo/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fun main() {
runBlocking { AppModule.shutdown() }
exitApplication()
},
title = "SyncDO — $instanceName",
title = "SyncDO - $instanceName",
state = WindowState(
width = 412.dp,
height = 942.dp,
Expand Down
2 changes: 1 addition & 1 deletion crdt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ sync engine and Ktor server endpoint: add a `clock` and implement its `ClockedSt

- All types are `@Serializable` (kotlinx.serialization). JSON is the default wire
format; binary formats work too.
- `LwwRegister` uses `kotlin.time.Instant` (stdlib, Kotlin 2.1+) - no extra
- `LwwRegister` uses `kotlin.time.Instant` (stdlib, stable since Kotlin 2.2) - no extra
datetime dependency required.
- `OrSet` is the most subtle type. Each add attaches a fresh unique tag; a remove
tombstones only the tags observed at remove time. This is what gives concurrent
Expand Down
21 changes: 18 additions & 3 deletions crdt/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import com.vanniktech.maven.publish.JavadocJar
import com.vanniktech.maven.publish.KotlinMultiplatform
import com.vanniktech.maven.publish.SonatypeHost
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

plugins {
Expand All @@ -12,6 +13,9 @@ plugins {
}

kotlin {
// Published library: every public declaration must say so, and must have an explicit type.
explicitApi()

androidTarget {
publishLibraryVariants("release")
compilerOptions {
Expand All @@ -22,9 +26,13 @@ kotlin {
iosArm64()
iosSimulatorArm64()

jvm()

applyDefaultHierarchyTemplate()
jvm {
// Pin the bytecode level of the published -jvm artifact instead of inheriting it
// from whichever JDK runs Gradle. Matches the Android target.
compilerOptions {
jvmTarget.set(JvmTarget.JVM_11)
}
}

sourceSets {
commonMain.dependencies {
Expand Down Expand Up @@ -64,6 +72,13 @@ dokka {
mavenPublishing {
configure(KotlinMultiplatform(javadocJar = JavadocJar.Dokka("dokkaGeneratePublicationHtml")))

// Maven Central through the Central Portal. Credentials and the signing key come from
// ORG_GRADLE_PROJECT_mavenCentralUsername / mavenCentralPassword / signingInMemoryKey /
// signingInMemoryKeyPassword (see .github/workflows/publish.yml). Signing is skipped for
// SNAPSHOT versions and for publishToMavenLocal when no key is configured.
publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL, automaticRelease = true)
signAllPublications()

pom {
name.set("SyncDO CRDT")
description.set(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ package com.doppio.syncdo.crdt
* @param T the implementing type itself (`class Foo : CrdtState<Foo>`), so that [merge]
* takes and returns the concrete type.
*/
interface CrdtState<T : CrdtState<T>> {
public interface CrdtState<T : CrdtState<T>> {

/** Combine this state with [other] and return the result. Neither operand is modified. */
fun merge(other: T): T
public fun merge(other: T): T
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ import kotlinx.serialization.Serializable
* @property nodeId the node that wrote [value], used as a tie-breaker.
*/
@Serializable
data class LwwRegister<T>(
val value: T,
val timestamp: Instant,
val nodeId: NodeId
public data class LwwRegister<T>(
public val value: T,
public val timestamp: Instant,
public val nodeId: NodeId
) : CrdtState<LwwRegister<T>> {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ package com.doppio.syncdo.crdt
* }
* ```
*/
fun <K, V : CrdtState<V>> Map<K, V>.mergeStates(other: Map<K, V>): Map<K, V> =
public fun <K, V : CrdtState<V>> Map<K, V>.mergeStates(other: Map<K, V>): Map<K, V> =
mergeValues(other) { a, b -> a.merge(b) }

/** Merge two maps of sets by taking the union at each key. */
Expand Down
26 changes: 13 additions & 13 deletions crdt/src/commonMain/kotlin/com/doppio/syncdo/crdt/OrSet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import kotlinx.serialization.Serializable
* @property counter a number that [nodeId] never uses twice.
*/
@Serializable
data class UniqueTag(
val nodeId: NodeId,
val counter: Long
public data class UniqueTag(
public val nodeId: NodeId,
public val counter: Long
)

/**
Expand Down Expand Up @@ -59,45 +59,45 @@ data class UniqueTag(
* @property tombstones the removed tags of each element that was ever removed.
*/
@Serializable
data class OrSet<E>(
val entries: Map<E, Set<UniqueTag>> = emptyMap(),
val tombstones: Map<E, Set<UniqueTag>> = emptyMap()
public data class OrSet<E>(
public val entries: Map<E, Set<UniqueTag>> = emptyMap(),
public val tombstones: Map<E, Set<UniqueTag>> = emptyMap()
) : CrdtState<OrSet<E>> {

/** True if [element] is in the set. */
fun contains(element: E): Boolean = element in entries
public fun contains(element: E): Boolean = element in entries

/** The elements currently in the set. */
fun elements(): Set<E> = entries.keys
public fun elements(): Set<E> = entries.keys

/**
* True if this set holds no tag at all, live or tombstoned. Useful to detect an empty
* delta; note that a set whose elements were all removed is not empty.
*/
fun isEmpty(): Boolean = entries.isEmpty() && tombstones.isEmpty()
public fun isEmpty(): Boolean = entries.isEmpty() && tombstones.isEmpty()

/**
* The change "add [element] with [tag]", as a delta to [merge].
*
* @param tag a tag never used before, see [UniqueTag].
*/
fun addDelta(element: E, tag: UniqueTag): OrSet<E> =
public fun addDelta(element: E, tag: UniqueTag): OrSet<E> =
OrSet(entries = mapOf(element to setOf(tag)))

/**
* The change "remove [element]", as a delta to [merge]: it tombstones every tag this
* set has observed for [element]. Empty (see [isEmpty]) if [element] is not in the set.
*/
fun removeDelta(element: E): OrSet<E> {
public fun removeDelta(element: E): OrSet<E> {
val observedTags = entries[element] ?: return OrSet()
return OrSet(tombstones = mapOf(element to observedTags))
}

/** This set with [element] added. Shorthand for `merge(addDelta(element, tag))`. */
fun add(element: E, tag: UniqueTag): OrSet<E> = merge(addDelta(element, tag))
public fun add(element: E, tag: UniqueTag): OrSet<E> = merge(addDelta(element, tag))

/** This set with [element] removed. Shorthand for `merge(removeDelta(element))`. */
fun remove(element: E): OrSet<E> = merge(removeDelta(element))
public fun remove(element: E): OrSet<E> = merge(removeDelta(element))

/** Union of both sets: union of the tombstones, union of the tags minus the tombstoned ones. */
override fun merge(other: OrSet<E>): OrSet<E> {
Expand Down
Loading
Loading