1
- #[ cfg( debug_assertions) ]
1
+ #[ cfg( all ( feature = "hot-reload" , debug_assertions) ) ]
2
2
mod hot_reloader;
3
3
mod resource_loader;
4
4
mod resource_saver;
@@ -28,13 +28,13 @@ use crate::{
28
28
29
29
use self :: rust_script_language:: RustScriptLanguage ;
30
30
31
- #[ cfg( debug_assertions) ]
31
+ #[ cfg( all ( feature = "hot-reload" , debug_assertions) ) ]
32
32
use hot_reloader:: { HotReloadEntry , HotReloader } ;
33
33
34
34
#[ macro_export]
35
35
macro_rules! setup {
36
36
( $lib_crate: tt) => {
37
- #[ cfg( debug_assertions) ]
37
+ #[ cfg( all ( feature = "hot-reload" , debug_assertions) ) ]
38
38
#[ $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( ) ) ]
39
39
mod scripts_lib {
40
40
use $crate:: private_export:: RVec ;
@@ -54,7 +54,7 @@ macro_rules! setup {
54
54
pub use :: $lib_crate:: __GODOT_RUST_SCRIPT_SRC_ROOT;
55
55
}
56
56
57
- #[ cfg( not( debug_assertions) ) ]
57
+ #[ cfg( not( all ( feature = "hot-reload" , debug_assertions) ) ) ]
58
58
mod scripts_lib {
59
59
pub use :: $lib_crate:: { __godot_rust_script_init, __GODOT_RUST_SCRIPT_SRC_ROOT} ;
60
60
}
@@ -67,15 +67,15 @@ macro_rules! init {
67
67
$crate:: RustScriptExtensionLayer :: new(
68
68
scripts_lib:: __godot_rust_script_init,
69
69
scripts_lib:: __GODOT_RUST_SCRIPT_SRC_ROOT,
70
- #[ cfg( debug_assertions) ]
70
+ #[ cfg( all ( feature = "hot-reload" , debug_assertions) ) ]
71
71
scripts_lib:: subscribe,
72
72
)
73
73
} ;
74
74
}
75
75
76
76
thread_local ! {
77
77
static SCRIPT_REGISTRY : RwLock <HashMap <String , ScriptMetaData >> = RwLock :: default ( ) ;
78
- #[ cfg( debug_assertions) ]
78
+ #[ cfg( all ( feature = "hot-reload" , debug_assertions) ) ]
79
79
static HOT_RELOAD_BRIDGE : std:: cell:: RefCell <HashMap <rust_script_instance:: RustScriptInstanceId , std:: cell:: RefCell <HotReloadEntry >>> = std:: cell:: RefCell :: default ( ) ;
80
80
}
81
81
@@ -86,7 +86,7 @@ pub trait RustScriptLibInit: Fn(Option<BindingInit>) -> RVec<RemoteScriptMetaDat
86
86
impl < F > RustScriptLibInit for F where F : Fn ( Option < BindingInit > ) -> RVec < RemoteScriptMetaData > { }
87
87
88
88
cfg_if ! {
89
- if #[ cfg( debug_assertions) ] {
89
+ if #[ cfg( all ( feature = "hot-reload" , debug_assertions) ) ] {
90
90
type HotReloadSubscribe = fn ( ) -> hot_lib_reloader:: LibReloadObserver ;
91
91
}
92
92
}
@@ -98,18 +98,19 @@ pub struct RustScriptExtensionLayer {
98
98
res_loader : Option < Gd < RustScriptResourceLoader > > ,
99
99
scripts_src_dir : Option < & ' static str > ,
100
100
101
- #[ cfg( debug_assertions) ]
101
+ #[ cfg( all ( feature = "hot-reload" , debug_assertions) ) ]
102
102
hot_reload_subscribe : HotReloadSubscribe ,
103
103
104
- #[ cfg( debug_assertions) ]
104
+ #[ cfg( all ( feature = "hot-reload" , debug_assertions) ) ]
105
105
hot_reloader : Option < Gd < HotReloader > > ,
106
106
}
107
107
108
108
impl RustScriptExtensionLayer {
109
109
pub fn new < F : RustScriptLibInit + ' static + Clone > (
110
110
lib_init_fn : F ,
111
111
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 ,
113
114
) -> Self {
114
115
Self {
115
116
lib_init_fn : Rc :: new ( lib_init_fn) ,
@@ -118,10 +119,10 @@ impl RustScriptExtensionLayer {
118
119
res_loader : None ,
119
120
scripts_src_dir : Some ( scripts_src_dir) ,
120
121
121
- #[ cfg( debug_assertions) ]
122
+ #[ cfg( all ( feature = "hot-reload" , debug_assertions) ) ]
122
123
hot_reload_subscribe,
123
124
124
- #[ cfg( debug_assertions) ]
125
+ #[ cfg( all ( feature = "hot-reload" , debug_assertions) ) ]
125
126
hot_reloader : None ,
126
127
}
127
128
}
@@ -134,7 +135,7 @@ impl RustScriptExtensionLayer {
134
135
let res_saver = Gd :: new ( RustScriptResourceSaver ) ;
135
136
136
137
cfg_if ! {
137
- if #[ cfg( debug_assertions) ] {
138
+ if #[ cfg( all ( feature = "hot-reload" , debug_assertions) ) ] {
138
139
use godot:: prelude:: StringName ;
139
140
140
141
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 {
179
180
180
181
fn load_rust_scripts ( lib_init_fn : Rc < dyn RustScriptLibInit > ) {
181
182
cfg_if ! {
182
- if #[ cfg( debug_assertions) ] {
183
+ if #[ cfg( all ( feature = "hot-reload" , debug_assertions) ) ] {
183
184
let ffi_init = Some ( unsafe { godot:: sys:: get_binding( ) } ) ;
184
185
} else {
185
186
let ffi_init = None ;
@@ -239,17 +240,3 @@ impl ToDictionary for MethodInfo {
239
240
} )
240
241
}
241
242
}
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