dioxus icon indicating copy to clipboard operation
dioxus copied to clipboard

Default features usage in `dioxus` precludes disabling `tokio_runtime`

Open Jaltaire opened this issue 7 months ago • 1 comments

When adding dioxus as a dependency, dioxus-desktop is configured in dioxus/Cargo.toml as:

dioxus-desktop = { workspace = true, default-features = true, optional = true }

and because Cargo features are additive, this precludes tokio_runtime from being later disabled.

(As such, I am currently using a fork of Dioxus with default-features = false for dioxus-desktop, and this resolves the tokio runtime problem as expected: https://github.com/Jaltaire/dioxus/commit/6d3d3e99bf3c60bc452301eb37fd59a2005dfa09.)

Not sure what the preferred/idiomatic way would be to better handle this, but a couple ideas:

  • We can set default-features = false (or remove tokio_runtime as a default feature) in dioxus/Cargo.toml, though this may be less than preferable for those who ordinarily do not need to set up a separate tokio runtime (as seems to be the expectation for most Dioxus users).
  • Could add setup of tokio runtime to the LaunchBuilder instead.

Happy to put together a PR once there's some consensus around a preferred solution.

Jaltaire avatar May 07 '25 22:05 Jaltaire

if you configure your cargo.toml as such:

[package]
name = "desktop-no-tokio"
version = "0.1.0"
edition = "2024"

[dependencies]
dioxus = { version = "0.7.0-alpha.0" }
dioxus-desktop = { version = "0.7.0-alpha.0", default-features = false }

Then you can launch the desktop app with the dioxus::desktop:

use dioxus::prelude::*;

fn main() {
    dioxus_desktop::launch::launch(app, Default::default(), Default::default())
}

fn app() -> Element {
    rsx! {
        div { style: "display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100vh;",
            h1 { "Hello, Dioxus!" }
            p { "This is a simple Dioxus application." }
            button { onclick: |_| println!("Button clicked!"), "Click Me" }
        }
    }
}

However, we should adjust this so dioxus enables the default features of its child crates and default-features=false is set for desktop.

jkelleyrtp avatar Jun 20 '25 03:06 jkelleyrtp

If we want to allow disabling the tokio runtime we should somehow try to ensure that spawning still works properly. E.g. I just accidentially used a single threaded tokio runtime and then suddenly async tasks don't work because they can't be run anywhere.

mohe2015 avatar Jun 29 '25 15:06 mohe2015