Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,31 @@ jobs:
run: |
bake --strict

build-emscripten:
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
fail-fast: false

steps:
- uses: actions/checkout@v4

- name: install compiler
run: |
sudo apt-get update
sudo apt-get install -y emscripten

- name: install bake
run: |
git clone https://github.com/SanderMertens/bake
make -C bake/build-$(uname)
bake/bake setup
bake/bake setup --target em

- name: build flecs
run: |
bake --strict --target em

build-windows:
runs-on: windows-latest
timeout-minutes: 30
Expand Down Expand Up @@ -232,6 +257,45 @@ jobs:
cmake -DFLECS_STRICT=ON ..
cmake --build . -j 4

build-cmake-emscripten:
needs: build-emscripten
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
fail-fast: false

steps:
- uses: actions/checkout@v4

- name: install compiler
run: |
sudo apt-get update
sudo apt-get install -y emscripten

- name: create cmake build folders
run: |
mkdir cmake_build
mkdir examples/c/cmake_build
mkdir examples/cpp/cmake_build

- name: build flecs
working-directory: cmake_build
run: |
emcmake cmake -DFLECS_STRICT=ON ..
emcmake cmake --build . -j 4

- name: build c examples
working-directory: examples/c/cmake_build
run: |
emcmake cmake -DFLECS_STRICT=ON ..
emcmake cmake --build . -j 4

- name: build c++ examples
working-directory: examples/cpp/cmake_build
run: |
emcmake cmake -DFLECS_STRICT=ON ..
emcmake cmake --build . -j 4

build-cmake-windows:
needs: build-windows
runs-on: windows-latest
Expand Down Expand Up @@ -634,6 +698,52 @@ jobs:
- name: test c++
run: bake run test/cpp -- -j 8

test-emscripten:
needs: build-emscripten
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
fail-fast: false

steps:
- uses: actions/checkout@v4

- name: install compiler
run: |
sudo apt-get update
sudo apt-get install -y emscripten

- name: install bake
run: |
git clone https://github.com/SanderMertens/bake
make -C bake/build-$(uname)
bake/bake setup
bake/bake setup --target em

- name: build flecs
run: bake --strict --target em

- name: test core
run: bake run test/core --target em -- -j 8

- name: test query
run: bake run test/query --target em -- -j 8

- name: test addons
run: bake run test/addons --target em -- -j 8

- name: test meta
run: bake run test/meta --target em -- -j 8

- name: test script
run: bake run test/script --target em -- -j 8

- name: test collections
run: bake run test/collections --target em -- -j 8

- name: test c++
run: bake run test/cpp --target em -- -j 8

test-windows:
needs: build-windows
runs-on: windows-latest
Expand Down
10 changes: 5 additions & 5 deletions distr/flecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ typedef struct ecs_table_diff_t {
} ecs_table_diff_t;

