Skip to content

Commit

Permalink
🚧 Zip files support (Windows)
Browse files Browse the repository at this point in the history
  • Loading branch information
xurei committed Oct 9, 2023
1 parent f41ab8f commit b60c5a9
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 31 deletions.
42 changes: 40 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ name: build obs plugin

on:
push:
branches: [ main, ci, dev ]
branches: [ main, ci, dev, zip-support ]
#pull_request:
# branches: [ main ]

env:
PLUGIN_NAME: shadertastic
OBS_VERSION: 28.1.2
LIBZIP_VERSION: v1.10.1
jobs:
# macos:
# name: macOS
Expand Down Expand Up @@ -227,6 +228,42 @@ jobs:
uses: actions/[email protected]
with:
path: plugins/${{ env.PLUGIN_NAME}}
submodules: 'recursive'
- name: install libzip dependencies (Windows)
uses: lukka/run-vcpkg@v7
id: runvcpkg
with:
vcpkgGitCommitId: f93ba152d55e1d243160e690bc302ffe8638358e
vcpkgTriplet: x64-windows
vcpkgArguments: zlib
- name: "libzip: Cache"
uses: actions/cache/restore@v3
id: libzip-cache
with:
path: plugins/${{ env.PLUGIN_NAME }}/vendor/libzip/build
key: libzip-${{env.LIBZIP_VERSION}}
- name: "libzip: Build"
if: "steps.libzip-cache.outputs.cache-hit != 'true'"
shell: cmd
run: |
cd plugins/${{ env.PLUGIN_NAME }}/vendor/libzip
git fetch
git checkout ${{ env.LIBZIP_VERSION }}
mkdir build
cd build
cmake -G"${{ env.CMAKE_GENERATOR }}" -DBUILD_SHARED_LIBS=OFF -DENABLE_COMMONCRYPTO=OFF -DENABLE_ZSTD=OFF -DENABLE_BZIP2=OFF -DENABLE_LZMA=OFF -DCMAKE_TOOLCHAIN_FILE=${{env.VCPKG_ROOT}}/scripts/buildsystems/vcpkg.cmake ..
dir
cmake --build . --config Release
cd lib
dir
cd Release
dir
- name: "libzip: Save Cache"
if: "steps.libzip-cache.outputs.cache-hit != 'true'"
uses: actions/cache/save@v3
with:
path: plugins/${{ env.PLUGIN_NAME }}/vendor/libzip/build
key: ${{ steps.libzip-cache.outputs.cache-primary-key }}
- name: Add plugin to obs cmake
shell: cmd
run: echo add_subdirectory(${{ env.PLUGIN_NAME }}) >> plugins/CMakeLists.txt
Expand Down Expand Up @@ -275,7 +312,8 @@ jobs:
mkdir ./installer
mkdir ./installer/media
mkdir ./build
cmake -S . -B "${{ github.workspace }}/build" -G"${{ env.CMAKE_GENERATOR }}" -DCMAKE_PREFIX_PATH:PATH="${{ github.workspace }}/cmbuild/deps" -A"${{ matrix.cmake_build }}" -DCMAKE_SYSTEM_VERSION="${{ env.CMAKE_SYSTEM_VERSION }}" -DBUILD_BROWSER=false -DBUILD_VST=false -DBUILD_VIRTUALCAM=false -DBUILD_CAPTIONS=false -DCOMPILE_D3D12_HOOK=false -DENABLE_SCRIPTING=false -DDepsPath="${{ github.workspace }}/cmbuild/deps" -DDepsPath${{ matrix.deps_ext }}="${{ github.workspace }}/cmbuild/deps" -DQTDIR="${{ github.workspace }}/cmbuild/deps/qt6" -DCOPIED_DEPENDENCIES=FALSE -DCOPY_DEPENDENCIES=TRUE -DENABLE_PLUGINS=TRUE -DDISABLE_PLUGINS=FALSE -DENABLE_BROWSER=FALSE -DENABLE_WEBSOCKET=FALSE
cmake -S . -B "${{ github.workspace }}/build" -G"${{ env.CMAKE_GENERATOR }}" -DCMAKE_PREFIX_PATH:PATH="${{ github.workspace }}/cmbuild/deps" -A"${{ matrix.cmake_build }}" -DCMAKE_SYSTEM_VERSION="${{ env.CMAKE_SYSTEM_VERSION }}" -DBUILD_BROWSER=false -DBUILD_VST=false -DBUILD_VIRTUALCAM=false -DBUILD_CAPTIONS=false -DCOMPILE_D3D12_HOOK=false -DENABLE_SCRIPTING=false -DDepsPath="${{ github.workspace }}/cmbuild/deps" -DDepsPath${{ matrix.deps_ext }}="${{ github.workspace }}/cmbuild/deps" -DQTDIR="${{ github.workspace }}/cmbuild/deps/qt6" -DCOPIED_DEPENDENCIES=FALSE -DCOPY_DEPENDENCIES=TRUE -DENABLE_PLUGINS=TRUE -DDISABLE_PLUGINS=FALSE -DENABLE_BROWSER=FALSE -DENABLE_WEBSOCKET=FALSE -DLIBZIP_INCLUDE="plugins/${{ env.PLUGIN_NAME }}/vendor/libzip/lib" -DLIBZIP_INCLUDE_CONF="plugins/${{ env.PLUGIN_NAME }}/vendor/libzip/build" -DLIBZIP_LIBRARY="plugins/${{ env.PLUGIN_NAME }}/vendor/libzip/build/lib/Release/zip.lib"
- name: 'Build'
run: msbuild /m /p:Configuration=RelWithDebInfo .\build\obs-studio.sln
- name: Package
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "vendor/libzip"]
path = vendor/libzip
url = https://github.com/nih-at/libzip
52 changes: 32 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@

