An opinionated cross-platform full-stack application template developed with Rust, Cargo Mobile 2, Dioxus, Warp, Diesel, PostgreSQL, Supabase Auth, Bun and TailwindCSS.
MIT License
cargo install --git https://github.com/tauri-apps/cargo-mobile2
cargo install cargo-watch
curl -fsSL https://bun.sh/install | bash
or powershell -c "irm bun.sh/install.ps1 | iex"
@material-tailwind/html
using bun install
bun tailwind
.env.example
file in a new .env
file and fill in the SUPABASE_URL
, SUPABASE_API_KEY
and SUPABASE_JWT_SECRET
fields with your Supabase credentials (found in the Supabase dashboard under project settings).DATABASE_URL
in the .env
file with a PostgreSQL connection string (you can use the one provided by Supabase):DATABASE_URL="postgres://postgres.<name>:<password>@<domain>:<port>/<database>"
cargo install diesel_cli --no-default-features --features postgres
. You could run into some issues linking the postgres library, in that case you should install the libpq-dev
package (or Postgres for Windows) on your system and setup the correct rustc
linker path search in the .cargo/config.toml
file:[target.x86_64-unknown-linux-gnu.pq]
rustc-link-search = ["/path/to/postgres/15/lib"]
rustc-link-lib = ["libpq"]
# or for Windows
[target.x86_64-pc-windows-msvc.pq]
rustc-link-search = ["C:\\path\\to\\postgres\\15\\lib"]
rustc-link-lib = ["libpq"]
bun migrate
or call directly the diesel
CLI inside the api
folder.api/src/handlers.rs
file by removing the JWT verification.To setup Supabase Storage you should create two new buckets in the Supabase dashboard (e.g. a private bucket images
and a public one public-images
), then upload a file to them (e.g. t5.png
).
Make sure to allow read and/or write access to the private bucket for authenticated users, using Supabase RLS as follows:
bun api
(or cargo run
inside the api
folder).All the below notes on various package versions and features are handled by the
bun web
,bun desktop
, andbun android
commands by automatically copying the correctCargo.toml
(.web
,.desktop
or.mobile
) file to the project root so beware of running multiple platorms at the same time.
To compile this you must switch on the
web
feature of thedioxus
package and remove themobile
one. Works only withoutopenssl
installed with thevendored
option in theCargo.toml
.
bun web
(or dx serve
).Works with
openssl
installed with thevendored
option and also without it (builds significantly faster both on Windows and Linux).
dioxus-cli
, you can find them here.llvm
on your system with sudo apt install llvm-dev libclang-dev clang lib
on Linux, winget install LLVM.LLVM
on Windows or brew install llvm
on MacOS to compile the desktop app.LIBCLANG_PATH
environment variable for Windows to point to the LLVM installation folder (e.g. C:\Program Files\LLVM\bin
)bun desktop
(or dx serve --platform desktop
).Works only with
openssl
installed with thevendored
option (requiresperl
of the UNIX flavour to build it, this means you cannot use the Windowsperl
version directly). Avoid spaces in the absolute path of the project folder, this will cause a linking error while buildingopenssl
.
cargo mobile init
to generate only the .cargo/config.toml
file and discard the other changes. If that errors out just create it with the following content to setup the linker for the Android targets:[target.aarch64-linux-android]
linker = "/<absolute-path-to-home>/<path-to-sdk>/ndk/<ndk-version>/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android<api-version>-clang"
[target.armv7-linux-androideabi]
linker = "/<absolute-path-to-home>/<path-to-sdk>/ndk/<ndk-version>/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7-linux-android<api-version>-clang"
[target.i686-linux-android]
linker = "/<absolute-path-to-home>/<path-to-sdk>/ndk/<ndk-version>/toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android<api-version>-clang"
[target.x86_64-linux-android]
linker = "/<absolute-path-to-home>/<path-to-sdk>/ndk/<ndk-version>/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android<api-version>-clang"
.bashrc
/.zshrc
file (or in the system environment for Windows) and install gcc-multilib
with apt to compile the Android app:# These two variables depend on the architecture of the device
# and the API version you are targeting
export TARGET=aarch64-linux-android
export API=33
export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
export ANDROID_HOME=$HOME/android
export ANDROID_SDK_ROOT=$ANDROID_HOME
export NDK_HOME=$ANDROID_HOME/ndk/<your-ndk-version>
export ANDROID_NDK_HOME=$NDK_HOME
export TOOLCHAIN=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64
export AR=$TOOLCHAIN/bin/llvm-ar
export CC=$TOOLCHAIN/bin/$TARGET$API-clang
export AS=$CC
export CXX=$TOOLCHAIN/bin/$TARGET$API-clang++
export LD=$TOOLCHAIN/bin/ld
export RANLIB=$TOOLCHAIN/bin/llvm-ranlib
export STRIP=$TOOLCHAIN/bin/llvm-strip
export PATH=$JAVA_HOME/bin:$ANDROID_HOME/cmdline-tools/latest/bin:\
$TOOLCHAIN/bin:$NDK_HOME:$ANDROID_HOME/platform-tools:\
$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$PATH
bun android
(or cargo android run
).adb tcpip 5555
and adb connect <device-ip>:5555
with the device temporarily connected via USB (this works great on WSL).adb reverse tcp:8000 tcp:8000
from the local machine..cargo/config.toml
file introduced above:[profile.release]
opt-level = "z"
debug = false
lto = true
codegen-units = 1
panic = "abort"
strip = true
incremental = false
API_URL (for the web app) -> update this after your API deployment
APP_URL (for the API) -> update this after your web deployment
SUPABASE_URL
SUPABASE_API_KEY
SUPABASE_JWT_SECRET
DATABASE_URL
flyctl
CLI using curl -L https://fly.io/install.sh | sh
and login with your Fly.io account using fly auth login
.fly launch
and following the prompts, using the existing Dockerfile
and fly.toml
files.fly deploy
or bun deploy:api
. You can then change the API_URL
in the .env
file to the one deployed by Fly../github/workflows/deploy-api.yml
workflow, adding to the repository secrets the FLY_API_TOKEN
key, generated with fly tokens create deploy -x 999999h
.gh-pages
branch. You should also set workflow permissions under the Actions settings to Read and write permissions
.base_path
in the Dioxus.pages.toml
file to match the name of your repository.APP_URL
set to your Github Pages domain (e.g. https://albbus-stack.github.io
) otherwise there will be CORS errors..github/workflows/deploy-web.yaml
workflow to deploy on every push to the master
branch or manually with the workflow_dispatch
event.The Github action for MacOS is not yet implemented. Linux is barely functioning since the built bundle has some bugs (e.g the installed .deb package searches assets in the folder where you call it and not globally). Windows is the only platform that bundles correctly for now.
.github/workflows/windows.yaml
workflow to build and upload the .msi
installer in the action artifacts on every push to the master
branch or manually with the workflow_dispatch
event..github/workflows/linux.yaml
workflow to build and upload the .deb
package along with the dist folder in the action artifacts on every push to the master
branch or manually with the workflow_dispatch
event.dx bundle
is being actively developed and is not yet ready for production use, so you should use dx build
if bundling fails on other platforms (this is not good since you need attach the entire dist
folder to your release build).bun build:android
command, this will generate various .apk
files in subfolders of gen/android/app/build/outputs/apk/
for each ABI.keytool
CLI as follows:keytool -genkey -keystore release.keystore -alias alias_name -keyalg RSA -validity 10000
.apk
file using the jarsigner
CLI as follows:jarsigner -keystore release.keystore ./path/to/apk alias_name
.apk
you can install the app on your device physically or using adb install ./path/to/apk
(you should sign and install an .apk
compatible with the ABI of your device).