Skip to content

Commit 4eec253

Browse files
authored
dylib rework + C header compatiblity fixes (#98)
1 parent 5cbf725 commit 4eec253

File tree

6 files changed

+117
-53
lines changed

6 files changed

+117
-53
lines changed

dylib/BUILD.bazel

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
load("@rules_cc//cc:defs.bzl", "cc_library")
22
load("//bazel:copts.bzl", "copts")
3+
load("//:index.bzl", "ecsact_runtime_modules")
4+
load(":index.bzl", "cc_ecsact_dylib")
35

46
package(default_visibility = ["//visibility:public"])
57

@@ -11,13 +13,15 @@ cc_library(
1113
copts = copts,
1214
)
1315

14-
cc_library(
15-
name = "meta",
16-
srcs = ["meta-dylib.cc"],
16+
# Convenient targets
17+
[cc_ecsact_dylib(
18+
name = m,
19+
copts = copts,
20+
ecsact_modules = [m],
21+
) for m in ecsact_runtime_modules]
22+
23+
cc_ecsact_dylib(
24+
name = "full",
1725
copts = copts,
18-
defines = ["ECSACT_META_API_LOAD_AT_RUNTIME"],
19-
deps = [
20-
":util",
21-
"//:meta",
22-
],
26+
ecsact_modules = ecsact_runtime_modules,
2327
)

dylib/README.md

Whitespace-only changes.

dylib/dylib.cc

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,48 @@
22
#include <cassert>
33
#include "ecsact/runtime/dylib.h"
44

5+
#ifdef ECSACT_ASYNC_API_LOAD_AT_RUNTIME
6+
# include "ecsact/runtime/async.h"
7+
#endif
8+
9+
#ifdef ECSACT_CORE_API_LOAD_AT_RUNTIME
10+
# include "ecsact/runtime/core.h"
11+
#endif
12+
13+
#ifdef ECSACT_DYNAMIC_API_LOAD_AT_RUNTIME
14+
# include "ecsact/runtime/dynamic.h"
15+
#endif
16+
517
#ifdef ECSACT_META_API_LOAD_AT_RUNTIME
618
# include "ecsact/runtime/meta.h"
719
#endif
820

21+
#ifdef ECSACT_SERIALIZE_API_LOAD_AT_RUNTIME
22+
# include "ecsact/runtime/serialize.h"
23+
#endif
24+
25+
#include "./dylib-util.hh"
26+
27+
#ifdef ECSACT_ASYNC_API_LOAD_AT_RUNTIME
28+
FOR_EACH_ECSACT_ASYNC_API_FN(ECSACT_DYLIB_UTIL_FN_PTR_DEFN);
29+
#endif
30+
31+
#ifdef ECSACT_CORE_API_LOAD_AT_RUNTIME
32+
FOR_EACH_ECSACT_CORE_API_FN(ECSACT_DYLIB_UTIL_FN_PTR_DEFN);
33+
#endif
34+
35+
#ifdef ECSACT_DYNAMIC_API_LOAD_AT_RUNTIME
36+
FOR_EACH_ECSACT_DYNAMIC_API_FN(ECSACT_DYLIB_UTIL_FN_PTR_DEFN);
37+
#endif
38+
39+
#ifdef ECSACT_META_API_LOAD_AT_RUNTIME
40+
FOR_EACH_ECSACT_META_API_FN(ECSACT_DYLIB_UTIL_FN_PTR_DEFN);
41+
#endif
42+
43+
#ifdef ECSACT_SERIALIZE_API_LOAD_AT_RUNTIME
44+
FOR_EACH_ECSACT_SERIALIZE_API_FN(ECSACT_DYLIB_UTIL_FN_PTR_DEFN);
45+
#endif
46+
947
#define HAS_FN_CHECK(fn_name, target_fn_name) \
1048
if(std::strcmp(target_fn_name, #fn_name) == 0) return true
1149

@@ -16,9 +54,26 @@
1654
static_assert(true, "macro requires ;")
1755

1856
bool ecsact_dylib_has_fn(const char* fn_name) {
57+
#ifdef ECSACT_ASYNC_API_LOAD_AT_RUNTIME
58+
FOR_EACH_ECSACT_ASYNC_API_FN(HAS_FN_CHECK, fn_name);
59+
#endif
60+
61+
#ifdef ECSACT_CORE_API_LOAD_AT_RUNTIME
62+
FOR_EACH_ECSACT_CORE_API_FN(HAS_FN_CHECK, fn_name);
63+
#endif
64+
65+
#ifdef ECSACT_DYNAMIC_API_LOAD_AT_RUNTIME
66+
FOR_EACH_ECSACT_DYNAMIC_API_FN(HAS_FN_CHECK, fn_name);
67+
#endif
68+
1969
#ifdef ECSACT_META_API_LOAD_AT_RUNTIME
2070
FOR_EACH_ECSACT_META_API_FN(HAS_FN_CHECK, fn_name);
2171
#endif
72+
73+
#ifdef ECSACT_SERIALIZE_API_LOAD_AT_RUNTIME
74+
FOR_EACH_ECSACT_SERIALIZE_API_FN(HAS_FN_CHECK, fn_name);
75+
#endif
76+
2277
return false;
2378
}
2479

@@ -30,7 +85,23 @@ void ecsact_dylib_set_fn_addr(const char* fn_name, void (*fn_ptr)()) {
3085
}
3186
#endif // NDEBUG
3287

88+
#ifdef ECSACT_ASYNC_API_LOAD_AT_RUNTIME
89+
FOR_EACH_ECSACT_ASYNC_API_FN(ASSIGN_FN_IF, fn_name, fn_ptr);
90+
#endif
91+
92+
#ifdef ECSACT_CORE_API_LOAD_AT_RUNTIME
93+
FOR_EACH_ECSACT_CORE_API_FN(ASSIGN_FN_IF, fn_name, fn_ptr);
94+
#endif
95+
96+
#ifdef ECSACT_DYNAMIC_API_LOAD_AT_RUNTIME
97+
FOR_EACH_ECSACT_DYNAMIC_API_FN(ASSIGN_FN_IF, fn_name, fn_ptr);
98+
#endif
99+
33100
#ifdef ECSACT_META_API_LOAD_AT_RUNTIME
34101
FOR_EACH_ECSACT_META_API_FN(ASSIGN_FN_IF, fn_name, fn_ptr);
35102
#endif
103+
104+
#ifdef ECSACT_SERIALIZE_API_LOAD_AT_RUNTIME
105+
FOR_EACH_ECSACT_SERIALIZE_API_FN(ASSIGN_FN_IF, fn_name, fn_ptr);
106+
#endif
36107
}

dylib/index.bzl

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,16 @@ def cc_ecsact_dylib(name = None, srcs = [], ecsact_modules = [], deps = [], defi
1717
defines: Passed to underlying cc_library
1818
**kwargs: Passed to underlying cc_library
1919
"""
20-
srcs.append("@ecsact_runtime//dylib:dylib.cc")
21-
deps.append("@ecsact_runtime//:dylib")
2220

2321
for ecsact_module in ecsact_modules:
2422
if not ecsact_module in ecsact_runtime_modules:
2523
fail("Invalid ecsact module '{}'\nAllowed values: {}".format(ecsact_module, ",".join(ecsact_runtime_modules)))
2624

27-
deps.append("@ecsact_runtime//dylib:{}".format(ecsact_module))
28-
defines.append("ECSACT_{}_API_LOAD_AT_RUNTIME".format(ecsact_module.upper()))
29-
3025
cc_library(
3126
name = name,
32-
deps = deps,
33-
defines = defines,
27+
deps = deps + ["@ecsact_runtime//:dylib", "@ecsact_runtime//dylib:util"] + ["@ecsact_runtime//:{}".format(m) for m in ecsact_modules],
28+
srcs = srcs + ["@ecsact_runtime//dylib:dylib.cc"],
29+
defines = defines +
30+
["ECSACT_{}_API_LOAD_AT_RUNTIME".format(m.upper()) for m in ecsact_modules],
3431
**kwargs
3532
)

dylib/meta-dylib.cc

Lines changed: 0 additions & 9 deletions
This file was deleted.

ecsact/runtime/dynamic.h

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#ifndef ECSACT_RUNTIME_DYNAMIC_H
22
#define ECSACT_RUNTIME_DYNAMIC_H
33

4-
#include <stdlib.h>
4+
#include <stdbool.h>
5+
#include <stdint.h>
56

67
#include "ecsact/runtime/common.h"
78
#include "ecsact/runtime/definitions.h"
@@ -51,8 +52,8 @@
5152
*/
5253
ECSACT_DYNAMIC_API_FN(void, ecsact_system_execution_context_action)
5354
( //
54-
ecsact_system_execution_context* context,
55-
void* out_action_data
55+
struct ecsact_system_execution_context* context,
56+
void* out_action_data
5657
);
5758

5859
/**
@@ -63,9 +64,9 @@ ECSACT_DYNAMIC_API_FN(void, ecsact_system_execution_context_action)
6364
*/
6465
ECSACT_DYNAMIC_API_FN(void, ecsact_system_execution_context_add)
6566
( //
66-
ecsact_system_execution_context* context,
67-
ecsact_component_like_id component_id,
68-
const void* component_data
67+
struct ecsact_system_execution_context* context,
68+
ecsact_component_like_id component_id,
69+
const void* component_data
6970
);
7071

7172
/**
@@ -77,8 +78,8 @@ ECSACT_DYNAMIC_API_FN(void, ecsact_system_execution_context_add)
7778
*/
7879
ECSACT_DYNAMIC_API_FN(void, ecsact_system_execution_context_remove)
7980
( //
80-
ecsact_system_execution_context* context,
81-
ecsact_component_like_id component_id
81+
struct ecsact_system_execution_context* context,
82+
ecsact_component_like_id component_id
8283
);
8384

8485
/**
@@ -96,9 +97,9 @@ ECSACT_DYNAMIC_API_FN(void, ecsact_system_execution_context_remove)
9697
*/
9798
ECSACT_DYNAMIC_API_FN(void, ecsact_system_execution_context_get)
9899
( //
99-
ecsact_system_execution_context* context,
100-
ecsact_component_like_id component_id,
101-
void* out_component_data
100+
struct ecsact_system_execution_context* context,
101+
ecsact_component_like_id component_id,
102+
void* out_component_data
102103
);
103104

104105
/**
@@ -110,9 +111,9 @@ ECSACT_DYNAMIC_API_FN(void, ecsact_system_execution_context_get)
110111
*/
111112
ECSACT_DYNAMIC_API_FN(void, ecsact_system_execution_context_update)
112113
( //
113-
ecsact_system_execution_context* context,
114-
ecsact_component_like_id component_id,
115-
const void* component_data
114+
struct ecsact_system_execution_context* context,
115+
ecsact_component_like_id component_id,
116+
const void* component_data
116117
);
117118

118119
/**
@@ -126,8 +127,8 @@ ECSACT_DYNAMIC_API_FN(void, ecsact_system_execution_context_update)
126127
*/
127128
ECSACT_DYNAMIC_API_FN(bool, ecsact_system_execution_context_has)
128129
( //
129-
ecsact_system_execution_context* context,
130-
ecsact_component_like_id component_id
130+
struct ecsact_system_execution_context* context,
131+
ecsact_component_like_id component_id
131132
);
132133

133134
/**
@@ -143,10 +144,10 @@ ECSACT_DYNAMIC_API_FN(bool, ecsact_system_execution_context_has)
143144
*/
144145
ECSACT_DYNAMIC_API_FN(void, ecsact_system_execution_context_generate)
145146
( //
146-
ecsact_system_execution_context* context,
147-
int component_count,
148-
ecsact_component_id* component_ids,
149-
const void** components_data
147+
struct ecsact_system_execution_context* context,
148+
int component_count,
149+
ecsact_component_id* component_ids,
150+
const void** components_data
150151
);
151152

152153
/**
@@ -155,11 +156,11 @@ ECSACT_DYNAMIC_API_FN(void, ecsact_system_execution_context_generate)
155156
* Only available if the currently executing system is a nested system.
156157
*/
157158
ECSACT_DYNAMIC_API_FN(
158-
const ecsact_system_execution_context*,
159+
const struct ecsact_system_execution_context*,
159160
ecsact_system_execution_context_parent
160161
)
161162
( //
162-
ecsact_system_execution_context* context
163+
struct ecsact_system_execution_context* context
163164
);
164165

165166
/**
@@ -171,8 +172,8 @@ ECSACT_DYNAMIC_API_FN(
171172
*/
172173
ECSACT_DYNAMIC_API_FN(bool, ecsact_system_execution_context_same)
173174
( //
174-
const ecsact_system_execution_context*,
175-
const ecsact_system_execution_context*
175+
const struct ecsact_system_execution_context*,
176+
const struct ecsact_system_execution_context*
176177
);
177178

178179
/**
@@ -184,28 +185,28 @@ ECSACT_DYNAMIC_API_FN(bool, ecsact_system_execution_context_same)
184185
* - `ECSACT_SYS_CAP_OPTIONAL_READWRITE`
185186
*/
186187
ECSACT_DYNAMIC_API_FN(
187-
ecsact_system_execution_context*,
188+
struct ecsact_system_execution_context*,
188189
ecsact_system_execution_context_other
189190
)
190191
( //
191-
ecsact_system_execution_context* context,
192-
ecsact_entity_id entity_id
192+
struct ecsact_system_execution_context* context,
193+
ecsact_entity_id entity_id
193194
);
194195

195196
/**
196197
* Get the entity for the execution context
197198
*/
198199
ECSACT_DYNAMIC_API_FN(ecsact_entity_id, ecsact_system_execution_context_entity)
199200
( //
200-
const ecsact_system_execution_context* context
201+
const struct ecsact_system_execution_context* context
201202
);
202203

203204
/**
204205
* Get the current system/action ID
205206
*/
206207
ECSACT_DYNAMIC_API_FN(ecsact_system_like_id, ecsact_system_execution_context_id)
207208
( //
208-
ecsact_system_execution_context* context
209+
struct ecsact_system_execution_context* context
209210
);
210211

211212
ECSACT_DYNAMIC_API_FN(ecsact_package_id, ecsact_create_package)

0 commit comments

Comments
 (0)