Skip to content

Commit

Permalink
GitHub action (#1)
Browse files Browse the repository at this point in the history
* added github action

* applied tfussell/miniz-cpp#7
  • Loading branch information
mkalkbrenner authored Dec 21, 2022
1 parent 58735c4 commit 4cb9797
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 39 deletions.
82 changes: 82 additions & 0 deletions .github/workflows/libserum.yml
Original file line number Diff line number Diff line change
@@ -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
25 changes: 21 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
50 changes: 25 additions & 25 deletions src/miniz/zip_file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -4981,7 +4981,7 @@ char alt_directory_separator = '\\';
std::string join_path(const std::vector<std::string> &parts)
{
std::string joined;
std::size_t i = 0;
size_t i = 0;
for(auto part : parts)
{
joined.append(part);
Expand Down Expand Up @@ -5029,7 +5029,7 @@ std::vector<std::string> 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;

Expand Down Expand Up @@ -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<std::vector<char> *>(opaque);

Expand All @@ -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<std::size_t>(file_ofs + i)] = (static_cast<const char *>(pBuf))[i];
(*buffer)[static_cast<size_t>(file_ofs + i)] = (static_cast<const char *>(pBuf))[i];
}

return n;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -5326,7 +5326,7 @@ class zip_file

std::vector<zip_info> 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<int>(i)));
}
Expand Down Expand Up @@ -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())
{
Expand Down Expand Up @@ -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<char *>(mz_zip_reader_extract_file_to_heap(archive_.get(), info.filename.c_str(), &size, 0));
if(data == nullptr)
{
Expand Down Expand Up @@ -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<char> buffer_copy(buffer_.begin(), buffer_.end());

if(!mz_zip_reader_init_mem(&archive_copy, buffer_copy.data(), buffer_copy.size(), 0))
Expand Down Expand Up @@ -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--)
{
Expand Down Expand Up @@ -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<std::size_t>(stat.m_comp_size);
result.file_size = static_cast<std::size_t>(stat.m_uncomp_size);
result.header_offset = static_cast<std::size_t>(stat.m_local_header_ofs);
result.compress_size = static_cast<size_t>(stat.m_comp_size);
result.file_size = static_cast<size_t>(stat.m_uncomp_size);
result.header_offset = static_cast<size_t>(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;
Expand Down
20 changes: 10 additions & 10 deletions src/serum-decode.h
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 4cb9797

Please sign in to comment.