Skip to content

Commit 6774535

Browse files
committed
fix basic wasm nothreads compilation
1 parent 0ee93f0 commit 6774535

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

godot-core/src/private.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ where
262262
godot_error!("{message}");
263263
}
264264
eprintln!("{message}");
265-
#[cfg(debug_assertions)]
265+
#[cfg(debug_assertions)] // TODO: remove too?
266266
eprintln!("{}", std::backtrace::Backtrace::capture());
267267
let _ignored_result = std::io::stderr().flush();
268268
}));
@@ -281,12 +281,12 @@ pub(crate) fn has_error_print_level(level: u8) -> bool {
281281
/// Internal type used to store context information for debug purposes. Debug context is stored on the thread-local
282282
/// ERROR_CONTEXT_STACK, which can later be used to retrieve the current context in the event of a panic. This value
283283
/// probably shouldn't be used directly; use ['get_gdext_panic_context()'](get_gdext_panic_context) instead.
284-
#[cfg(debug_assertions)]
284+
#[cfg(all(debug_assertions, not(wasm_nothreads)))]
285285
struct ScopedFunctionStack {
286286
functions: Vec<*const dyn Fn() -> String>,
287287
}
288288

289-
#[cfg(debug_assertions)]
289+
#[cfg(all(debug_assertions, not(wasm_nothreads)))]
290290
impl ScopedFunctionStack {
291291
/// # Safety
292292
/// Function must be removed (using [`pop_function()`](Self::pop_function)) before lifetime is invalidated.
@@ -311,7 +311,7 @@ impl ScopedFunctionStack {
311311
}
312312
}
313313

314-
#[cfg(debug_assertions)]
314+
#[cfg(all(debug_assertions, not(wasm_nothreads)))]
315315
thread_local! {
316316
static ERROR_CONTEXT_STACK: RefCell<ScopedFunctionStack> = const {
317317
RefCell::new(ScopedFunctionStack { functions: Vec::new() })
@@ -320,9 +320,9 @@ thread_local! {
320320

321321
// Value may return `None`, even from panic hook, if called from a non-Godot thread.
322322
pub fn get_gdext_panic_context() -> Option<String> {
323-
#[cfg(debug_assertions)]
323+
#[cfg(all(debug_assertions, not(wasm_nothreads)))]
324324
return ERROR_CONTEXT_STACK.with(|cell| cell.borrow().get_last());
325-
#[cfg(not(debug_assertions))]
325+
#[cfg(not(all(debug_assertions, not(wasm_nothreads))))]
326326
None
327327
}
328328

@@ -337,14 +337,14 @@ where
337337
E: Fn() -> String,
338338
F: FnOnce() -> R + std::panic::UnwindSafe,
339339
{
340-
#[cfg(debug_assertions)]
340+
#[cfg(all(debug_assertions, not(wasm_nothreads)))]
341341
ERROR_CONTEXT_STACK.with(|cell| unsafe {
342342
// SAFETY: &error_context is valid for lifetime of function, and is removed from LAST_ERROR_CONTEXT before end of function.
343343
cell.borrow_mut().push_function(&error_context)
344344
});
345345
let result =
346346
std::panic::catch_unwind(code).map_err(|payload| extract_panic_message(payload.as_ref()));
347-
#[cfg(debug_assertions)]
347+
#[cfg(all(debug_assertions, not(wasm_nothreads)))]
348348
ERROR_CONTEXT_STACK.with(|cell| cell.borrow_mut().pop_function());
349349
result
350350
}

godot-core/src/task/async_runtime.rs

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ pub fn spawn(future: impl Future<Output = ()> + 'static) -> TaskHandle {
5555
// By limiting async tasks to the main thread we can redirect all signal callbacks back to the main thread via `call_deferred`.
5656
//
5757
// Once thread-safe futures are possible the restriction can be lifted.
58+
#[cfg(not(wasm_nothreads))]
5859
assert!(
5960
crate::init::is_main_thread(),
6061
"godot_task() can only be used on the main thread"

0 commit comments

Comments
 (0)