Skip to content

Commit 09650f3

Browse files
authored
hot reloading should be behind feature (#3)
1 parent c03a8f6 commit 09650f3

File tree

9 files changed

+112
-159
lines changed

9 files changed

+112
-159
lines changed

.github/workflows/ci.yaml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ jobs:
2020
uses: actions/checkout@v3
2121
- name: Setup Cache
2222
uses: Swatinem/rust-cache@v2
23+
with:
24+
cache-on-failure: true
2325
- name: Install Tools
2426
run: cargo install clippy-sarif sarif-fmt
2527
- name: Build Debug
@@ -36,8 +38,7 @@ jobs:
3638
with:
3739
sarif_file: rust-build-results.sarif
3840
wait-for-processing: true
39-
40-
41+
4142
clippy:
4243
runs-on: "ubuntu-22.04"
4344

@@ -59,4 +60,18 @@ jobs:
5960
if: ${{ always() }}
6061
with:
6162
sarif_file: rust-clippy-results.sarif
62-
wait-for-processing: true
63+
wait-for-processing: true
64+
65+
tests:
66+
runs-on: "ubuntu-22.04"
67+
68+
steps:
69+
- name: Checkout
70+
uses: actions/checkout@v3
71+
- name: Setup Cache
72+
uses: Swatinem/rust-cache@v2
73+
with:
74+
cache-on-failure: true
75+
- name: Tests
76+
run: |
77+
cargo test

Cargo.lock

Lines changed: 0 additions & 70 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ edition = "2021"
1111

1212
[workspace.dependencies]
1313
godot = { git = "https://github.com/titannano/gdext", rev = "0f9a3e22f9cbdc31e0c575a12c69d26241a92f9f" }
14-
#godot = { path = "../gdext/godot" }
15-
backtrace = "0.3.64"
1614
hot-lib-reloader = "0.6.5"
1715
itertools = "0.10.3"
1816
abi_stable = { version = "0.11.2", default-features = false }

rust-script/Cargo.toml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,19 @@ edition.workspace = true
77

88
[dependencies]
99
godot.workspace = true
10-
backtrace.workspace = true
11-
hot-lib-reloader.workspace = true
1210
itertools.workspace = true
1311
abi_stable.workspace = true
1412
rand.workspace = true
1513
cfg-if.workspace = true
16-
process_path.workspace = true
14+
15+
hot-lib-reloader = { workspace = true, optional = true }
16+
process_path = { workspace = true, optional = true }
1717

1818
godot-rust-script-derive.workspace = true
1919

2020
[dev-dependencies]
21-
tests-scripts-lib = { path = "../tests-scripts-lib" }
21+
tests-scripts-lib = { path = "../tests-scripts-lib", features = ["hot-reload"] }
22+
23+
[features]
24+
default = ["hot-reload"]
25+
hot-reload = ["dep:process_path", "dep:hot-lib-reloader"]

rust-script/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ pub mod private_export {
1212
pub use super::script_registry::RemoteVariantType;
1313
pub use abi_stable::std_types::{RStr, RString, RVec};
1414
pub use godot::sys::{plugin_add, plugin_registry};
15+
16+
#[cfg(all(feature = "hot-reload", debug_assertions))]
1517
pub use hot_lib_reloader::{self, hot_module};
1618
}
1719

rust-script/src/runtime/mod.rs

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#[cfg(debug_assertions)]
1+
#[cfg(all(feature = "hot-reload", debug_assertions))]
22
mod hot_reloader;
33
mod resource_loader;
44
mod resource_saver;
@@ -28,13 +28,13 @@ use crate::{
2828

2929
use self::rust_script_language::RustScriptLanguage;
3030

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

3434
#[macro_export]
3535
macro_rules! setup {
3636
($lib_crate:tt) => {
37-
#[cfg(debug_assertions)]
37+
#[cfg(all(feature = "hot-reload", debug_assertions))]
3838
#[$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())]
3939
mod scripts_lib {
4040
use $crate::private_export::RVec;
@@ -54,7 +54,7 @@ macro_rules! setup {
5454
pub use ::$lib_crate::__GODOT_RUST_SCRIPT_SRC_ROOT;
5555
}
5656

57-
#[cfg(not(debug_assertions))]
57+
#[cfg(not(all(feature = "hot-reload", debug_assertions)))]
5858
mod scripts_lib {
5959
pub use ::$lib_crate::{__godot_rust_script_init, __GODOT_RUST_SCRIPT_SRC_ROOT};
6060
}
@@ -67,15 +67,15 @@ macro_rules! init {
6767
$crate::RustScriptExtensionLayer::new(
6868
scripts_lib::__godot_rust_script_init,
6969
scripts_lib::__GODOT_RUST_SCRIPT_SRC_ROOT,
70-
#[cfg(debug_assertions)]
70+
#[cfg(all(feature = "hot-reload", debug_assertions))]
7171
scripts_lib::subscribe,
7272
)
7373
};
7474
}
7575

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

@@ -86,7 +86,7 @@ pub trait RustScriptLibInit: Fn(Option<BindingInit>) -> RVec<RemoteScriptMetaDat
8686
impl<F> RustScriptLibInit for F where F: Fn(Option<BindingInit>) -> RVec<RemoteScriptMetaData> {}
8787

8888
cfg_if! {
89-
if #[cfg(debug_assertions)] {
89+
if #[cfg(all(feature = "hot-reload", debug_assertions))] {
9090
type HotReloadSubscribe = fn() -> hot_lib_reloader::LibReloadObserver;
9191
}
9292
}
@@ -98,18 +98,19 @@ pub struct RustScriptExtensionLayer {
9898
res_loader: Option<Gd<RustScriptResourceLoader>>,
9999
scripts_src_dir: Option<&'static str>,
100100

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

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

108108
impl RustScriptExtensionLayer {
109109
pub fn new<F: RustScriptLibInit + 'static + Clone>(
110110
lib_init_fn: F,
111111
scripts_src_dir: &'static str,
112-
#[cfg(debug_assertions)] hot_reload_subscribe: HotReloadSubscribe,
112+
#[cfg(all(feature = "hot-reload", debug_assertions))]
113+
hot_reload_subscribe: HotReloadSubscribe,
113114
) -> Self {
114115
Self {
115116
lib_init_fn: Rc::new(lib_init_fn),
@@ -118,10 +119,10 @@ impl RustScriptExtensionLayer {
118119
res_loader: None,
119120
scripts_src_dir: Some(scripts_src_dir),
120121

121-
#[cfg(debug_assertions)]
122+
#[cfg(all(feature = "hot-reload", debug_assertions))]
122123
hot_reload_subscribe,
123124

124-
#[cfg(debug_assertions)]
125+
#[cfg(all(feature = "hot-reload", debug_assertions))]
125126
hot_reloader: None,
126127
}
127128
}
@@ -134,7 +135,7 @@ impl RustScriptExtensionLayer {
134135
let res_saver = Gd::new(RustScriptResourceSaver);
135136

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

140141
let mut hot_reloader = Gd::with_base(|base| HotReloader::new((self.hot_reload_subscribe)(), self.lib_init_fn.clone(), base));
@@ -179,7 +180,7 @@ impl RustScriptExtensionLayer {
179180

180181
fn load_rust_scripts(lib_init_fn: Rc<dyn RustScriptLibInit>) {
181182
cfg_if! {
182-
if #[cfg(debug_assertions)] {
183+
if #[cfg(all(feature = "hot-reload", debug_assertions))] {
183184
let ffi_init = Some(unsafe { godot::sys::get_binding() });
184185
} else {
185186
let ffi_init = None;
@@ -239,17 +240,3 @@ impl ToDictionary for MethodInfo {
239240
})
240241
}
241242
}
242-
243-
#[cfg(test)]
244-
mod test {
245-
mod macros_test {
246-
crate::setup!(tests_scripts_lib);
247-
248-
#[test]
249-
fn verify_macros() {
250-
let inst = crate::init!();
251-
252-
assert_eq!(inst.lang, None);
253-
}
254-
}
255-
}

0 commit comments

Comments
 (0)