From 331122acac873f2defd1bd714adb02eee1c7d778 Mon Sep 17 00:00:00 2001 From: Markus Kalkbrenner Date: Wed, 21 Dec 2022 15:42:45 +0100 Subject: [PATCH 01/11] added github action --- .github/workflows/libserum.yml | 91 ++++++++++++++++++++++++++++++++++ CMakeLists.txt | 3 +- 2 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/libserum.yml diff --git a/.github/workflows/libserum.yml b/.github/workflows/libserum.yml new file mode 100644 index 0000000..45d3796 --- /dev/null +++ b/.github/workflows/libserum.yml @@ -0,0 +1,91 @@ +name: libserum +on: + push: + +env: + VERSION_START_SHA: e87be0e3cfa66411976ca04a72dd29e36c483966 + +defaults: + run: + shell: bash + +jobs: + version: + name: Version + runs-on: ubuntu-latest + outputs: + version: ${{ steps.version.outputs.version }} + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - id: version + run: | + VERSION=$(grep -Eo "[0-9\.]+" CMakeLists.txt | head -2 | tail -1) + echo "version=${VERSION}" >> $GITHUB_OUTPUT + + build: + name: Build libserum-${{ matrix.platform }} + runs-on: ${{ matrix.os }} + needs: [ version ] + strategy: + fail-fast: false + matrix: + include: + - os: windows-latest + platform: win-x64 + platform-name: x64 + libserum: libserum-${{ needs.version.outputs.version }}.dll + - os: windows-latest + platform: win-x86 + platform-name: Win32 + libserum: libserum-${{ needs.version.outputs.version }}.dll + - os: macos-latest + platform: osx-x64 + libserum: libserum.${{ needs.version.outputs.version }}.dylib + - os: macos-latest + platform: osx-arm64 + libserum: libserum.${{ needs.version.outputs.version }}.dylib + - os: macos-latest + platform: ios-arm64 + libserum: libserum.${{ needs.version.outputs.version }}.a + - os: ubuntu-18.04 + platform: linux-x64 + libserum: libserum.so.${{ needs.version.outputs.version }} + - os: ubuntu-18.04 + platform: android-arm64-v8a + libserum: libserum.${{ needs.version.outputs.version }}.so + steps: + - uses: actions/checkout@v3 + - name: Build libserum-${{ matrix.platform }} + run: | + if [[ "${{ matrix.os }}" == "windows-latest" ]]; then + cmake -G "Visual Studio 17 2022" -A ${{ matrix.platform-name }} -B build + cmake --build build --config Release + else + cmake -DCMAKE_BUILD_TYPE=Release -B build/Release + cmake --build build/Release + fi + - run: | + mkdir tmp + cp build/Release/${{ matrix.libserum }} tmp + - uses: actions/upload-artifact@v3 + with: + name: libserum-${{ needs.version.outputs.tag }}-${{ matrix.platform }} + path: tmp + + post-build: + runs-on: macos-latest + needs: [ version, build ] + name: Build libserum-osx + steps: + - uses: actions/download-artifact@v3 + - run: | + mkdir tmp + lipo -create -output tmp/libserum.${{ needs.version.outputs.version }}.dylib \ + libserum-${{ needs.version.outputs.tag }}-osx-x64/libserum.${{ needs.version.outputs.version }}.dylib \ + libserum-${{ needs.version.outputs.tag }}-osx-arm64/libserum.${{ needs.version.outputs.version }}.dylib + - uses: actions/upload-artifact@v3 + with: + name: libserum-${{ needs.version.outputs.tag }}-osx + path: tmp diff --git a/CMakeLists.txt b/CMakeLists.txt index 618ff73..dd28901 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,7 @@ cmake_minimum_required(VERSION 3.9) -project(serum VERSION 0.1.0 DESCRIPTION "Cross-platform library for decoding Serum files, a colorization format for pinball ROMs.") +project(serum VERSION 0.1.0 DESCRIPTION + "Cross-platform library for decoding Serum files, a colorization format for pinball ROMs.") set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_VISIBILITY_PRESET hidden) From 3bc9ecb4204b893c5f4e696ea7cb675ff7ace8f1 Mon Sep 17 00:00:00 2001 From: Markus Kalkbrenner Date: Wed, 21 Dec 2022 15:49:18 +0100 Subject: [PATCH 02/11] use ubuntu-latest --- .github/workflows/libserum.yml | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/.github/workflows/libserum.yml b/.github/workflows/libserum.yml index 45d3796..25b7b69 100644 --- a/.github/workflows/libserum.yml +++ b/.github/workflows/libserum.yml @@ -2,9 +2,6 @@ name: libserum on: push: -env: - VERSION_START_SHA: e87be0e3cfa66411976ca04a72dd29e36c483966 - defaults: run: shell: bash @@ -46,13 +43,10 @@ jobs: - os: macos-latest platform: osx-arm64 libserum: libserum.${{ needs.version.outputs.version }}.dylib - - os: macos-latest - platform: ios-arm64 - libserum: libserum.${{ needs.version.outputs.version }}.a - - os: ubuntu-18.04 + - os: ubuntu-latest platform: linux-x64 libserum: libserum.so.${{ needs.version.outputs.version }} - - os: ubuntu-18.04 + - os: ubuntu-latest platform: android-arm64-v8a libserum: libserum.${{ needs.version.outputs.version }}.so steps: From 57fa59e52639bdcb4479ec21863e215cfc22ea8c Mon Sep 17 00:00:00 2001 From: Markus Kalkbrenner Date: Wed, 21 Dec 2022 16:02:45 +0100 Subject: [PATCH 03/11] applied https://github.com/tfussell/miniz-cpp/pull/7 --- src/miniz/zip_file.hpp | 50 +++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/miniz/zip_file.hpp b/src/miniz/zip_file.hpp index c324f70..9adf560 100644 --- a/src/miniz/zip_file.hpp +++ b/src/miniz/zip_file.hpp @@ -509,13 +509,13 @@ const char *mz_error(int err); // ------------------- Types and macros -typedef unsigned char mz_uint8; -typedef signed short mz_int16; -typedef unsigned short mz_uint16; -typedef unsigned int mz_uint32; +typedef uint8_t mz_uint8; +typedef int16_t mz_int16; +typedef uint16_t mz_uint16; +typedef uint32_t mz_uint32; typedef unsigned int mz_uint; -typedef long long mz_int64; -typedef unsigned long long mz_uint64; +typedef int64_t mz_int64; +typedef uint64_t mz_uint64; typedef int mz_bool; #define MZ_FALSE (0) @@ -4981,7 +4981,7 @@ char alt_directory_separator = '\\'; std::string join_path(const std::vector &parts) { std::string joined; - std::size_t i = 0; + size_t i = 0; for(auto part : parts) { joined.append(part); @@ -5029,7 +5029,7 @@ std::vector split_path(const std::string &path, char delim = direct return split; } -uint32_t crc32buf(const char *buf, std::size_t len) +uint32_t crc32buf(const char *buf, size_t len) { uint32_t oldcrc32 = 0xFFFFFFFF; @@ -5103,7 +5103,7 @@ tm safe_localtime(const time_t &t) #endif } -std::size_t write_callback(void *opaque, std::uint64_t file_ofs, const void *pBuf, std::size_t n) +size_t write_callback(void *opaque, uint64_t file_ofs, const void *pBuf, size_t n) { auto buffer = static_cast *>(opaque); @@ -5113,9 +5113,9 @@ std::size_t write_callback(void *opaque, std::uint64_t file_ofs, const void *pBu buffer->resize(new_size); } - for(std::size_t i = 0; i < n; i++) + for(size_t i = 0; i < n; i++) { - (*buffer)[static_cast(file_ofs + i)] = (static_cast(pBuf))[i]; + (*buffer)[static_cast(file_ofs + i)] = (static_cast(pBuf))[i]; } return n; @@ -5143,13 +5143,13 @@ struct zip_info uint16_t create_version = 0; uint16_t extract_version = 0; uint16_t flag_bits = 0; - std::size_t volume = 0; + size_t volume = 0; uint32_t internal_attr = 0; uint32_t external_attr = 0; - std::size_t header_offset = 0; + size_t header_offset = 0; uint32_t crc = 0; - std::size_t compress_size = 0; - std::size_t file_size = 0; + size_t compress_size = 0; + size_t file_size = 0; }; class zip_file @@ -5326,7 +5326,7 @@ class zip_file std::vector info; - for(std::size_t i = 0; i < mz_zip_reader_get_num_files(archive_.get()); i++) + for(size_t i = 0; i < mz_zip_reader_get_num_files(archive_.get()); i++) { info.push_back(getinfo(static_cast(i))); } @@ -5402,8 +5402,8 @@ class zip_file stream << " Length " << " " << " " << "Date" << " " << " " << "Time " << " " << "Name" << std::endl; stream << "--------- ---------- ----- ----" << std::endl; - std::size_t sum_length = 0; - std::size_t file_count = 0; + size_t sum_length = 0; + size_t file_count = 0; for(auto &member : infolist()) { @@ -5445,7 +5445,7 @@ class zip_file std::string read(const zip_info &info) { - std::size_t size; + size_t size; char *data = static_cast(mz_zip_reader_extract_file_to_heap(archive_.get(), info.filename.c_str(), &size, 0)); if(data == nullptr) { @@ -5570,7 +5570,7 @@ class zip_file case MZ_ZIP_MODE_READING: { mz_zip_archive archive_copy; - std::memset(&archive_copy, 0, sizeof(mz_zip_archive)); + memset(&archive_copy, 0, sizeof(mz_zip_archive)); std::vector buffer_copy(buffer_.begin(), buffer_.end()); if(!mz_zip_reader_init_mem(&archive_copy, buffer_copy.data(), buffer_copy.size(), 0)) @@ -5632,7 +5632,7 @@ class zip_file { if(buffer_.empty()) return; - std::size_t position = buffer_.size() - 1; + size_t position = buffer_.size() - 1; for(; position >= 3; position--) { @@ -5676,11 +5676,11 @@ class zip_file zip_info result; - result.filename = std::string(stat.m_filename, stat.m_filename + std::strlen(stat.m_filename)); + result.filename = std::string(stat.m_filename, stat.m_filename + strlen(stat.m_filename)); result.comment = std::string(stat.m_comment, stat.m_comment + stat.m_comment_size); - result.compress_size = static_cast(stat.m_comp_size); - result.file_size = static_cast(stat.m_uncomp_size); - result.header_offset = static_cast(stat.m_local_header_ofs); + result.compress_size = static_cast(stat.m_comp_size); + result.file_size = static_cast(stat.m_uncomp_size); + result.header_offset = static_cast(stat.m_local_header_ofs); result.crc = stat.m_crc32; auto time = detail::safe_localtime(stat.m_time); result.date_time.year = 1900 + time.tm_year; From a5e8d1899b1d230905bb4fba97567e012f4e662f Mon Sep 17 00:00:00 2001 From: Markus Kalkbrenner Date: Wed, 21 Dec 2022 16:17:30 +0100 Subject: [PATCH 04/11] linux so name --- .github/workflows/libserum.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/libserum.yml b/.github/workflows/libserum.yml index 25b7b69..8ab4a29 100644 --- a/.github/workflows/libserum.yml +++ b/.github/workflows/libserum.yml @@ -48,7 +48,7 @@ jobs: libserum: libserum.so.${{ needs.version.outputs.version }} - os: ubuntu-latest platform: android-arm64-v8a - libserum: libserum.${{ needs.version.outputs.version }}.so + libserum: libserum.so.${{ needs.version.outputs.version }} steps: - uses: actions/checkout@v3 - name: Build libserum-${{ matrix.platform }} From 1098670a77e4307edfa11eb878fa6867b004bace Mon Sep 17 00:00:00 2001 From: Markus Kalkbrenner Date: Wed, 21 Dec 2022 16:44:56 +0100 Subject: [PATCH 05/11] fixed win? --- .github/workflows/libserum.yml | 6 +++++- CMakeLists.txt | 12 +++++++++--- src/serum-decode.h | 20 ++++++++++---------- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/.github/workflows/libserum.yml b/.github/workflows/libserum.yml index 8ab4a29..ae90a90 100644 --- a/.github/workflows/libserum.yml +++ b/.github/workflows/libserum.yml @@ -55,7 +55,11 @@ jobs: run: | if [[ "${{ matrix.os }}" == "windows-latest" ]]; then cmake -G "Visual Studio 17 2022" -A ${{ matrix.platform-name }} -B build - cmake --build build --config Release + if [[ "${{ matrix.platform-name }}" == "Win32" ]]; then + cmake --build build --config Release -DUSE_WIN32=ON -DUSE_DLLEXPORTS=ON + else + cmake --build build --config Release -DUSE_DLLEXPORTS=ON + fi else cmake -DCMAKE_BUILD_TYPE=Release -B build/Release cmake --build build/Release diff --git a/CMakeLists.txt b/CMakeLists.txt index dd28901..65129c2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,11 +4,17 @@ project(serum VERSION 0.1.0 DESCRIPTION "Cross-platform library for decoding Serum files, a colorization format for pinball ROMs.") set(CMAKE_CXX_STANDARD 20) -set(CMAKE_CXX_VISIBILITY_PRESET hidden) set(CMAKE_C_STANDARD 99) -set(CMAKE_C_VISIBILITY_PRESET hidden) -include(GNUInstallDirs) +option(USE_DLLEXPORTS "dll exports" OFF) +if (USE_DLLEXPORTS) + add_compile_definitions(DLL_EXPORTS) +endif() + +option(USE_WIN32 "Win32" OFF) +if (USE_WIN32) + add_compile_definitions(WIN32) +endif() add_library(serum SHARED src/miniz/zip_file.hpp diff --git a/src/serum-decode.h b/src/serum-decode.h index db11e69..acdcc6c 100644 --- a/src/serum-decode.h +++ b/src/serum-decode.h @@ -2,17 +2,17 @@ #define SERUM_DECODE_H #if defined DLL_EXPORTS -#if defined WIN32 -#define SERUM_API(RetType) extern "C" __declspec(dllexport) RetType + #if defined WIN32 + #define SERUM_API(RetType) extern "C" __declspec(dllexport) RetType + #else + #define SERUM_API(RetType) extern "C" RetType __attribute__((visibility("default"))) + #endif #else -#define SERUM_API(RetType) extern "C" RetType __attribute__((visibility("default"))) -#endif -#else -#if defined WIN32 -#define SERUM_API(RetType) extern "C" __declspec(dllimport) RetType -#else -#define SERUM_API(RetType) extern "C" RetType -#endif + #if defined WIN32 + #define SERUM_API(RetType) extern "C" __declspec(dllimport) RetType + #else + #define SERUM_API(RetType) extern "C" RetType + #endif #endif #define MIN(a,b) ((a) < (b) ? (a) : (b)) From e29eef5c002e2462866e752ec67031f06648e291 Mon Sep 17 00:00:00 2001 From: Markus Kalkbrenner Date: Wed, 21 Dec 2022 16:50:13 +0100 Subject: [PATCH 06/11] added windows options --- .github/workflows/libserum.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/libserum.yml b/.github/workflows/libserum.yml index ae90a90..b987dca 100644 --- a/.github/workflows/libserum.yml +++ b/.github/workflows/libserum.yml @@ -54,12 +54,12 @@ jobs: - name: Build libserum-${{ matrix.platform }} run: | if [[ "${{ matrix.os }}" == "windows-latest" ]]; then - cmake -G "Visual Studio 17 2022" -A ${{ matrix.platform-name }} -B build if [[ "${{ matrix.platform-name }}" == "Win32" ]]; then - cmake --build build --config Release -DUSE_WIN32=ON -DUSE_DLLEXPORTS=ON + cmake -G "Visual Studio 17 2022" -A ${{ matrix.platform-name }} -B build -DUSE_WIN32=ON -DUSE_DLLEXPORTS=ON else - cmake --build build --config Release -DUSE_DLLEXPORTS=ON + cmake -G "Visual Studio 17 2022" -A ${{ matrix.platform-name }} -B build -DUSE_DLLEXPORTS=ON fi + cmake --build build --config Release else cmake -DCMAKE_BUILD_TYPE=Release -B build/Release cmake --build build/Release From 4d587e1a0838d022b375c62e6a36966ef2398638 Mon Sep 17 00:00:00 2001 From: Markus Kalkbrenner Date: Wed, 21 Dec 2022 16:58:47 +0100 Subject: [PATCH 07/11] no version number --- .github/workflows/libserum.yml | 43 +++++++++++----------------------- 1 file changed, 14 insertions(+), 29 deletions(-) diff --git a/.github/workflows/libserum.yml b/.github/workflows/libserum.yml index b987dca..16ed458 100644 --- a/.github/workflows/libserum.yml +++ b/.github/workflows/libserum.yml @@ -7,24 +7,9 @@ defaults: shell: bash jobs: - version: - name: Version - runs-on: ubuntu-latest - outputs: - version: ${{ steps.version.outputs.version }} - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - id: version - run: | - VERSION=$(grep -Eo "[0-9\.]+" CMakeLists.txt | head -2 | tail -1) - echo "version=${VERSION}" >> $GITHUB_OUTPUT - build: name: Build libserum-${{ matrix.platform }} runs-on: ${{ matrix.os }} - needs: [ version ] strategy: fail-fast: false matrix: @@ -32,23 +17,23 @@ jobs: - os: windows-latest platform: win-x64 platform-name: x64 - libserum: libserum-${{ needs.version.outputs.version }}.dll + libserum: libserum.dll - os: windows-latest platform: win-x86 platform-name: Win32 - libserum: libserum-${{ needs.version.outputs.version }}.dll + libserum: libserum.dll - os: macos-latest - platform: osx-x64 - libserum: libserum.${{ needs.version.outputs.version }}.dylib + platform: macOS-x64 + libserum: libserum.dylib - os: macos-latest - platform: osx-arm64 - libserum: libserum.${{ needs.version.outputs.version }}.dylib + platform: macOS-arm64 + libserum: libserum.dylib - os: ubuntu-latest platform: linux-x64 - libserum: libserum.so.${{ needs.version.outputs.version }} + libserum: libserum.so - os: ubuntu-latest platform: android-arm64-v8a - libserum: libserum.so.${{ needs.version.outputs.version }} + libserum: libserum.so steps: - uses: actions/checkout@v3 - name: Build libserum-${{ matrix.platform }} @@ -69,21 +54,21 @@ jobs: cp build/Release/${{ matrix.libserum }} tmp - uses: actions/upload-artifact@v3 with: - name: libserum-${{ needs.version.outputs.tag }}-${{ matrix.platform }} + name: libserum-${{ matrix.platform }} path: tmp post-build: runs-on: macos-latest needs: [ version, build ] - name: Build libserum-osx + name: Build libserum-macOS steps: - uses: actions/download-artifact@v3 - run: | mkdir tmp - lipo -create -output tmp/libserum.${{ needs.version.outputs.version }}.dylib \ - libserum-${{ needs.version.outputs.tag }}-osx-x64/libserum.${{ needs.version.outputs.version }}.dylib \ - libserum-${{ needs.version.outputs.tag }}-osx-arm64/libserum.${{ needs.version.outputs.version }}.dylib + lipo -create -output tmp/libserum.dylib \ + libserum-macOS-x64/libserum.dylib \ + libserum-macOS-arm64/libserum.dylib - uses: actions/upload-artifact@v3 with: - name: libserum-${{ needs.version.outputs.tag }}-osx + name: libserum-macOS path: tmp From 5d1143a87f57b7b2c014a06c06b227db8f4d5705 Mon Sep 17 00:00:00 2001 From: Markus Kalkbrenner Date: Wed, 21 Dec 2022 16:59:49 +0100 Subject: [PATCH 08/11] no versions --- .github/workflows/libserum.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/libserum.yml b/.github/workflows/libserum.yml index 16ed458..8c6cf1f 100644 --- a/.github/workflows/libserum.yml +++ b/.github/workflows/libserum.yml @@ -59,7 +59,7 @@ jobs: post-build: runs-on: macos-latest - needs: [ version, build ] + needs: [ build ] name: Build libserum-macOS steps: - uses: actions/download-artifact@v3 From edc3f90651a074ad413a0d5a5816f7d6c310bd3e Mon Sep 17 00:00:00 2001 From: Markus Kalkbrenner Date: Wed, 21 Dec 2022 17:03:01 +0100 Subject: [PATCH 09/11] erum.dll --- .github/workflows/libserum.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/libserum.yml b/.github/workflows/libserum.yml index 8c6cf1f..c560bb4 100644 --- a/.github/workflows/libserum.yml +++ b/.github/workflows/libserum.yml @@ -17,11 +17,11 @@ jobs: - os: windows-latest platform: win-x64 platform-name: x64 - libserum: libserum.dll + libserum: serum.dll - os: windows-latest platform: win-x86 platform-name: Win32 - libserum: libserum.dll + libserum: serum.dll - os: macos-latest platform: macOS-x64 libserum: libserum.dylib From 71b89ce4761cad9019d4c9d50ff1b01c94c8153f Mon Sep 17 00:00:00 2001 From: Markus Kalkbrenner Date: Wed, 21 Dec 2022 17:13:11 +0100 Subject: [PATCH 10/11] macOS arm vs intel --- .github/workflows/libserum.yml | 10 +++++++++- CMakeLists.txt | 10 ++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/.github/workflows/libserum.yml b/.github/workflows/libserum.yml index c560bb4..dc72cc2 100644 --- a/.github/workflows/libserum.yml +++ b/.github/workflows/libserum.yml @@ -46,7 +46,15 @@ jobs: fi cmake --build build --config Release else - cmake -DCMAKE_BUILD_TYPE=Release -B build/Release + if [[ "${{ matrix.os }}" == "macos-latest" ]]; then + if [[ "${{ matrix.platform }}" == "macOS-arm64" ]]; then + cmake -DCMAKE_BUILD_TYPE=Release -B build/Release -DUSE_OSXARM=ON + else + cmake -DCMAKE_BUILD_TYPE=Release -B build/Release -DUSE_OSXINTEL=ON + fi + else + cmake -DCMAKE_BUILD_TYPE=Release -B build/Release + fi cmake --build build/Release fi - run: | diff --git a/CMakeLists.txt b/CMakeLists.txt index 65129c2..9c99267 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,6 +16,16 @@ if (USE_WIN32) add_compile_definitions(WIN32) endif() +option(USE_OSXARM "macOS arm64" OFF) +if (USE_OSXARM) + set(CMAKE_OSX_ARCHITECTURES arm64) +endif() + +option(USE_OSXINTEL "macOS x86_64" OFF) +if (USE_OSXINTEL) + set(CMAKE_OSX_ARCHITECTURES x86_64) +endif() + add_library(serum SHARED src/miniz/zip_file.hpp src/serum-decode.h From 23ab183b6c151d74b2bf29eb866993ad11a8d7d6 Mon Sep 17 00:00:00 2001 From: Markus Kalkbrenner Date: Wed, 21 Dec 2022 17:24:34 +0100 Subject: [PATCH 11/11] compile options --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 998b34a..baf568c 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,12 @@ Due to complicated dependency management on different platforms, these libraries * [miniz-cpp](https://github.com/tfussell/miniz-cpp) by Thomas Fussel ## Compiling + +#### Linux or macOS ```shell cmake -DCMAKE_BUILD_TYPE=Release -B build/Release cmake --build build/Release ``` + +#### Windows +Use Visual Studio.