From 9998b156f833d871864b963c67476aa2cb786a67 Mon Sep 17 00:00:00 2001 From: Ezekiel Warren Date: Mon, 14 Oct 2024 13:44:11 -0700 Subject: [PATCH] fix: use correct macro in async header --- dylib/dylib.cc | 13 +++++++++---- dylib/index.bzl | 1 + ecsact/runtime/async.h | 22 ++++++++++++---------- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/dylib/dylib.cc b/dylib/dylib.cc index 13c9899e..afe460c3 100644 --- a/dylib/dylib.cc +++ b/dylib/dylib.cc @@ -1,5 +1,6 @@ #include #include +#include #include "ecsact/runtime/dylib.h" #ifdef ECSACT_ASYNC_API_LOAD_AT_RUNTIME @@ -47,10 +48,14 @@ FOR_EACH_ECSACT_SERIALIZE_API_FN(ECSACT_DYLIB_UTIL_FN_PTR_DEFN); #define HAS_FN_CHECK(fn_name, target_fn_name) \ if(std::strcmp(target_fn_name, #fn_name) == 0) return true -#define ASSIGN_FN_IF(fn_name, target_fn_name, fn_ptr) \ - if(std::strcmp(#fn_name, target_fn_name) == 0) { \ - fn_name = reinterpret_cast(fn_ptr); \ - } \ +#define ASSIGN_FN_IF(fn_name, target_fn_name, fn_ptr) \ + static_assert( \ + std::is_pointer_v, \ + "Ecsact dylib may only be used for functions available at runtime" \ + ); \ + if(std::strcmp(#fn_name, target_fn_name) == 0) { \ + fn_name = reinterpret_cast(fn_ptr); \ + } \ static_assert(true, "macro requires ;") bool ecsact_dylib_has_fn(const char* fn_name) { diff --git a/dylib/index.bzl b/dylib/index.bzl index 9bd4358a..6d836c3c 100644 --- a/dylib/index.bzl +++ b/dylib/index.bzl @@ -26,6 +26,7 @@ def cc_ecsact_dylib(name = None, srcs = [], ecsact_modules = [], deps = [], defi name = name, deps = deps + ["@ecsact_runtime//:dylib", "@ecsact_runtime//dylib:util"] + ["@ecsact_runtime//:{}".format(m) for m in ecsact_modules], srcs = srcs + ["@ecsact_runtime//dylib:dylib.cc"], + local_defines = ["ECSACT_{}_API_EXPORT".format(m.upper()) for m in ecsact_modules], defines = # defines + ["ECSACT_{}_API_LOAD_AT_RUNTIME".format(m.upper()) for m in ecsact_modules], diff --git a/ecsact/runtime/async.h b/ecsact/runtime/async.h index 9437b94e..19a5496f 100644 --- a/ecsact/runtime/async.h +++ b/ecsact/runtime/async.h @@ -213,7 +213,7 @@ ECSACT_ASYNC_API_FN(int32_t, ecsact_async_get_current_tick)(void); * fields must be supplied as a sequential array in declaration order, * otherwise may be NULL. */ -ECSACT_CORE_API_FN(ecsact_async_request_id, ecsact_async_stream) +ECSACT_ASYNC_API_FN(ecsact_async_request_id, ecsact_async_stream) ( // ecsact_entity_id entity, ecsact_component_id component_id, @@ -221,14 +221,16 @@ ECSACT_CORE_API_FN(ecsact_async_request_id, ecsact_async_stream) const void* indexed_field_values ); -#define FOR_EACH_ECSACT_ASYNC_API_FN(fn, ...) \ - fn(ecsact_async_enqueue_execution_options, __VA_ARGS__); \ - fn(ecsact_async_flush_events, __VA_ARGS__); \ - fn(ecsact_async_connect, __VA_ARGS__); \ - fn(ecsact_async_disconnect, __VA_ARGS__); \ - fn(ecsact_async_get_current_tick, __VA_ARGS__); \ - fn(ecsact_async_stream, __VA_ARGS__) +#ifdef ECSACT_MSVC_TRADITIONAL +# define FOR_EACH_ECSACT_ASYNC_API_FN(fn, ...) ECSACT_MSVC_TRADITIONAL_ERROR() +#else +# define FOR_EACH_ECSACT_ASYNC_API_FN(fn, ...) \ + fn(ecsact_async_enqueue_execution_options, __VA_ARGS__); \ + fn(ecsact_async_flush_events, __VA_ARGS__); \ + fn(ecsact_async_connect, __VA_ARGS__); \ + fn(ecsact_async_disconnect, __VA_ARGS__); \ + fn(ecsact_async_get_current_tick, __VA_ARGS__); \ + fn(ecsact_async_stream, __VA_ARGS__) +#endif -#undef ECSACT_ASYNC_API -#undef ECSACT_ASYNC_API_FN #endif // ECSACT_RUNTIME_ASYNC_H