diff --git a/.gitignore b/.gitignore index 6b39d31..a4f0713 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ /target -.idea/ \ No newline at end of file +.idea/ +.DS_Store +generated/ \ No newline at end of file diff --git a/Android/app/build.gradle.kts b/Android/app/build.gradle.kts index e50857e..db56e7e 100644 --- a/Android/app/build.gradle.kts +++ b/Android/app/build.gradle.kts @@ -52,6 +52,7 @@ android { dependencies { // our shared library implementation(project(path = ":shared")) + implementation("net.java.dev.jna:jna:5.14.0@aar") val composeBom = platform("androidx.compose:compose-bom:2024.06.00") diff --git a/Android/app/src/main/java/com/example/simple_counter/Core.kt b/Android/app/src/main/java/com/example/simple_counter/Core.kt index 3c15cd1..1f10cf7 100644 --- a/Android/app/src/main/java/com/example/simple_counter/Core.kt +++ b/Android/app/src/main/java/com/example/simple_counter/Core.kt @@ -3,32 +3,3 @@ package com.example.simple_counter import androidx.compose.runtime.getValue import androidx.compose.runtime.setValue import androidx.compose.runtime.mutableStateOf -import com.example.simple_counter.shared.processEvent -import com.example.simple_counter.shared.view -import com.example.simple_counter.shared_types.Effect -import com.example.simple_counter.shared_types.Event -import com.example.simple_counter.shared_types.Request -import com.example.simple_counter.shared_types.Requests -import com.example.simple_counter.shared_types.ViewModel - -class Core : androidx.lifecycle.ViewModel() { - var view: ViewModel? by mutableStateOf(null) - private set - - fun update(event: Event) { - val effects = processEvent(event.bincodeSerialize()) - - val requests = Requests.bincodeDeserialize(effects) - for (request in requests) { - processEffect(request) - } - } - - private fun processEffect(request: Request) { - when (request.effect) { - is Effect.Render -> { - this.view = ViewModel.bincodeDeserialize(view()) - } - } - } -} \ No newline at end of file diff --git a/Android/app/src/main/java/com/example/simple_counter/MainActivity.kt b/Android/app/src/main/java/com/example/simple_counter/MainActivity.kt index bfb3759..8eb83cb 100644 --- a/Android/app/src/main/java/com/example/simple_counter/MainActivity.kt +++ b/Android/app/src/main/java/com/example/simple_counter/MainActivity.kt @@ -16,14 +16,19 @@ import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Surface import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.setValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color +import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.lifecycle.viewmodel.compose.viewModel -import com.example.simple_counter.shared_types.Event import com.example.simple_counter.ui.theme.CounterTheme +import com.example.simple_counter.shared.increment class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { @@ -41,7 +46,12 @@ class MainActivity : ComponentActivity() { } @Composable -fun View(core: Core = viewModel()) { +fun View() { + val path = LocalContext.current.filesDir.path + var state by remember { + mutableStateOf("none") + } + Column( horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center, @@ -49,23 +59,15 @@ fun View(core: Core = viewModel()) { .fillMaxSize() .padding(10.dp), ) { - Text(text = (core.view?.count ?: "0").toString(), modifier = Modifier.padding(10.dp)) + Text(text = state, modifier = Modifier.padding(10.dp)) Row(horizontalArrangement = Arrangement.spacedBy(10.dp)) { - Button( - onClick = { core.update(Event.Reset()) }, colors = ButtonDefaults.buttonColors( - containerColor = MaterialTheme.colorScheme.error - ) - ) { Text(text = "Reset", color = Color.White) } - Button( - onClick = { core.update(Event.Increment()) }, colors = ButtonDefaults.buttonColors( - containerColor = MaterialTheme.colorScheme.primary - ) - ) { Text(text = "Increment", color = Color.White) } - Button( - onClick = { core.update(Event.Decrement()) }, colors = ButtonDefaults.buttonColors( - containerColor = MaterialTheme.colorScheme.secondary - ) - ) { Text(text = "Decrement", color = Color.White) } + + Button(onClick = { + val increment = increment() + state += "Increment $increment" + }) { + Text("Open database", color = Color.White) + } } } } diff --git a/Android/shared/build.gradle.kts b/Android/shared/build.gradle.kts index 947325d..45f4e87 100644 --- a/Android/shared/build.gradle.kts +++ b/Android/shared/build.gradle.kts @@ -10,7 +10,7 @@ android { namespace = "com.example.simple_counter.shared" compileSdk = 34 - ndkVersion = "27.0.11902837" + ndkVersion = "26.3.11579264" defaultConfig { minSdk = 33 @@ -40,7 +40,7 @@ android { sourceSets { // main.java.srcDirs += "${projectDir}/../../shared_types/generated/java" named("main") { - java.srcDirs("${projectDir}/../../shared_types/generated/java") + java.srcDirs("${projectDir}/../../shared/generated/java") } } } @@ -85,7 +85,7 @@ afterEvaluate { } tasks.named("compileDebugKotlin") { - dependsOn(tasks.named("typesGen"), tasks.named("bindGen")) + dependsOn(tasks.named("bindGen")) } tasks.named("generate${productFlavor}${buildType}Assets") { @@ -95,7 +95,7 @@ afterEvaluate { } tasks.register("bindGen") { - val outDir = "${projectDir}/../../shared_types/generated/java" + val outDir = "${projectDir}/../../shared/generated/java" workingDir = File("../../") if (System.getProperty("os.name").lowercase(Locale.getDefault()).contains("windows")) { commandLine( @@ -117,12 +117,3 @@ tasks.register("bindGen") { ) } } - -tasks.register("typesGen") { - workingDir = File("../../") - if (System.getProperty("os.name").lowercase(Locale.getDefault()).contains("windows")) { - commandLine("cmd", "/c", "cargo build -p shared_types") - } else { - commandLine("sh", "-c", "cargo build -p shared_types") - } -} diff --git a/Cargo.lock b/Cargo.lock index 9963bf8..f3ca7af 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -133,7 +133,7 @@ dependencies = [ "proc-macro2", "quote", "serde", - "syn 2.0.68", + "syn", ] [[package]] @@ -170,7 +170,7 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn", ] [[package]] @@ -181,7 +181,7 @@ checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn", ] [[package]] @@ -299,7 +299,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.68", + "syn", "which", ] @@ -450,10 +450,10 @@ version = "4.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c780290ccf4fb26629baa7a1081e68ced113f1d3ec302fa5948f1c381ebf06c6" dependencies = [ - "heck 0.5.0", + "heck", "proc-macro2", "quote", - "syn 2.0.68", + "syn", ] [[package]] @@ -493,54 +493,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crossbeam-channel" -version = "0.5.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33480d6946193aa8033910124896ca395333cae7e2d1113d1fef6c3272217df2" -dependencies = [ - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-utils" -version = "0.8.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" - -[[package]] -name = "crux_core" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cbc7f23786d97287a7f9221a7f255639e7eaae4a109394e0a00e71a41c544ce" -dependencies = [ - "anyhow", - "bincode", - "crossbeam-channel", - "crux_macros", - "erased-serde", - "futures", - "serde", - "serde-generate", - "serde-reflection", - "serde_json", - "slab", - "thiserror", -] - -[[package]] -name = "crux_macros" -version = "0.3.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da01ee88d58247be654239d54d58131c3bc2789a447a601ec2faf3dddacd49c4" -dependencies = [ - "darling", - "proc-macro-error", - "proc-macro2", - "quote", - "syn 2.0.68", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -551,41 +503,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "darling" -version = "0.20.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83b2eb4d90d12bdda5ed17de686c2acb4c57914f8f921b8da7e112b5a36f3fe1" -dependencies = [ - "darling_core", - "darling_macro", -] - -[[package]] -name = "darling_core" -version = "0.20.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "622687fe0bac72a04e5599029151f5796111b90f1baaa9b544d807a5e31cd120" -dependencies = [ - "fnv", - "ident_case", - "proc-macro2", - "quote", - "strsim", - "syn 2.0.68", -] - -[[package]] -name = "darling_macro" -version = "0.20.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "733cabb43482b1a1b53eee8583c2b9e8684d592215ea83efd305dd31bc2f0178" -dependencies = [ - "darling_core", - "quote", - "syn 2.0.68", -] - [[package]] name = "either" version = "1.13.0" @@ -598,16 +515,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" -[[package]] -name = "erased-serde" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24e2389d65ab4fab27dc2a5de7b191e1f6617d1f1c8855c0dc569c94a4cbb18d" -dependencies = [ - "serde", - "typeid", -] - [[package]] name = "errno" version = "0.3.9" @@ -707,7 +614,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn", ] [[package]] @@ -828,15 +735,6 @@ dependencies = [ "hashbrown 0.14.5", ] -[[package]] -name = "heck" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" -dependencies = [ - "unicode-segmentation", -] - [[package]] name = "heck" version = "0.5.0" @@ -952,36 +850,6 @@ dependencies = [ "tokio-io-timeout", ] -[[package]] -name = "ident_case" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" - -[[package]] -name = "include_dir" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24b56e147e6187d61e9d0f039f10e070d0c0a887e24fe0bb9ca3f29bfde62cab" -dependencies = [ - "glob", - "include_dir_impl", - "proc-macro-hack", -] - -[[package]] -name = "include_dir_impl" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a0c890c85da4bab7bce4204c707396bbd3c6c8a681716a51c8814cfc2b682df" -dependencies = [ - "anyhow", - "proc-macro-hack", - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "indexmap" version = "1.9.3" @@ -1147,9 +1015,9 @@ dependencies = [ "indexmap 2.2.6", "log", "memchr", - "phf 0.11.2", + "phf", "phf_codegen", - "phf_shared 0.11.2", + "phf_shared", "smallvec", "uncased", ] @@ -1352,24 +1220,13 @@ version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" -[[package]] -name = "phf" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" -dependencies = [ - "phf_macros", - "phf_shared 0.10.0", - "proc-macro-hack", -] - [[package]] name = "phf" version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" dependencies = [ - "phf_shared 0.11.2", + "phf_shared", ] [[package]] @@ -1378,18 +1235,8 @@ version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" dependencies = [ - "phf_generator 0.11.2", - "phf_shared 0.11.2", -] - -[[package]] -name = "phf_generator" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" -dependencies = [ - "phf_shared 0.10.0", - "rand", + "phf_generator", + "phf_shared", ] [[package]] @@ -1398,33 +1245,10 @@ version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" dependencies = [ - "phf_shared 0.11.2", + "phf_shared", "rand", ] -[[package]] -name = "phf_macros" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58fdf3184dd560f160dd73922bea2d5cd6e8f064bf4b13110abd81b03697b4e0" -dependencies = [ - "phf_generator 0.10.0", - "phf_shared 0.10.0", - "proc-macro-hack", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "phf_shared" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" -dependencies = [ - "siphasher", -] - [[package]] name = "phf_shared" version = "0.11.2" @@ -1452,7 +1276,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn", ] [[package]] @@ -1486,39 +1310,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f12335488a2f3b0a83b14edad48dca9879ce89b2edd10e80237e4e852dd645e" dependencies = [ "proc-macro2", - "syn 2.0.68", + "syn", ] -[[package]] -name = "proc-macro-error" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" -dependencies = [ - "proc-macro-error-attr", - "proc-macro2", - "quote", - "syn 1.0.109", - "version_check", -] - -[[package]] -name = "proc-macro-error-attr" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" -dependencies = [ - "proc-macro2", - "quote", - "version_check", -] - -[[package]] -name = "proc-macro-hack" -version = "0.5.20+deprecated" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068" - [[package]] name = "proc-macro2" version = "1.0.86" @@ -1548,7 +1342,7 @@ dependencies = [ "itertools", "proc-macro2", "quote", - "syn 2.0.68", + "syn", ] [[package]] @@ -1766,7 +1560,7 @@ checksum = "7f81c2fde025af7e69b1d1420531c8a8811ca898919db177141a85313b1cb932" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn", ] [[package]] @@ -1810,31 +1604,6 @@ dependencies = [ "serde_derive", ] -[[package]] -name = "serde-generate" -version = "0.25.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8c9331265d81c61212dc75df7b0836544ed8e32dba77a522f113805ff9a948e" -dependencies = [ - "heck 0.3.3", - "include_dir", - "phf 0.10.1", - "serde", - "serde-reflection", - "textwrap 0.13.4", -] - -[[package]] -name = "serde-reflection" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f05a5f801ac62a51a49d378fdb3884480041b99aced450b28990673e8ff99895" -dependencies = [ - "once_cell", - "serde", - "thiserror", -] - [[package]] name = "serde_derive" version = "1.0.203" @@ -1843,7 +1612,7 @@ checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn", ] [[package]] @@ -1861,21 +1630,10 @@ dependencies = [ name = "shared" version = "0.1.0" dependencies = [ - "crux_core", "libsql", - "serde", "uniffi", ] -[[package]] -name = "shared_types" -version = "0.1.0" -dependencies = [ - "anyhow", - "crux_core", - "shared", -] - [[package]] name = "shlex" version = "1.3.0" @@ -1952,17 +1710,6 @@ version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - [[package]] name = "syn" version = "2.0.68" @@ -1980,16 +1727,6 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" -[[package]] -name = "textwrap" -version = "0.13.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd05616119e612a8041ef58f2b578906cc2531a6069047ae092cfb86a325d835" -dependencies = [ - "smawk", - "unicode-width", -] - [[package]] name = "textwrap" version = "0.16.1" @@ -2016,7 +1753,7 @@ checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn", ] [[package]] @@ -2056,7 +1793,7 @@ checksum = "5f5ae998a069d4b5aba8ee9dad856af7d520c3699e6159b185c2acd48155d39a" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn", ] [[package]] @@ -2227,7 +1964,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn", ] [[package]] @@ -2245,12 +1982,6 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" -[[package]] -name = "typeid" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "059d83cc991e7a42fc37bd50941885db0888e34209f8cfd9aab07ddec03bc9cf" - [[package]] name = "typenum" version = "1.17.0" @@ -2281,18 +2012,6 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" -[[package]] -name = "unicode-segmentation" -version = "1.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" - -[[package]] -name = "unicode-width" -version = "0.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" - [[package]] name = "uniffi" version = "0.28.0" @@ -2321,11 +2040,11 @@ dependencies = [ "fs-err", "glob", "goblin", - "heck 0.5.0", + "heck", "once_cell", "paste", "serde", - "textwrap 0.16.1", + "textwrap", "toml", "uniffi_meta", "uniffi_testing", @@ -2350,7 +2069,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2fcfa22f55829d3aaa7acfb1c5150224188fe0f27c59a8a3eddcaa24d1ffbe58" dependencies = [ "quote", - "syn 2.0.68", + "syn", ] [[package]] @@ -2381,7 +2100,7 @@ dependencies = [ "proc-macro2", "quote", "serde", - "syn 2.0.68", + "syn", "toml", "uniffi_meta", ] @@ -2418,7 +2137,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cef408229a3a407fafa4c36dc4f6ece78a6fb258ab28d2b64bddd49c8cb680f6" dependencies = [ "anyhow", - "textwrap 0.16.1", + "textwrap", "uniffi_meta", "uniffi_testing", "weedle2", @@ -2654,7 +2373,7 @@ checksum = "15e934569e47891f7d9411f1a451d947a60e000ab3bd24fbb970f000387d1b3b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index eb1c1a0..8cf27a9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -members = ["shared", "shared_types"] +members = ["shared" ] resolver = "1" [workspace.package] @@ -11,10 +11,6 @@ keywords = ["crux", "crux_core", "cross-platform-ui", "ffi", "wasm"] rust-version = "1.66" [workspace.dependencies] -anyhow = "1.0.86" -crux_core = "0.8" -# crux_core = { path = "../../crux_core" } -serde = "1.0.203" [workspace.metadata.bin] cargo-xcode = { version = "=1.7.0" } diff --git a/Crux.toml b/Crux.toml deleted file mode 100644 index d2f504a..0000000 --- a/Crux.toml +++ /dev/null @@ -1,44 +0,0 @@ -name = "Simple Counter" -description = "A _very_ simple counter core, which is wrapped with multiple shells" -authors = ["Red Badger Consulting Limited"] -repository = "https://github.com/redbadger/crux/" - -[cores.shared] -source = "shared" -type_gen = "shared_types" -crux_version = "0.6.3" - -[shells.android] -template = "Android" -source = "Android" -cores = ["shared"] - -[shells.iOS] -template = "iOS" -source = "iOS" -cores = ["shared"] - -[shells.web_dioxus] -template = "web-dioxus" -source = "web-dioxus" -cores = ["shared"] - -[shells.web_leptos] -template = "web-leptos" -source = "web-leptos" -cores = ["shared"] - -[shells.web_nextjs] -template = "web-nextjs" -source = "web-nextjs" -cores = ["shared"] - -[shells.web_remix] -template = "web-remix" -source = "web-remix" -cores = ["shared"] - -[shells.web_yew] -template = "web-yew" -source = "web-yew" -cores = ["shared"] diff --git a/shared/Cargo.toml b/shared/Cargo.toml index 361a315..7e417d1 100644 --- a/shared/Cargo.toml +++ b/shared/Cargo.toml @@ -8,14 +8,9 @@ rust-version = "1.66" crate-type = ["lib", "staticlib", "cdylib"] name = "shared" -[features] -typegen = ["crux_core/typegen"] - [dependencies] -crux_core.workspace = true -serde = { workspace = true, features = ["derive"] } uniffi = "0.28.0" -libsql = { version = "0.4.0", features = ["encryption"] } +libsql = { version = "0.4", features = ["encryption"] } [target.uniffi-bindgen.dependencies] uniffi = { version = "0.28.0", features = ["cli"] } diff --git a/shared/src/app.rs b/shared/src/app.rs index 1064e9f..e69de29 100644 --- a/shared/src/app.rs +++ b/shared/src/app.rs @@ -1,143 +0,0 @@ -// ANCHOR: app -use crux_core::{render::Render, App}; -use serde::{Deserialize, Serialize}; - -#[derive(Serialize, Deserialize, Clone, Debug)] -pub enum Event { - Increment, - Decrement, - Reset, -} - -#[derive(Default)] -pub struct Model { - count: isize, -} - -#[derive(Serialize, Deserialize, Clone, Default)] -pub struct ViewModel { - pub count: String, -} - -#[cfg_attr(feature = "typegen", derive(crux_core::macros::Export))] -#[derive(crux_core::macros::Effect)] -pub struct Capabilities { - render: Render, -} - -#[derive(Default)] -pub struct Counter; - -// ANCHOR: impl_app -impl App for Counter { - type Event = Event; - type Model = Model; - type ViewModel = ViewModel; - type Capabilities = Capabilities; - - fn update(&self, event: Self::Event, model: &mut Self::Model, caps: &Self::Capabilities) { - match event { - Event::Increment => model.count += 2, - Event::Decrement => model.count -= 1, - Event::Reset => model.count = 0, - }; - - caps.render.render(); - } - - fn view(&self, model: &Self::Model) -> Self::ViewModel { - ViewModel { - count: format!("Count is: {}", model.count), - } - } -} -// ANCHOR_END: impl_app -// ANCHOR_END: app - -// ANCHOR: test -#[cfg(test)] -mod test { - use super::*; - use crux_core::{assert_effect, testing::AppTester}; - - #[test] - fn renders() { - let app = AppTester::::default(); - let mut model = Model::default(); - - let update = app.update(Event::Reset, &mut model); - - // Check update asked us to `Render` - assert_effect!(update, Effect::Render(_)); - } - - #[test] - fn shows_initial_count() { - let app = AppTester::::default(); - let model = Model::default(); - - let actual_view = app.view(&model).count; - let expected_view = "Count is: 0"; - assert_eq!(actual_view, expected_view); - } - - #[test] - fn increments_count() { - let app = AppTester::::default(); - let mut model = Model::default(); - - let update = app.update(Event::Increment, &mut model); - - let actual_view = app.view(&model).count; - let expected_view = "Count is: 1"; - assert_eq!(actual_view, expected_view); - - // Check update asked us to `Render` - assert_effect!(update, Effect::Render(_)); - } - - #[test] - fn decrements_count() { - let app = AppTester::::default(); - let mut model = Model::default(); - - let update = app.update(Event::Decrement, &mut model); - - let actual_view = app.view(&model).count; - let expected_view = "Count is: -1"; - assert_eq!(actual_view, expected_view); - - // Check update asked us to `Render` - assert_effect!(update, Effect::Render(_)); - } - - #[test] - fn resets_count() { - let app = AppTester::::default(); - let mut model = Model::default(); - - app.update(Event::Increment, &mut model); - app.update(Event::Reset, &mut model); - - let actual_view = app.view(&model).count; - let expected_view = "Count is: 0"; - assert_eq!(actual_view, expected_view); - } - - #[test] - fn counts_up_and_down() { - let app = AppTester::::default(); - let mut model = Model::default(); - - app.update(Event::Increment, &mut model); - app.update(Event::Reset, &mut model); - app.update(Event::Decrement, &mut model); - app.update(Event::Increment, &mut model); - app.update(Event::Increment, &mut model); - - let actual_view = app.view(&model).count; - let expected_view = "Count is: 1"; - assert_eq!(actual_view, expected_view); - } -} -// ANCHOR_END: test diff --git a/shared/src/database.rs b/shared/src/database.rs index 5e8dc3f..e69de29 100644 --- a/shared/src/database.rs +++ b/shared/src/database.rs @@ -1,34 +0,0 @@ -use crux_core::capability::{CapabilityContext, Operation}; -use crux_core::macros::Capability; -use serde::{Deserialize, Serialize}; - -// use crux_core::capability::OP -#[derive(Serialize, Deserialize, PartialEq)] -pub struct GetUserOperation; - -// impl Operation -impl Operation for GetUserOperation { - type Output = String; -} - -#[derive(Capability)] -pub struct Database { - context: CapabilityContext, -} - -impl Database { - pub fn new(context: CapabilityContext) -> Self { - Self { context } - } - - pub fn get_user(&self) -> String { - - // let context = self.context.clone(); - // self.context.spawn(async move { - // // context.request_from_shell(GetUserOperation).await; - // - // }); - // - todo!() - } -} \ No newline at end of file diff --git a/shared/src/lib.rs b/shared/src/lib.rs index a0b3e29..6f07f76 100644 --- a/shared/src/lib.rs +++ b/shared/src/lib.rs @@ -3,26 +3,20 @@ pub mod database; use std::sync::OnceLock; -pub use crux_core::{bridge::Bridge, Core, Request}; - pub use app::*; uniffi::include_scaffolding!("shared"); -fn core() -> &'static Bridge { - static CORE: OnceLock> = OnceLock::new(); - CORE.get_or_init(|| Bridge::new(Core::new())) -} - -pub fn process_event(data: &[u8]) -> Vec { - core().process_event(data) +struct Counter { + count: isize, } -pub fn handle_response(id: u32, data: &[u8]) -> Vec { - core().handle_response(id, data) +fn core() -> &'static Counter { + static CORE: OnceLock = OnceLock::new(); + CORE.get_or_init(|| Counter { count: 0 }) } -pub fn view() -> Vec { - core().view() -} +fn increment() -> i32 { + 3 +} \ No newline at end of file diff --git a/shared/src/shared.udl b/shared/src/shared.udl index db53521..d60621f 100644 --- a/shared/src/shared.udl +++ b/shared/src/shared.udl @@ -1,5 +1,4 @@ namespace shared { - bytes process_event([ByRef] bytes msg); - bytes handle_response(u32 id, [ByRef] bytes res); - bytes view(); + + i32 increment(); }; diff --git a/shared_types/.gitignore b/shared_types/.gitignore deleted file mode 100644 index e324eac..0000000 --- a/shared_types/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/generated diff --git a/shared_types/Cargo.toml b/shared_types/Cargo.toml deleted file mode 100644 index f878f9b..0000000 --- a/shared_types/Cargo.toml +++ /dev/null @@ -1,16 +0,0 @@ -[package] -name = "shared_types" -version = "0.1.0" -authors.workspace = true -repository.workspace = true -edition.workspace = true -license.workspace = true -keywords.workspace = true -rust-version.workspace = true - -[dependencies] - -[build-dependencies] -anyhow.workspace = true -crux_core = { workspace = true, features = ["typegen"] } -shared = { path = "../shared", features = ["typegen"] } diff --git a/shared_types/build.rs b/shared_types/build.rs deleted file mode 100644 index c3187c1..0000000 --- a/shared_types/build.rs +++ /dev/null @@ -1,24 +0,0 @@ -use crux_core::typegen::TypeGen; -use shared::Counter; -use std::path::PathBuf; - -fn main() -> anyhow::Result<()> { - println!("cargo:rerun-if-changed=../shared"); - - let mut gen = TypeGen::new(); - - gen.register_app::()?; - - let output_root = PathBuf::from("./generated"); - - gen.swift("SharedTypes", output_root.join("swift"))?; - - gen.java( - "com.example.simple_counter.shared_types", - output_root.join("java"), - )?; - - gen.typescript("shared_types", output_root.join("typescript"))?; - - Ok(()) -} diff --git a/shared_types/src/lib.rs b/shared_types/src/lib.rs deleted file mode 100644 index cd215e1..0000000 --- a/shared_types/src/lib.rs +++ /dev/null @@ -1 +0,0 @@ -// see build.rs