diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 68482f2a9..074ca0898 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -277,6 +277,45 @@ jobs: with: name: msi_${{ matrix.toolset }}_${{ matrix.platform }} path: ./*.msi + static: + name: Static build on Windows + needs: python + runs-on: windows-2025-vs2026 + env: + VCPKG_BINARY_SOURCES: clear;files,${{ github.workspace }}/vcpkg_cache,readwrite + CXXFLAGS: '/D_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR' + steps: + - name: Checkout + uses: actions/checkout@v6 + - name: Cache vcpkg + uses: actions/cache@v5 + with: + path: ${{ github.workspace }}/vcpkg_cache + key: vcpkg-static-x64-${{ hashFiles('vcpkg.json') }} + - name: Install dependencies + run: winget install --silent --accept-source-agreements --accept-package-agreements swig + - name: Download Python + uses: actions/download-artifact@v8 + with: + name: python + path: python/ + - uses: actions/setup-java@v5 + with: + distribution: 'temurin' + java-version: '17' + - name: Build + run: | + $swig = (Get-Item "$env:LOCALAPPDATA\Microsoft\WinGet\Links\swig.exe").Target + cmake -B build -S . ` + -DCMAKE_TOOLCHAIN_FILE="C:/vcpkg/scripts/buildsystems/vcpkg.cmake" ` + -DVCPKG_TARGET_TRIPLET=x64-windows-static-md ` + -DVCPKG_MANIFEST_FEATURES=tests ` + -DBUILD_SHARED_LIBS=OFF ` + -DSWIG_EXECUTABLE="$swig" ` + -DPython3_ROOT_DIR="${{ github.workspace }}/python/x64" ` + -DCMAKE_DISABLE_FIND_PACKAGE_Doxygen=YES + cmake --build build --config RelWithDebInfo + cmake --build build --config RelWithDebInfo --target check pages: name: Deploy pages if: github.repository == 'open-eid/libdigidocpp' && contains(github.ref, 'master') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a617eed5c..fa7bcc8bd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -84,10 +84,9 @@ add_library(digidocpp_tsl STATIC XMLDocument.h ) -set_target_properties(digidocpp_util digidocpp_tsl PROPERTIES - COMPILE_DEFINITIONS digidocpp_EXPORTS - POSITION_INDEPENDENT_CODE YES -) +target_compile_definitions(digidocpp_tsl PRIVATE $,digidocpp_EXPORTS,digidocpp_STATIC>) +target_compile_definitions(digidocpp_util PRIVATE $,digidocpp_EXPORTS,digidocpp_STATIC>) +set_target_properties(digidocpp_util digidocpp_tsl PROPERTIES POSITION_INDEPENDENT_CODE YES) target_include_directories(digidocpp_tsl PUBLIC $) @@ -261,8 +260,9 @@ if(SWIG_FOUND) endif() endif() -if(NOT ${BUILD_SHARED_LIBS}) +if(NOT BUILD_SHARED_LIBS) set(STATIC_TARGETS minizip digidocpp_tsl digidocpp_util) + target_compile_definitions(digidocpp PUBLIC digidocpp_STATIC) endif() install(TARGETS digidocpp ${STATIC_TARGETS} @@ -398,9 +398,6 @@ if( FRAMEWORK ) COMMAND zip -r ${PROJECT_BINARY_DIR}/libdigidocpp-dbg_${VERSION}$ENV{VER_SUFFIX}.zip libdigidocpp.dSYM ) else() - if(NOT ${BUILD_SHARED_LIBS}) - install( TARGETS minizip digidocpp_tsl digidocpp_util DESTINATION ${CMAKE_INSTALL_LIBDIR} ) - endif() if( BUILD_TOOLS ) install( TARGETS digidoc-tool DESTINATION ${CMAKE_INSTALL_BINDIR} ) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/digidoc-tool.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 ) diff --git a/src/Exports.h b/src/Exports.h index 6bbc7bb85..e1466ef66 100644 --- a/src/Exports.h +++ b/src/Exports.h @@ -21,7 +21,9 @@ #ifdef WIN32 #include - #ifdef digidocpp_EXPORTS + #ifdef digidocpp_STATIC + #define DIGIDOCPP_EXPORT + #elifdef digidocpp_EXPORTS #define DIGIDOCPP_EXPORT __declspec(dllexport) #else #define DIGIDOCPP_EXPORT __declspec(dllimport) diff --git a/src/util/File.cpp b/src/util/File.cpp index c57643f15..32f1a9cb6 100644 --- a/src/util/File.cpp +++ b/src/util/File.cpp @@ -19,6 +19,7 @@ #include "File.h" +#include "../Container.h" #include "log.h" #include @@ -54,17 +55,15 @@ namespace fs = filesystem; #define f_stat _wstat64 #define f_utime _wutime64 using f_statbuf = struct _stat64; -using f_utimbuf = struct __utimbuf64; #else #define f_stat stat #define f_utime utime using f_statbuf = struct stat; -using f_utimbuf = struct utimbuf; #endif stack File::tempFiles; -static string decodeName(fs::path path) +static string decodeName(const fs::path &path) { auto name = path.u8string(); return {reinterpret_cast(name.data()), name.size()}; @@ -72,12 +71,22 @@ static string decodeName(fs::path path) string File::confPath() { -#if defined(__APPLE__) +#ifdef __APPLE__ return frameworkResourcesPath("ee.ria.digidocpp"); -#elif defined(_WIN32) && defined(_DEBUG) - return dllPath("digidocppd.dll"); -#elif defined(_WIN32) - return dllPath("digidocpp.dll"); +#elifdef _WIN32 + if(HMODULE handle {}; + GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | + GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, + reinterpret_cast(&digidoc::terminate), + &handle)) + { + wstring path(MAX_PATH, 0); + path.resize(GetModuleFileNameW(handle, path.data(), DWORD(path.size()))); + if(size_t pos = path.find_last_of(L"/\\"); pos != wstring::npos) + path.resize(pos); + return decodeName(std::move(path)); + } + return {}; #else fs::path result; if(char *var = getenv("SNAP")) @@ -107,20 +116,6 @@ bool File::fileExists(const string& path) return fs::is_regular_file(encodeName(path)); } -#ifdef _WIN32 -string File::dllPath(string_view dll) -{ -#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) - HMODULE handle = GetModuleHandleW(encodeName(dll).c_str()); - wstring path(MAX_PATH, 0); - path.resize(GetModuleFileNameW(handle, path.data(), DWORD(path.size()))); - return decodeName(fs::path(path).parent_path()); -#else - return {}; -#endif -} -#endif - /** * Returns last modified time * diff --git a/src/util/File.h b/src/util/File.h index ccc24f1e8..626004720 100644 --- a/src/util/File.h +++ b/src/util/File.h @@ -53,9 +53,6 @@ namespace digidoc static std::vector hexToBin(std::string_view in); private: -#ifdef _WIN32 - static std::string dllPath(std::string_view dll); -#endif #ifdef __APPLE__ static std::string frameworkResourcesPath(std::string_view name); #endif