diff --git a/.github/workflows/libserum.yml b/.github/workflows/libserum.yml new file mode 100644 index 0000000..dc72cc2 --- /dev/null +++ b/.github/workflows/libserum.yml @@ -0,0 +1,82 @@ +name: libserum +on: + push: + +defaults: + run: + shell: bash + +jobs: + build: + name: Build libserum-${{ matrix.platform }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - os: windows-latest + platform: win-x64 + platform-name: x64 + libserum: serum.dll + - os: windows-latest + platform: win-x86 + platform-name: Win32 + libserum: serum.dll + - os: macos-latest + platform: macOS-x64 + libserum: libserum.dylib + - os: macos-latest + platform: macOS-arm64 + libserum: libserum.dylib + - os: ubuntu-latest + platform: linux-x64 + libserum: libserum.so + - os: ubuntu-latest + platform: android-arm64-v8a + libserum: libserum.so + steps: + - uses: actions/checkout@v3 + - name: Build libserum-${{ matrix.platform }} + run: | + if [[ "${{ matrix.os }}" == "windows-latest" ]]; then + if [[ "${{ matrix.platform-name }}" == "Win32" ]]; then + cmake -G "Visual Studio 17 2022" -A ${{ matrix.platform-name }} -B build -DUSE_WIN32=ON -DUSE_DLLEXPORTS=ON + else + cmake -G "Visual Studio 17 2022" -A ${{ matrix.platform-name }} -B build -DUSE_DLLEXPORTS=ON + fi + cmake --build build --config Release + else + 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: | + mkdir tmp + cp build/Release/${{ matrix.libserum }} tmp + - uses: actions/upload-artifact@v3 + with: + name: libserum-${{ matrix.platform }} + path: tmp + + post-build: + runs-on: macos-latest + needs: [ build ] + name: Build libserum-macOS + steps: + - uses: actions/download-artifact@v3 + - run: | + mkdir tmp + lipo -create -output tmp/libserum.dylib \ + libserum-macOS-x64/libserum.dylib \ + libserum-macOS-arm64/libserum.dylib + - uses: actions/upload-artifact@v3 + with: + name: libserum-macOS + path: tmp diff --git a/CMakeLists.txt b/CMakeLists.txt index 618ff73..9c99267 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,13 +1,30 @@ 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) 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() + +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 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. 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; 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))