# Attempt to compile a static zip library directly from here, but does not work, I will look at this later
#set(BUILD_SHARED_LIBS OFF)
#add_subdirectory(zip/libzip)
# set(BUILD_SHARED_LIBS ON)

# --- Detect if the plugin is build out of tree or not ---
if(CMAKE_PROJECT_NAME STREQUAL "obs-studio")
set(BUILD_OUT_OF_TREE OFF)
Expand All @@ -26,15 +20,15 @@ set(CMAKE_COMPILE_WARNING_AS_ERROR ON)
set(MACOS_PACKAGE_UUID "90e83546-fa37-453a-9adb-b51149c78df1")
set(MACOS_INSTALLER_UUID "14c0a640-0656-4528-8243-4a2ab2595dd5")

# libzip
set(LIBZIP_LIBRARY "" CACHE FILEPATH "Path to libzip library.")
set(LIBZIP_INCLUDE "" CACHE PATH "Path zo libzip's includes.")
set(LIBZIP_INCLUDE_CONF "" CACHE PATH "Path zo libzip's includes (config file).")

add_library(${PROJECT_NAME} MODULE)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/version.h.in ${CMAKE_CURRENT_SOURCE_DIR}/src/version.h)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx2 -O3 -fopenmp")

include_directories(AFTER zip/libzip/lib)
include_directories(AFTER zip/libzip/build)

target_sources(${PROJECT_NAME} PRIVATE
src/shadertastic.cpp
src/version.h
Expand All @@ -50,25 +44,44 @@ else()
endif()

if(OS_WINDOWS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:avx2 /O2 /openmp")
get_filename_component(ISS_FILES_DIR "${CMAKE_BINARY_DIR}\\..\\package" ABSOLUTE)
file(TO_NATIVE_PATH "${ISS_FILES_DIR}" ISS_FILES_DIR)
get_filename_component(ISS_PACKAGE_DIR "${CMAKE_PACKAGE_PREFIX}\\.." ABSOLUTE)
file(TO_NATIVE_PATH "${ISS_PACKAGE_DIR}" ISS_PACKAGE_DIR)
get_filename_component(ISS_SOURCE_DIR "${PROJECT_SOURCE_DIR}" ABSOLUTE)
file(TO_NATIVE_PATH "${ISS_SOURCE_DIR}" ISS_SOURCE_DIR)
configure_file("installer.iss.in"
"${PROJECT_BINARY_DIR}/installer.iss"
)
"${PROJECT_BINARY_DIR}/installer.iss"
)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/resource.rc.in ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.rc)

include_directories(AFTER ${LIBZIP_INCLUDE})
include_directories(AFTER ${LIBZIP_INCLUDE_CONF})
target_link_libraries(${PROJECT_NAME}
${LIBZIP_LIBRARY}
)
set(ZLIB_USE_STATIC_LIBS ON)
find_package(ZLIB REQUIRED)
target_link_libraries(${PROJECT_NAME} ${ZLIB_LIBRARIES})
include_directories(${ZLIB_INCLUDE_DIRS})

