Skip to content

Commit

Permalink
Remove hot reloader
Browse files Browse the repository at this point in the history
  • Loading branch information
TitanNano committed Dec 30, 2023
1 parent 928159e commit 0294463
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 694 deletions.
332 changes: 6 additions & 326 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,13 @@ edition = "2021"

[workspace.dependencies]
godot = { git = "https://github.com/titannano/gdext", rev = "a5d17342b7b47e8af652a6a733f497c468bbd59a" }
hot-lib-reloader = "0.6.5"
itertools = "0.10.3"
abi_stable = { version = "0.11.2", default-features = false }
rand = "0.8.5"
cfg-if = "1.0.0"
darling = { version = "0.20.3" }
proc-macro2 = "1.0.68"
quote = "1.0.33"
syn = "2.0.38"
process_path = "0.1"

godot-rust-script-derive = { path = "derive" }
tests-scripts-lib = { path = "tests-scripts-lib" }
10 changes: 3 additions & 7 deletions rust-script/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,17 @@ edition.workspace = true
[dependencies]
godot.workspace = true
abi_stable.workspace = true
cfg-if.workspace = true

hot-lib-reloader = { workspace = true, optional = true }
itertools = { workspace = true, optional = true }
rand = { workspace = true, optional = true }
process_path = { workspace = true, optional = true }

godot-rust-script-derive = { workspace = true, optional = true }

[dev-dependencies]
tests-scripts-lib = { path = "../tests-scripts-lib", features = ["test-hot-reload"] }
tests-scripts-lib = { path = "../tests-scripts-lib" }
godot-rust-script = { path = "./", features = ["runtime"] }

[features]
default = ["hot-reload"]
hot-reload = ["dep:process_path", "dep:hot-lib-reloader"]
default = []
runtime = ["dep:itertools", "dep:rand"]
scripts = ["dep:godot-rust-script-derive"]
scripts = ["dep:godot-rust-script-derive"]
5 changes: 1 addition & 4 deletions rust-script/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@ pub use runtime::*;
pub use godot_rust_script_derive::{godot_script_impl, GodotScript};

pub mod private_export {
pub use super::{script_registry::RemoteVariantType, shared::BindingInit};
pub use super::script_registry::RemoteVariantType;
pub use abi_stable::std_types::{RStr, RString, RVec};
pub use godot::sys::{plugin_add, plugin_registry};

#[cfg(all(feature = "hot-reload", debug_assertions))]
pub use hot_lib_reloader::{self, hot_module};
}

