Skip to content

Commit

Permalink
Changes for linux build (#13)
Browse files Browse the repository at this point in the history
* Changes for Building on fedora

* Added build step for linux

* Added build step for linux

* Added build step for linux

* Added build step for linux

* Changes for Building on fedora

* Github Action Changes

* Test release

* Test release

* Reset release
  • Loading branch information
Suraj-Yadav authored Jul 9, 2024
1 parent 5ff799a commit 1f6c210
Show file tree
Hide file tree
Showing 13 changed files with 171 additions and 118 deletions.
44 changes: 23 additions & 21 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
- '!master'
tags:
- '**' # matches every tag
defaults:
run:
shell: bash
jobs:
build-windows:
env:
Expand All @@ -16,38 +19,37 @@ jobs:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/github-script@v6
- uses: './.github/workflows/setup'
with:
script: |
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
- name: Setup OpenCppCoverage and add to PATH
id: setup_opencppcoverage
run: |
choco install OpenCppCoverage -y
echo "C:\Program Files\OpenCppCoverage" >> $env:GITHUB_PATH
- name: cmake configure
run: |
$env:CMAKE_TOOLCHAIN_FILE="$env:VCPKG_INSTALLATION_ROOT/scripts/buildsystems/vcpkg.cmake"
cmake -B build -S .
- name: cmake test
run: cmake --build build --target coverage
- name: cmake build
run: cmake --build build --target package --config Release
- uses: actions/upload-artifact@v3
if: startsWith(github.ref, 'refs/tags/v')
zip-output: windows-zip
build-linux:
env:
VCPKG_DEFAULT_TRIPLET: x64-linux
VCPKG_BINARY_SOURCES: clear;x-gha,readwrite
runs-on: ubuntu-latest
steps:
- name: Install wxWidgets
run: sudo apt update && sudo apt install -y x11-xserver-utils libxi-dev libxtst-dev python3-jinja2 libxrandr-dev
- uses: actions/checkout@v3
with:
name: windows-zip
path: build/comic_reader-*.zip
fetch-depth: 0
- uses: './.github/workflows/setup'
with:
zip-output: linux-zip

create-release:
if: startsWith(github.ref, 'refs/tags/v')
needs:
- build-windows
- build-linux
runs-on: macos-latest
steps:
- uses: actions/download-artifact@v3
with:
name: windows-zip
- uses: actions/download-artifact@v3
with:
name: linux-zip
- run: ls
- uses: marvinpinto/action-automatic-releases@latest
with:
Expand Down
25 changes: 25 additions & 0 deletions .github/workflows/setup/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: 'Build'
inputs:
zip-output:
required: true
runs:
using: "composite"
steps:
- uses: actions/github-script@v6
with:
script: |
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
- name: cmake configure
shell: bash
run: |
export CMAKE_TOOLCHAIN_FILE=$VCPKG_INSTALLATION_ROOT/scripts/buildsystems/vcpkg.cmake
cmake -B build -S . || cat build/vcpkg_installed/vcpkg/issue_body.md
- name: cmake build
shell: bash
run: cmake --build build --target package --config Release
- uses: actions/upload-artifact@v3
if: startsWith(github.ref, 'refs/tags/v')
with:
name: ${{ inputs.zip-output }}
path: build/comic_reader-*.zip
16 changes: 0 additions & 16 deletions .vscode/launch.json

This file was deleted.

109 changes: 58 additions & 51 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,80 +6,87 @@ parse_git_tag()
project(comic_reader LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "")
set(CMAKE_EXPORT_COMPILE_COMMANDS
ON
CACHE INTERNAL "")

find_package(LibArchive REQUIRED)
find_package(Tweeny CONFIG REQUIRED)
find_package(WebP CONFIG REQUIRED)
find_package(wxWidgets CONFIG REQUIRED)

add_library(common_lib STATIC
src/archive.cpp
src/comic_gallery.cpp
src/comic_viewer.cpp
src/comic.cpp
src/fuzzy.cpp
src/image_utils.cpp
src/viewport.cpp
src/wxUtil.cpp
)
target_link_libraries(common_lib PUBLIC
LibArchive::LibArchive
tweeny
WebP::webp
wx::core
)
add_library(
common_lib STATIC
src/archive.cpp
src/comic_gallery.cpp
src/comic_viewer.cpp
src/comic.cpp
src/fuzzy.cpp
src/image_utils.cpp
src/viewport.cpp
src/wxUtil.cpp)

target_link_libraries(common_lib PUBLIC LibArchive::LibArchive tweeny
WebP::webp wx::core)

target_include_directories(common_lib PUBLIC "${CMAKE_SOURCE_DIR}/include")

add_executable(comic_reader WIN32 src/main.cpp)
target_link_libraries(comic_reader PRIVATE common_lib)

if(MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
target_sources(comic_reader PRIVATE resource/main.rc resource/main.manifest)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
target_sources(comic_reader PRIVATE resource/main.rc resource/main.manifest)
endif()

if(MSVC)
set(CPACK_GENERATOR "ZIP")
install(TARGETS comic_reader
RUNTIME_DEPENDENCIES
PRE_EXCLUDE_REGEXES "api-ms-" "ext-ms-" "hvsifiletrust" "pdmutilities"
POST_EXCLUDE_REGEXES ".*system32/.*\\.dll"
RUNTIME DESTINATION .
)
set(CPACK_PACKAGE_VERSION ${VERSION_STRING})
include(CPack)
endif()
set(CPACK_GENERATOR "ZIP")
install(
TARGETS comic_reader
RUNTIME_DEPENDENCIES
PRE_EXCLUDE_REGEXES
"api-ms-"
"ext-ms-"
"hvsifiletrust"
"pdmutilities"
POST_EXCLUDE_REGEXES
".*system32/.*\\.dll"
RUNTIME DESTINATION .)
set(CPACK_PACKAGE_VERSION ${VERSION_STRING})
include(CPack)

# Setup Test, coverage and benchmarks
find_package(benchmark CONFIG REQUIRED)
find_package(GTest CONFIG REQUIRED)

SET(TEST_SRCS
src/archive_test.cpp
src/comic_test.cpp
src/fuzzy_test.cpp
src/lru_test.cpp
)
set(TEST_SRCS src/archive_test.cpp src/comic_test.cpp src/fuzzy_test.cpp
src/lru_test.cpp)

add_executable(tests ${TEST_SRCS})
target_link_libraries(tests PRIVATE
common_lib GTest::gtest benchmark::benchmark GTest::gtest_main)
target_link_libraries(tests PRIVATE common_lib GTest::gtest
benchmark::benchmark GTest::gtest_main)

add_executable(benchmarks ${TEST_SRCS})
target_link_libraries(benchmarks PRIVATE
common_lib GTest::gtest benchmark::benchmark benchmark::benchmark_main)
target_link_libraries(
benchmarks PRIVATE common_lib GTest::gtest benchmark::benchmark
benchmark::benchmark_main)

if(MSVC)
add_custom_target(
coverage
OpenCppCoverage
-q --export_type cobertura:${CMAKE_BINARY_DIR}/cov.xml
--sources $<SHELL_PATH:${CMAKE_SOURCE_DIR}/src>
--sources $<SHELL_PATH:${CMAKE_SOURCE_DIR}/include>
--modules $<SHELL_PATH:${CMAKE_BINARY_DIR}>
--cover_children -- $<TARGET_FILE:tests> --gtest_output=xml:${CMAKE_BINARY_DIR}/test.xml
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
DEPENDS tests
)
add_custom_target(
coverage
OpenCppCoverage
-q
--export_type
cobertura:${CMAKE_BINARY_DIR}/cov.xml
--sources
$<SHELL_PATH:${CMAKE_SOURCE_DIR}/src>
--sources
$<SHELL_PATH:${CMAKE_SOURCE_DIR}/include>
--modules
$<SHELL_PATH:${CMAKE_BINARY_DIR}>
--cover_children
--
$<TARGET_FILE:tests>
--gtest_output=xml:${CMAKE_BINARY_DIR}/test.xml
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
DEPENDS tests)
endif()
3 changes: 2 additions & 1 deletion include/comic_gallery.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ComicGallery : public wxPanel {
void OnComicAddition(wxCommandEvent& evt);
void OnPaint(wxPaintEvent& evt);
void OnSize(wxSizeEvent& event);
void AddComic(std::filesystem::path path);
bool AddComic(std::filesystem::path path);

void verify(const wxGraphicsContext* g, int index);

Expand All @@ -35,4 +35,5 @@ class ComicGallery : public wxPanel {
void loadComics(std::vector<std::filesystem::path> paths);
void HandleInput(Navigation input, char ch = ' ');
Comic& currentComic() { return comics[index]; }
int length() const;
};
1 change: 1 addition & 0 deletions include/comic_viewer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class ComicViewer : public wxPanel {
void OnLeftUp(wxMouseEvent&);
void OnSize(wxSizeEvent&);
void OnCaptureLost(wxMouseCaptureLostEvent&);
void OnClose(wxCloseEvent&);

void StartPan(const wxPoint2DDouble&, PanSource);
void ProcessPan(const wxPoint2DDouble&, bool, PanSource);
Expand Down
2 changes: 2 additions & 0 deletions include/image_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ class ImagePool {
bool addImage(const std::filesystem::path& filepath);
const wxSize size(int index);
const wxBitmap& bitmap(int index);
auto empty() const { return paths.empty() || bitmaps.empty(); }
void clear();
};
5 changes: 3 additions & 2 deletions src/archive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ ArchiveFile::ArchiveFile(struct archive* ap, archive_entry* e)
: archivePtr(ap), entry(e) {}

std::filesystem::path ArchiveFile::path() const {
return std::filesystem::path(archive_entry_pathname(entry))
.make_preferred();
auto p = archive_entry_pathname(entry);
if (p == nullptr) { return ""; }
return std::filesystem::path(p).make_preferred();
}

int64_t ArchiveFile::size() const { return archive_entry_size(entry); }
Expand Down
12 changes: 7 additions & 5 deletions src/comic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
#include "image_utils.hpp"
#include "util.hpp"

const int THUMB_DIM = (std::min)(
wxSystemSettings::GetMetric(wxSYS_SCREEN_X),
wxSystemSettings::GetMetric(wxSYS_SCREEN_Y));

int GET_THUMB_DIM() {
const static int THUMB_DIM = (std::min)(
wxSystemSettings::GetMetric(wxSYS_SCREEN_X),
wxSystemSettings::GetMetric(wxSYS_SCREEN_Y));
return THUMB_DIM;
}
const std::filesystem::path cacheDirectory =
std::filesystem::temp_directory_path() / "comicReaderCache";

Expand Down Expand Up @@ -39,7 +41,7 @@ Comic::Comic(const std::filesystem::path& comicPath)
coverPage = getCoverPath(comicPath, fullPath);
file.writeContent(coverPage);
});
saveThumbnail(coverPage, coverPage, THUMB_DIM);
saveThumbnail(coverPage, coverPage, GET_THUMB_DIM());
}

int Comic::length() const { return size; };
Expand Down
32 changes: 21 additions & 11 deletions src/comic_gallery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ ComicGallery::ComicGallery(
GALLERY_UPDATE_ID);

SetBackgroundStyle(wxBG_STYLE_PAINT);
SetBackgroundColour(wxColour(25, 25, 25, 1));
SetBackgroundColour(wxColour(25, 25, 25));

loadComics(paths);
}
Expand All @@ -40,10 +40,14 @@ ComicGallery::~ComicGallery() {
}
}

