mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-11 05:23:29 -04:00
Support delayed loading of WinFsp DLL for universal binary
This commit is contained in:
parent
8dc5ea0697
commit
c79369e8da
@ -518,6 +518,8 @@ if(FUSE3_FOUND OR WINFSP)
|
|||||||
DWARFS_FUSE_LOWLEVEL=0)
|
DWARFS_FUSE_LOWLEVEL=0)
|
||||||
target_include_directories(dwarfs_main PRIVATE "${WINFSP_PATH}/inc")
|
target_include_directories(dwarfs_main PRIVATE "${WINFSP_PATH}/inc")
|
||||||
target_link_libraries(dwarfs_main ${WINFSP})
|
target_link_libraries(dwarfs_main ${WINFSP})
|
||||||
|
target_link_libraries(dwarfsuniversal delayimp.lib)
|
||||||
|
target_link_options(dwarfsuniversal PRIVATE /DELAYLOAD:winfsp-x64.dll)
|
||||||
else()
|
else()
|
||||||
target_compile_definitions(dwarfs_main PRIVATE FUSE_USE_VERSION=35)
|
target_compile_definitions(dwarfs_main PRIVATE FUSE_USE_VERSION=35)
|
||||||
target_link_libraries(dwarfs_main PkgConfig::FUSE3)
|
target_link_libraries(dwarfs_main PkgConfig::FUSE3)
|
||||||
@ -526,16 +528,14 @@ if(FUSE3_FOUND OR WINFSP)
|
|||||||
target_link_libraries(dwarfs-bin dwarfs_main)
|
target_link_libraries(dwarfs-bin dwarfs_main)
|
||||||
set_target_properties(dwarfs-bin PROPERTIES OUTPUT_NAME dwarfs)
|
set_target_properties(dwarfs-bin PROPERTIES OUTPUT_NAME dwarfs)
|
||||||
target_link_libraries(dwarfsuniversal dwarfs_main)
|
target_link_libraries(dwarfsuniversal dwarfs_main)
|
||||||
if(NOT WIN32)
|
if(WINFSP)
|
||||||
|
install(TARGETS dwarfs-bin RUNTIME DESTINATION bin)
|
||||||
|
else()
|
||||||
add_custom_command(OUTPUT mount.dwarfs
|
add_custom_command(OUTPUT mount.dwarfs
|
||||||
COMMAND ${CMAKE_COMMAND} -E create_symlink dwarfs mount.dwarfs
|
COMMAND ${CMAKE_COMMAND} -E create_symlink dwarfs mount.dwarfs
|
||||||
DEPENDS dwarfs-bin)
|
DEPENDS dwarfs-bin)
|
||||||
list(APPEND SYMLINKS mount.dwarfs)
|
list(APPEND SYMLINKS mount.dwarfs)
|
||||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/mount.dwarfs DESTINATION sbin)
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/mount.dwarfs DESTINATION sbin)
|
||||||
endif()
|
|
||||||
if(WIN32)
|
|
||||||
install(TARGETS dwarfs-bin RUNTIME DESTINATION bin)
|
|
||||||
else()
|
|
||||||
install(TARGETS dwarfs-bin RUNTIME DESTINATION sbin)
|
install(TARGETS dwarfs-bin RUNTIME DESTINATION sbin)
|
||||||
endif()
|
endif()
|
||||||
list(APPEND BINARY_TARGETS dwarfs-bin)
|
list(APPEND BINARY_TARGETS dwarfs-bin)
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <cstdlib>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <map>
|
#include <map>
|
||||||
@ -29,6 +30,10 @@
|
|||||||
#include <folly/String.h>
|
#include <folly/String.h>
|
||||||
#include <folly/gen/String.h>
|
#include <folly/gen/String.h>
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <delayimp.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "dwarfs/error.h"
|
#include "dwarfs/error.h"
|
||||||
#include "dwarfs/tool.h"
|
#include "dwarfs/tool.h"
|
||||||
#include "dwarfs_tool_main.h"
|
#include "dwarfs_tool_main.h"
|
||||||
@ -50,6 +55,23 @@ std::string to_narrow_string(sys_char const* str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
FARPROC WINAPI delay_hook(unsigned dliNotify, PDelayLoadInfo pdli) {
|
||||||
|
switch (dliNotify) {
|
||||||
|
case dliFailLoadLib:
|
||||||
|
std::cerr << "failed to load " << pdli->szDll << "\n";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case dliFailGetProc:
|
||||||
|
std::cerr << "failed to load symbol from " << pdli->szDll << "\n";
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
::exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
int dwarfs_main_helper(int argc, sys_char** argv) {
|
int dwarfs_main_helper(int argc, sys_char** argv) {
|
||||||
std::vector<std::string> argv_strings;
|
std::vector<std::string> argv_strings;
|
||||||
std::vector<char*> argv_copy;
|
std::vector<char*> argv_copy;
|
||||||
@ -79,6 +101,10 @@ std::map<std::string_view, int (*)(int, sys_char**)> const functions{
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
extern "C" const PfnDliHook __pfnDliFailureHook2 = delay_hook;
|
||||||
|
#endif
|
||||||
|
|
||||||
int SYS_MAIN(int argc, sys_char** argv) {
|
int SYS_MAIN(int argc, sys_char** argv) {
|
||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
auto tool_arg = to_narrow_string(argv[1]);
|
auto tool_arg = to_narrow_string(argv[1]);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user