target_sources(${PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.rc)
elseif(OS_MACOS)
set(MACOS_BUNDLEID "com.xureilab.${PROJECT_NAME}")
set(MACOSX_PLUGIN_GUI_IDENTIFIER "${MACOS_BUNDLEID}")
set(MACOSX_PLUGIN_BUNDLE_VERSION "${PROJECT_VERSION}")
set(MACOSX_PLUGIN_SHORT_VERSION_STRING "1")
configure_file(cmake/bundle/macos/installer-macos.pkgproj.in ${CMAKE_BINARY_DIR}/installer-macos.generated.pkgproj)
target_compile_options(${PROJECT_NAME} PRIVATE -Wall)
set(MACOS_BUNDLEID "com.xureilab.${PROJECT_NAME}")
set(MACOSX_PLUGIN_GUI_IDENTIFIER "${MACOS_BUNDLEID}")
set(MACOSX_PLUGIN_BUNDLE_VERSION "${PROJECT_VERSION}")
set(MACOSX_PLUGIN_SHORT_VERSION_STRING "1")
configure_file(cmake/bundle/macos/installer-macos.pkgproj.in ${CMAKE_BINARY_DIR}/installer-macos.generated.pkgproj)
target_compile_options(${PROJECT_NAME} PRIVATE -Wall)
elseif(OS_LINUX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx2 -O3 -fopenmp")
include_directories(AFTER vendor/libzip/lib)
include_directories(AFTER vendor/libzip/build)
target_link_libraries(${PROJECT_NAME}
${PROJECT_SOURCE_DIR}/vendor/libzip/build/lib/libzip.a
)
endif()

# lines if you want add Qt UI in your plugin
Expand All @@ -79,7 +92,6 @@ target_link_libraries(${PROJECT_NAME}
OBS::${OBS_FRONTEND_API_NAME}
Qt::Widgets
OBS::libobs
${PROJECT_SOURCE_DIR}/zip/libzip/build/lib/libzip.a
)

if(BUILD_OUT_OF_TREE)
Expand Down
20 changes: 11 additions & 9 deletions src/util/file_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
#include <filesystem>
namespace fs = std::filesystem;

char *load_file_zipped_or_local(const char *path) {
debug("load_file_zipped_or_local %s", path);
char *load_file_zipped_or_local(std::string path) {
path = normalize_path(path);
debug("load_file_zipped_or_local %s", path.c_str());

if (os_file_exists(path)) {
return os_quick_read_utf8_file(path);
if (os_file_exists(path.c_str())) {
return os_quick_read_utf8_file(path.c_str());
}
else {
fs::path fs_path(path);
Expand All @@ -33,7 +34,8 @@ char *load_file_zipped_or_local(const char *path) {
}

int zip_err_code;
const char *zip_entry = fs_path.filename().string().c_str();
std::string zip_entry = fs_path.filename().string();
debug("zip_entry: %s", zip_entry.c_str());
struct zip_stat file_stat;
zip_t *zip_archive = zip_open(zip_path.c_str(), ZIP_RDONLY, &zip_err_code);

Expand All @@ -45,15 +47,15 @@ char *load_file_zipped_or_local(const char *path) {
return NULL;
}

if (zip_stat(zip_archive, zip_entry, 0, &file_stat) != 0) {
do_log(LOG_ERROR, "Cannot open shadertastic file in archive '%s': unable to stat entry file %s\n", zip_path.c_str(), zip_entry);
if (zip_stat(zip_archive, zip_entry.c_str(), 0, &file_stat) != 0) {
do_log(LOG_ERROR, "Cannot open shadertastic file in archive '%s': unable to stat entry file %s : %s\n", zip_path.c_str(), zip_entry.c_str(), zip_error_strerror(zip_get_error(zip_archive)));
return NULL;
}

zip_file_t *zipped_file = zip_fopen(zip_archive, zip_entry, 0);
zip_file_t *zipped_file = zip_fopen(zip_archive, zip_entry.c_str(), 0);

if (zipped_file == NULL) {
do_log(LOG_ERROR, "Cannot open shadertastic file in archive '%s': unable to open entry file %s\n", zip_path.c_str(), zip_entry);
do_log(LOG_ERROR, "Cannot open shadertastic file in archive '%s': unable to open entry file %s\n", zip_path.c_str(), zip_entry.c_str());
return NULL;
}

Expand Down
1 change: 1 addition & 0 deletions vendor/libzip
Submodule libzip added at 210b09

0 comments on commit b60c5a9

Please sign in to comment.