From d7cd4ff3ae10cc75e006f1b927d831899810e4a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=9A=93?= Date: Mon, 10 Feb 2025 18:58:47 -0500 Subject: [PATCH 1/2] Implement serialization for big-endian platforms --- src/util/serial-util.h | 50 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/src/util/serial-util.h b/src/util/serial-util.h index 45a6bde..49e9f6f 100644 --- a/src/util/serial-util.h +++ b/src/util/serial-util.h @@ -23,14 +23,11 @@ #define SERIALUTIL_H #include +#include #include #include -#if SDL_BYTEORDER != SDL_LIL_ENDIAN -#error "Non little endian systems not supported" -#endif - static inline int32_t readInt32(const char **dataP) { @@ -39,23 +36,56 @@ readInt32(const char **dataP) memcpy(&result, *dataP, 4); *dataP += 4; +#if SDL_BYTEORDER == SDL_BIG_ENDIAN +# ifdef _MSC_VER + static_assert(sizeof(unsigned long) == sizeof(int32_t), "unsigned long should be 32 bits"); + result = (int32_t)_byteswap_ulong((unsigned long)result); +# else + result = (int32_t)__builtin_bswap32((uint32_t)result); +# endif +#endif + return result; } static inline double readDouble(const char **dataP) { +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + uint64_t result; + + memcpy(&result, *dataP, 8); + *dataP += 8; + +# ifdef _MSC_VER + result = (uint64_t)_byteswap_uint64((unsigned __int64)result); +# else + result = __builtin_bswap64(result); +# endif + + return *(double *)&result; +#else double result; memcpy(&result, *dataP, 8); *dataP += 8; return result; +#endif } static inline void writeInt32(char **dataP, int32_t value) { +#if SDL_BYTEORDER == SDL_BIG_ENDIAN +# ifdef _MSC_VER + static_assert(sizeof(unsigned long) == sizeof(int32_t), "unsigned long should be 32 bits"); + value = (int32_t)_byteswap_ulong((unsigned long)value); +# else + value = (int32_t)__builtin_bswap32((uint32_t)value); +# endif +#endif + memcpy(*dataP, &value, 4); *dataP += 4; } @@ -63,7 +93,19 @@ writeInt32(char **dataP, int32_t value) static inline void writeDouble(char **dataP, double value) { +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + uint64_t valueUint = *(uint64_t *)&value; + +# ifdef _MSC_VER + valueUint = (uint64_t)_byteswap_uint64((unsigned __int64)valueUint); +# else + valueUint = __builtin_bswap64(valueUint); +# endif + + memcpy(*dataP, &valueUint, 8); +#else memcpy(*dataP, &value, 8); +#endif *dataP += 8; } From 0f6611f19f5ac304709fbb3a96759d12ade89eac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=9A=93?= Date: Mon, 10 Feb 2025 21:25:46 -0500 Subject: [PATCH 2/2] Upgrade actions to v4 No need for double-zipping anymore since the upload artifact action preserves +x permissions now. --- .github/workflows/autobuild.yml | 45 +++++++++++---------------------- 1 file changed, 15 insertions(+), 30 deletions(-) diff --git a/.github/workflows/autobuild.yml b/.github/workflows/autobuild.yml index 275f7bf..d72ab6f 100644 --- a/.github/workflows/autobuild.yml +++ b/.github/workflows/autobuild.yml @@ -22,7 +22,6 @@ jobs: - uses: msys2/setup-msys2@v2 with: msystem: mingw64 - # zip is just used for artifact compression at the end. install: >- base-devel git @@ -32,13 +31,11 @@ jobs: mingw-w64-x86_64-meson mingw-w64-x86_64-autotools mingw-w64-x86_64-gcc - zip - - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - - uses: actions/cache@v3 + - uses: actions/cache@v4 with: path: | windows/build-mingw64 @@ -73,16 +70,11 @@ jobs: cp ../../mkxp.json . cp -r ../../scripts . cp ../../assets/LICENSE.mkxp-z-with-https.txt . - cd .. - # Zipping before uploading decreases the upload time considerably. - # Unfortunately this results in double-zipping; tracked at: - # https://github.com/actions/upload-artifact/issues/426 - zip -r artifact.zip artifact - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 with: name: mkxp-z.windows.${{github.event_name == 'pull_request' && format('PR{0}', github.event.number) || github.ref_name}}-${{steps.short-sha.outputs.sha}} - path: build/artifact.zip + path: build/artifact build-linux-native: name: Ubuntu 22.04 x86_64 @@ -94,9 +86,9 @@ jobs: length: 7 - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - - uses: actions/cache@v3 + - uses: actions/cache@v4 with: path: | linux/build-x86_64 @@ -129,16 +121,11 @@ jobs: cp ../../mkxp.json . cp -r ../../scripts . cp ../../assets/LICENSE.mkxp-z-with-https.txt . - cd .. - # Zipping before uploading preserves +x permissions. - # Unfortunately this results in double-zipping; tracked at: - # https://github.com/actions/upload-artifact/issues/426 - zip -r local.zip local - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 with: name: mkxp-z.linux.x86_64.${{github.event_name == 'pull_request' && format('PR{0}', github.event.number) || github.ref_name}}-${{steps.short-sha.outputs.sha}} - path: build/local.zip + path: build/local build-linux-cross: name: Ubuntu 22.04 ${{matrix.arch_mkxpz}} @@ -190,9 +177,9 @@ jobs: length: 7 - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - - uses: actions/cache@v3 + - uses: actions/cache@v4 with: path: | linux/build-${{matrix.arch_mkxpz}} @@ -240,13 +227,11 @@ jobs: cp ../../mkxp.json . cp -r ../../scripts . cp ../../assets/LICENSE.mkxp-z-with-https.txt . - cd .. - zip -r local.zip local - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 with: name: mkxp-z.linux.${{matrix.arch_mkxpz}}.${{github.event_name == 'pull_request' && format('PR{0}', github.event.number) || github.ref_name}}-${{steps.short-sha.outputs.sha}} - path: build/local.zip + path: build/local build-macos: name: macOS @@ -261,9 +246,9 @@ jobs: run: brew remove --force $(brew list) - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - - uses: actions/cache@v3 + - uses: actions/cache@v4 with: path: | macos/Dependencies/build-macosx-x86_64 @@ -294,7 +279,7 @@ jobs: ditto -c -k --sequesterRsrc --keepParent Z-universal.app Z-universal.app.zip - name: Upload archive - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: mkxp-z.macos.${{github.event_name == 'pull_request' && format('PR{0}', github.event.number) || github.ref_name}}-${{steps.short-sha.outputs.sha}} path: build/Build/Products/Release/Z-universal.app.zip