/** Edge linked list (used to keep track of incoming edges) */
typedef struct ecs_graph_edge_hdr_t {
typedef struct ECS_ALIGNAS(8) ecs_graph_edge_hdr_t {
struct ecs_graph_edge_hdr_t *prev;
struct ecs_graph_edge_hdr_t *next;
} ecs_graph_edge_hdr_t;
Expand Down Expand Up @@ -745,7 +745,7 @@ typedef struct ecs_table_cache_list_t {
} ecs_table_cache_list_t;

/** Table cache */
typedef struct ecs_table_cache_t {
typedef struct ECS_ALIGNAS(8) ecs_table_cache_t {
ecs_map_t index; /* <table_id, T*> */
ecs_table_cache_list_t tables;
} ecs_table_cache_t;
Expand Down Expand Up @@ -20553,9 +20553,9 @@ char* flecs_explorer_request(const char *method, char *request, char *body) {
if (reply.code == 200) {
return ecs_strbuf_get(&reply.body);
} else {
char *body = ecs_strbuf_get(&reply.body);
if (body) {
return body;
char *reply_body = ecs_strbuf_get(&reply.body);
if (reply_body) {
return reply_body;
} else {
return flecs_asprintf(
"{\"error\": \"bad request\", \"status\": %d}", reply.code);
Expand Down
12 changes: 10 additions & 2 deletions distr/flecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,14 @@ typedef struct ecs_allocator_t ecs_allocator_t;
#define ECS_ALIGNOF(T) ((int64_t)&((struct { char c; T d; } *)0)->d)
#endif

#if defined(ECS_TARGET_GNU)
#define ECS_ALIGNAS(N) __attribute__((aligned(N)))
#elif defined(ECS_TARGET_MSVC)
#define ECS_ALIGNAS(N) __declspec(align(N))
#else
#define ECS_ALIGNAS(N)
#endif

#ifndef FLECS_NO_DEPRECATED_WARNINGS
#if defined(ECS_TARGET_GNU)
#define ECS_DEPRECATED(msg) __attribute__((deprecated(msg)))
Expand Down Expand Up @@ -3223,7 +3231,7 @@ struct ecs_record_t {
};

/** Header for table cache elements. */
typedef struct ecs_table_cache_hdr_t {
typedef struct ECS_ALIGNAS(8) ecs_table_cache_hdr_t {
struct ecs_table_cache_t *cache; /**< Table cache of element. Of type ecs_id_record_t* for component index elements. */
ecs_table_t *table; /**< Table associated with element. */
struct ecs_table_cache_hdr_t *prev, *next; /**< Next/previous elements for id in table cache. */
Expand Down Expand Up @@ -14509,7 +14517,7 @@ typedef struct ecs_script_vars_t {
} ecs_script_vars_t;

/** Script object. */
typedef struct ecs_script_t {
typedef struct ECS_ALIGNAS(8) ecs_script_t {
ecs_world_t *world;
const char *name;
const char *code;
Expand Down
2 changes: 1 addition & 1 deletion include/flecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ struct ecs_record_t {
};

/** Header for table cache elements. */
typedef struct ecs_table_cache_hdr_t {
typedef struct ECS_ALIGNAS(8) ecs_table_cache_hdr_t {
struct ecs_table_cache_t *cache; /**< Table cache of element. Of type ecs_id_record_t* for component index elements. */
ecs_table_t *table; /**< Table associated with element. */
struct ecs_table_cache_hdr_t *prev, *next; /**< Next/previous elements for id in table cache. */
Expand Down
2 changes: 1 addition & 1 deletion include/flecs/addons/script.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ typedef struct ecs_script_vars_t {
} ecs_script_vars_t;

/** Script object. */
typedef struct ecs_script_t {
typedef struct ECS_ALIGNAS(8) ecs_script_t {
ecs_world_t *world;
const char *name;
const char *code;
Expand Down
8 changes: 8 additions & 0 deletions include/flecs/private/api_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,14 @@ typedef struct ecs_allocator_t ecs_allocator_t;
#define ECS_ALIGNOF(T) ((int64_t)&((struct { char c; T d; } *)0)->d)
#endif

#if defined(ECS_TARGET_GNU)
#define ECS_ALIGNAS(N) __attribute__((aligned(N)))
#elif defined(ECS_TARGET_MSVC)
#define ECS_ALIGNAS(N) __declspec(align(N))
#else
#define ECS_ALIGNAS(N)
#endif

#ifndef FLECS_NO_DEPRECATED_WARNINGS
#if defined(ECS_TARGET_GNU)
#define ECS_DEPRECATED(msg) __attribute__((deprecated(msg)))
Expand Down
6 changes: 3 additions & 3 deletions src/addons/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ char* flecs_explorer_request(const char *method, char *request, char *body) {
if (reply.code == 200) {
return ecs_strbuf_get(&reply.body);
} else {
char *body = ecs_strbuf_get(&reply.body);
if (body) {
return body;
char *reply_body = ecs_strbuf_get(&reply.body);
if (reply_body) {
return reply_body;
} else {
return flecs_asprintf(
"{\"error\": \"bad request\", \"status\": %d}", reply.code);
Expand Down
2 changes: 1 addition & 1 deletion src/addons/script/ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ typedef enum ecs_script_node_kind_t {
EcsAstFor
} ecs_script_node_kind_t;

typedef struct ecs_script_node_t {
typedef struct ECS_ALIGNAS(8) ecs_script_node_t {
ecs_script_node_kind_t kind;
const char *pos;
} ecs_script_node_t;
Expand Down
2 changes: 1 addition & 1 deletion src/private_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ typedef struct ecs_table_cache_list_t {
} ecs_table_cache_list_t;

/** Table cache */
typedef struct ecs_table_cache_t {
typedef struct ECS_ALIGNAS(8) ecs_table_cache_t {
ecs_map_t index; /* <table_id, T*> */
ecs_table_cache_list_t tables;
} ecs_table_cache_t;
Expand Down
2 changes: 1 addition & 1 deletion src/storage/table_graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ typedef struct ecs_table_diff_t {
} ecs_table_diff_t;

/** Edge linked list (used to keep track of incoming edges) */
typedef struct ecs_graph_edge_hdr_t {
typedef struct ECS_ALIGNAS(8) ecs_graph_edge_hdr_t {
struct ecs_graph_edge_hdr_t *prev;
struct ecs_graph_edge_hdr_t *next;
} ecs_graph_edge_hdr_t;
Expand Down