-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Hot patching systems with subsecond #19309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
06d9d6c
ca7d5cf
6eeae7f
5ac3e41
dc635d8
d92ae90
3be68fa
d4290fb
21ff0de
9c73e08
6f6490b
23dc91d
0e7ab18
5ced020
27acbd7
5a540a1
a60862a
04157b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
//! Utilities for hotpatching code. | ||
mockersf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
use bevy_ecs::{event::EventWriter, HotPatched}; | ||
use dioxus_devtools::{connect, subsecond::apply_patch, DevserverMsg}; | ||
|
||
pub use dioxus_devtools::subsecond::{call, HotFunction}; | ||
|
||
use crate::{Last, Plugin}; | ||
|
||
/// Plugin connecting to Dioxus CLI to enable hot patching. | ||
#[derive(Default)] | ||
pub struct HotPatchPlugin; | ||
|
||
impl Plugin for HotPatchPlugin { | ||
fn build(&self, app: &mut crate::App) { | ||
let (sender, receiver) = crossbeam_channel::bounded::<HotPatched>(1); | ||
|
||
// Connects to the dioxus CLI that will handle rebuilds | ||
// On a successful rebuild the CLI sends a `HotReload` message with the new jump table | ||
// When receiving that message, update the table and send a `HotPatched` message through the channel | ||
connect(move |msg| { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
use dioxus_devtools::{connect_subsecond, subsecond::register_handler};
...
connect_subsecond();
register_handler(Arc::new(move || {
sender.send(HotPatched).unwrap();
})); |
||
if let DevserverMsg::HotReload(hot_reload_msg) = msg { | ||
if let Some(jumptable) = hot_reload_msg.jump_table { | ||
// SAFETY: This is not unsafe, but anything using the updated jump table is. | ||
// The table must be built carefully | ||
unsafe { apply_patch(jumptable).unwrap() }; | ||
sender.send(HotPatched).unwrap(); | ||
} | ||
} | ||
}); | ||
|
||
// Adds a system that will read the channel for new `HotPatched`, and forward them as event to the ECS | ||
app.add_event::<HotPatched>().add_systems( | ||
Last, | ||
move |mut events: EventWriter<HotPatched>| { | ||
if receiver.try_recv().is_ok() { | ||
events.write_default(); | ||
} | ||
}, | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,6 +88,8 @@ critical-section = [ | |
"bevy_reflect?/critical-section", | ||
] | ||
|
||
hotpatching = ["dep:subsecond"] | ||
|
||
[dependencies] | ||
bevy_ptr = { path = "../bevy_ptr", version = "0.16.0-dev" } | ||
bevy_reflect = { path = "../bevy_reflect", version = "0.16.0-dev", features = [ | ||
|
@@ -124,6 +126,7 @@ variadics_please = { version = "1.1", default-features = false } | |
tracing = { version = "0.1", default-features = false, optional = true } | ||
log = { version = "0.4", default-features = false } | ||
bumpalo = "3" | ||
subsecond = { git = "https://github.com/DioxusLabs/dioxus", optional = true } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pretty sure git dependencies will make this unpublishable on crates.io |
||
|
||
concurrent-queue = { version = "2.5.0", default-features = false } | ||
[target.'cfg(not(all(target_has_atomic = "8", target_has_atomic = "16", target_has_atomic = "32", target_has_atomic = "64", target_has_atomic = "ptr")))'.dependencies] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -140,6 +140,11 @@ where | |
}) | ||
} | ||
|
||
#[inline] | ||
fn refresh_hotpatch(&mut self) { | ||
// TODO: support exclusive systems | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a particular blocker that made exclusive systems harder to implement? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, mostly I wanted to make sure we wanted to go in this direction before doing more work. it should also be a todo that can be picked up by anyone among the many other things that can be continued if we get this first step in |
||
} | ||
|
||
#[inline] | ||
fn apply_deferred(&mut self, _world: &mut World) { | ||
// "pure" exclusive systems do not have any buffers to apply. | ||
|
Uh oh!
There was an error while loading. Please reload this page.