Skip to content

Hot Reloading#3000

Merged
hecrj merged 4 commits intomasterfrom
feature/hot-reloading
Jun 24, 2025
Merged

Hot Reloading#3000
hecrj merged 4 commits intomasterfrom
feature/hot-reloading

Conversation

@hecrj
Copy link
Member

@hecrj hecrj commented Jun 24, 2025

This PR implements a very, very experimental approach for hot reloading.

It leverages a new tech that the folks from the Dioxus toolkit came up with called subsecond. It performs hotpatching of Rust binaries at runtime, similar to how some malware operates.

Controversy

The recommended way to use this new tech is through Dioxus' opinionated CLI tool and dev server protocol: dioxus-cli. However, I personally love cargo and do not want to give it up; which is why I ported most of their technology into a generic tool: cargo-hot.

This did spur some controversy and discussion in a Bevy issue, as the authors of subsecond felt I was ripping out their code. I will reiterate here that I have no plans on hard-forking subsecond nor competing directly with it and, furthermore, I will do my best to port any considerable improvements that land in cargo-hot back to dioxus-cli.

Usage

The hot reloading client will be active when the hot feature flag is enabled. However, the build system needs to build and send patches to the executable; so a new build command is needed.

Let's assume you define a debug feature in your Cargo.toml that enables the hot feature:

[features]
debug = ["iced/hot"]

First, you must install cargo-hot:

cargo install --locked --git https://github.com/hecrj/cargo-hot.git cargo-hot

cargo-hot is meant to be a drop-in replacement for cargo run, so if you were running your project with:

cargo run --features debug

You can simply replace run with hot:

cargo hot --features debug

And that's it! iced integrates internally with subsecond, so your code does not need to change at all.

Simply edit your code and see it reload live!

Limitations

  • Very experimental! May crash your OS.
  • Only changes to the root crate will trigger a reload.
  • Changes to your application State or Message types will need a cold restart (for now!).
  • Wasm is not supported at the moment.

Closes #21.

@hecrj hecrj added this to the 0.14 milestone Jun 24, 2025
@hecrj hecrj force-pushed the feature/hot-reloading branch from 2ad0097 to 6a1e3a6 Compare June 24, 2025 12:07
@hecrj hecrj force-pushed the feature/hot-reloading branch from 6a1e3a6 to 699b857 Compare June 24, 2025 12:30
@clarkmoody
Copy link
Contributor

Based.

@hecrj hecrj enabled auto-merge June 24, 2025 15:46
@hecrj hecrj merged commit c952ea8 into master Jun 24, 2025
30 checks passed
@hecrj hecrj deleted the feature/hot-reloading branch June 24, 2025 15:48
@MoonBox5
Copy link

which is why I ported most of their technology into a generic tool: cargo-hot

@hecrj
Have you kept support for choosing to run iced apps using dx and subsecond instead of cargo-hot? Or is your implementation coupled to cargo-hot only?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hot reloading of layout

3 participants