void ComicGallery::AddComic(std::filesystem::path path) {
bool ComicGallery::AddComic(std::filesystem::path path) {
Comic c(path);
pool.addImage(c.coverPage);
comics.push_back(c);
if (c.length() > 0) {
pool.addImage(c.coverPage);
comics.push_back(c);
return true;
}
return false;
}

void ComicGallery::loadComics(std::vector<std::filesystem::path> paths) {
Expand All @@ -54,18 +58,22 @@ void ComicGallery::loadComics(std::vector<std::filesystem::path> paths) {
paths.erase(std::unique(paths.begin(), paths.end()), paths.end());
comics.reserve(paths.size());

AddComic(paths.front());
auto offset = 0u;
for (; offset < paths.size(); ++offset) {
if (AddComic(paths[offset])) { break; }
}

workInBackground.store(false);

if (!paths.empty()) {
workInBackground.store(true);
loader = std::async([paths, this]() {
for (auto i = 1u; i < paths.size(); ++i) {
loader = std::async([paths, offset, this]() {
for (auto i = offset + 1; i < paths.size(); ++i) {
if (!workInBackground.load()) { return; }
AddComic(paths[i]);
GetEventHandler()->AddPendingEvent(wxCommandEvent(
wxEVT_COMMAND_TEXT_UPDATED, GALLERY_UPDATE_ID));
if (AddComic(paths[i])) {
GetEventHandler()->AddPendingEvent(wxCommandEvent(
wxEVT_COMMAND_TEXT_UPDATED, GALLERY_UPDATE_ID));
};
}
workInBackground.store(false);
});
Expand All @@ -90,7 +98,7 @@ void ComicGallery::OnPaint(wxPaintEvent& event) {
dc.Clear();

// direct2d renderer
wxGraphicsRenderer* d2dr = wxGraphicsRenderer::GetDirect2DRenderer();
wxGraphicsRenderer* d2dr = wxGraphicsRenderer::GetDefaultRenderer();
wxGraphicsContext* gc = d2dr->CreateContext(dc);

if (gc) {
Expand Down Expand Up @@ -237,3 +245,5 @@ void ComicGallery::HandleInput(Navigation input, char ch) {
});
}
}

int ComicGallery::length() const { return comics.size(); };
Loading

0 comments on commit 1f6c210

Please sign in to comment.