The Crux Counter example is a simple multi-platform application that calls a cloud-hosted API.
It makes HTTP requests to a shared global counter hosted at https://crux-counter.fly.dev, incrementing or decrementing the counter value.
The server also has an endpoint for Server Sent Events (https://crux-counter.fly.dev/sse), which signals when changes are made to the global counter value — so that when you update the counter in one client, all the other clients will update too.
We have included an example of a Server Sent Events capability, which uses the core's ability to stream responses from the shell.
-
Please make sure you have the following rust targets installed (there is a
rust-toolchain.toml
in the root directory of this repo, so you should be able to typerustup target list --installed
, in or below the root directory, and these targets will be installed if they are not already present).aarch64-apple-darwin aarch64-apple-ios aarch64-apple-ios-sim aarch64-linux-android wasm32-unknown-unknown x86_64-apple-ios
-
This example currently depends on the
pnpm
package manager when generating types for TypeScript. We are currently revisiting the type generation for foreign types and so this requirement will probably go, but for now, please installpnpm
.
-
Make sure the core builds
cargo build --package shared
-
Generate the shared types for your client applications
cargo build --package shared_types
If you don't have it already, install the trunk
CLI tool:
brew install trunk
To build and run the Yew web app:
cd web-yew
trunk serve
If you don't have it already, install the trunk
CLI tool:
brew install trunk
To build and run the Leptos web app:
cd web-leptos
trunk serve
If you don't have it already, install the dx
CLI tool:
cargo install dioxus-cli
To build and run the [Dioxus]https://dioxuslabs.com/) web app:
cd web-dioxus
dx serve
To build and run the NextJS web app:
cd web-nextjs
pnpm install
pnpm dev
On Windows if you get "ℹ️ Installing wasm-pack" it does not work. You can solve it by installing it manually from: https://rustwasm.github.io/wasm-pack/installer/
You will need XCode, which you can get in the Mac AppStore
cd iOS
open CounterApp.xcodeproj
You should be able to press "Play" to start the app in the simulator, or on an iPhone.
-
You may encounter this error:
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
If this happens, then you need to install the Command Line Tools For Xcode.
Open the Android
folder in
Android Studio. If the build is
successful, you should be able to press "Play" to start the app in the
simulator.
- The Android Studio build might fail for a couple of known reasons:
- A
linker-wrapper.sh
script failure
Ensure you have Python installed and yourPATH
NDK is not installed
Install this via Android Studio --> Settings --> Appearance and Behaviour --> System Settings --> Select the "SDK Tools" tab, select "NDK (side by side)" and press Apply to install
- A
- If Android studio fails to install
git
, you can set the path to your git binary (e.g. the homebrew one) in the preferences under Version Control > Git
To build and run the Tauri app:
cd tauri
pnpm install
pnpm tauri dev