pub use godot;
13 changes: 1 addition & 12 deletions rust-script/src/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,10 @@ macro_rules! setup_library {
$crate::private_export::plugin_registry!(pub __SCRIPT_REGISTRY: $crate::RegistryItem);

#[no_mangle]
pub fn __godot_rust_script_init(binding: Option<$crate::private_export::BindingInit>) -> $crate::private_export::RVec<$crate::RemoteScriptMetaData> {
pub fn __godot_rust_script_init() -> $crate::private_export::RVec<$crate::RemoteScriptMetaData> {
use $crate::private_export::*;
use $crate::godot::obj::EngineEnum;

if let Some(init) = binding {
let config = $crate::godot::sys::GdextConfig {
tool_only_in_editor: false,
is_editor: ::std::cell::OnceCell::new(),
};

unsafe {
$crate::godot::sys::init_with_existing_binding(init);
}
}

let lock = __godot_rust_plugin___SCRIPT_REGISTRY.lock().expect("unable to aquire mutex lock");

$crate::assemble_metadata(lock.iter())
Expand Down
141 changes: 0 additions & 141 deletions rust-script/src/runtime/hot_reloader.rs

This file was deleted.

89 changes: 1 addition & 88 deletions rust-script/src/runtime/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#[cfg(all(feature = "hot-reload", debug_assertions))]
mod hot_reloader;
mod metadata;
mod resource_loader;
mod resource_saver;
Expand All @@ -9,7 +7,6 @@ mod rust_script_language;

use std::{collections::HashMap, rc::Rc, sync::RwLock};

use cfg_if::cfg_if;
use godot::{
engine::{Engine, ResourceLoader, ResourceSaver},
prelude::{godot_print, Gd},
Expand All @@ -25,35 +22,6 @@ use crate::{

use self::rust_script_language::RustScriptLanguage;

#[cfg(all(feature = "hot-reload", debug_assertions))]
use hot_reloader::{HotReloadEntry, HotReloader};

#[cfg(all(feature = "hot-reload", debug_assertions))]
#[macro_export]
macro_rules! setup {
($lib_crate:tt) => {
#[$crate::private_export::hot_module(dylib = stringify!($lib_crate), lib_dir=process_path::get_dylib_path().and_then(|path| path.parent().map(std::path::Path::to_path_buf)).unwrap_or_default())]
mod scripts_lib {
use $crate::private_export::RVec;

// manually expose functions.
#[hot_functions]
extern "Rust" {
pub fn __godot_rust_script_init(
binding: Option<$crate::private_export::BindingInit>,
) -> RVec<$crate::RemoteScriptMetaData>;
}

// expose a type to subscribe to lib load events
#[lib_change_subscription]
pub fn subscribe() -> hot_lib_reloader::LibReloadObserver {}

pub use ::$lib_crate::__GODOT_RUST_SCRIPT_SRC_ROOT;
}
};
}

#[cfg(not(all(feature = "hot-reload", debug_assertions)))]
#[macro_export]
macro_rules! setup {
($lib_crate:tt) => {
Expand All @@ -63,7 +31,6 @@ macro_rules! setup {
};
}

#[cfg(not(all(feature = "hot-reload", debug_assertions)))]
#[macro_export]
macro_rules! init {
() => {
Expand All @@ -74,28 +41,8 @@ macro_rules! init {
};
}

#[cfg(all(feature = "hot-reload", debug_assertions))]
#[macro_export]
macro_rules! init {
() => {
$crate::RustScriptExtensionLayer::new(
scripts_lib::__godot_rust_script_init,
scripts_lib::__GODOT_RUST_SCRIPT_SRC_ROOT,
scripts_lib::subscribe,
)
};
}

thread_local! {
static SCRIPT_REGISTRY: RwLock<HashMap<String, ScriptMetaData>> = RwLock::default();
#[cfg(all(feature = "hot-reload", debug_assertions))]
static HOT_RELOAD_BRIDGE: std::cell::RefCell<HashMap<rust_script_instance::RustScriptInstanceId, std::cell::RefCell<HotReloadEntry>>> = std::cell::RefCell::default();
}

cfg_if! {
if #[cfg(all(feature = "hot-reload", debug_assertions))] {
type HotReloadSubscribe = fn() -> hot_lib_reloader::LibReloadObserver;
}
}

pub struct RustScriptExtensionLayer {
Expand All @@ -104,33 +51,19 @@ pub struct RustScriptExtensionLayer {
res_saver: Option<Gd<RustScriptResourceSaver>>,
res_loader: Option<Gd<RustScriptResourceLoader>>,
scripts_src_dir: Option<&'static str>,

#[cfg(all(feature = "hot-reload", debug_assertions))]
hot_reload_subscribe: HotReloadSubscribe,

#[cfg(all(feature = "hot-reload", debug_assertions))]
hot_reloader: Option<Gd<HotReloader>>,
}

impl RustScriptExtensionLayer {
pub fn new<F: RustScriptLibInit + 'static + Clone>(
lib_init_fn: F,
scripts_src_dir: &'static str,
#[cfg(all(feature = "hot-reload", debug_assertions))]
hot_reload_subscribe: HotReloadSubscribe,
) -> Self {
Self {
lib_init_fn: Rc::new(lib_init_fn),
lang: None,
res_saver: None,
res_loader: None,
scripts_src_dir: Some(scripts_src_dir),

#[cfg(all(feature = "hot-reload", debug_assertions))]
hot_reload_subscribe,

#[cfg(all(feature = "hot-reload", debug_assertions))]
hot_reloader: None,
}
}

Expand All @@ -141,18 +74,6 @@ impl RustScriptExtensionLayer {
let res_loader = RustScriptResourceLoader::new(lang.clone());
let res_saver = Gd::from_object(RustScriptResourceSaver);

cfg_if! {
if #[cfg(all(feature = "hot-reload", debug_assertions))] {
use godot::prelude::StringName;

let mut hot_reloader = Gd::from_init_fn(|base| HotReloader::new((self.hot_reload_subscribe)(), self.lib_init_fn.clone(), base));

hot_reloader.call_deferred(StringName::from("register"), &[]);

self.hot_reloader = Some(hot_reloader);
}
}

self.lang = Some(lang.clone());
self.res_saver = Some(res_saver.clone());
self.res_loader = Some(res_loader.clone());
Expand Down Expand Up @@ -186,15 +107,7 @@ impl RustScriptExtensionLayer {
}

fn load_rust_scripts(lib_init_fn: Rc<dyn RustScriptLibInit>) {
cfg_if! {
if #[cfg(all(feature = "hot-reload", debug_assertions))] {
let ffi_init = Some(unsafe { godot::sys::get_binding() });
} else {
let ffi_init = None;
}
}

let result = lib_init_fn(ffi_init);
let result = lib_init_fn();

let registry: HashMap<String, ScriptMetaData> = result
.into_iter()
Expand Down
Loading

0 comments on commit 0294463

Please sign in to comment.