From 2e76f7cd6974f5356d683920eb4e9977fe60d1f0 Mon Sep 17 00:00:00 2001 From: John Rehbein Date: Mon, 12 Aug 2024 00:02:25 +0000 Subject: [PATCH] Improve C compatibility --- .github/workflows/ci-build.yml | 13 ++++++++----- Source/ThirdParty/netarch/sam2.c | 8 ++++++++ Source/UnrealLibretro/Private/sam2.h | 2 +- Source/UnrealLibretro/Private/ulnet.h | 11 ++++++++++- 4 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 Source/ThirdParty/netarch/sam2.c diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index d003446..78a2491 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -15,10 +15,13 @@ jobs: run: cmake -S . -B build -DCMAKE_BUILD_TYPE=Release - name: Build (GCC) run: cmake --build build --config Release -# - name: Configure CMake (Linux TCC) -# run: cmake -S . -B build-tcc -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=tcc -# - name: Build (TCC) -# run: cmake --build build-tcc --config Release + # Check that our C code is reasonably portable + - name: Build with TCC + run: | + tcc -c Source/ThirdParty/netarch/sam2.c \ + -ISource/UnrealLibretro/Private \ + -ISource/ThirdParty/zstd/lib \ + -ISource/ThirdParty/libjuice/include build-macos: runs-on: macos-latest @@ -44,4 +47,4 @@ jobs: - name: Configure CMake (Windows MSVC) run: cmake -S . -B build -DCMAKE_BUILD_TYPE=Release - name: Build - run: cmake --build build --config Release + run: cmake --build build --config Release \ No newline at end of file diff --git a/Source/ThirdParty/netarch/sam2.c b/Source/ThirdParty/netarch/sam2.c new file mode 100644 index 0000000..4b1c723 --- /dev/null +++ b/Source/ThirdParty/netarch/sam2.c @@ -0,0 +1,8 @@ +#define SAM2_IMPLEMENTATION +#define SAM2_SERVER +#define SAM2_EXECUTABLE + +#define ULNET_IMPLEMENTATION + +#include "ulnet.h" +#include "sam2.h" diff --git a/Source/UnrealLibretro/Private/sam2.h b/Source/UnrealLibretro/Private/sam2.h index 644c385..a7c095e 100644 --- a/Source/UnrealLibretro/Private/sam2.h +++ b/Source/UnrealLibretro/Private/sam2.h @@ -1721,7 +1721,7 @@ int main() { // Setup signal handler uv_signal_t sig; - uv_signal_init(&server->loop, &sig); + uv_signal_init(&server.loop, &sig); sig.data = &server; uv_signal_start(&sig, on_signal, SIGINT); diff --git a/Source/UnrealLibretro/Private/ulnet.h b/Source/UnrealLibretro/Private/ulnet.h index b8be7b5..f351d5b 100644 --- a/Source/UnrealLibretro/Private/ulnet.h +++ b/Source/UnrealLibretro/Private/ulnet.h @@ -1,11 +1,15 @@ +#ifndef ULNET_H +#define ULNET_H + #include "sam2.h" -#include "juice/juice.h" +typedef struct juice_agent juice_agent_t; #include "zstd.h" #include "common/xxhash.h" #include "fec.h" #include +#include #ifndef ULNET_LINKAGE #ifdef __cplusplus @@ -256,8 +260,11 @@ static inline void ulnet__xor_delta(void *dest, void *src, int size) { ((uint8_t *) dest)[i] ^= ((uint8_t *) src)[i]; } } +#endif #if defined(ULNET_IMPLEMENTATION) +#ifndef ULNET_C +#define ULNET_C #if defined(ULNET_IMGUI) #include "imgui.h" #include "implot.h" @@ -266,6 +273,7 @@ static inline void ulnet__xor_delta(void *dest, void *src, int size) { #define IMH(statement) #endif +#include "juice/juice.h" #include #include @@ -1553,3 +1561,4 @@ ULNET_LINKAGE void ulnet_send_save_state(ulnet_session_t *session, juice_agent_t free(savestate_transfer_payload); } #endif +#endif