Skip to content

Commit

Permalink
Fixing MinGW port
Browse files Browse the repository at this point in the history
  • Loading branch information
maxirmx committed Mar 9, 2024
1 parent 892f46c commit 0f9ea10
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
27 changes: 17 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,18 @@ if("${OSTYPE_TXT}" MATCHES "^linux-musl.*")
add_compile_definitions(__musl__)
include(${TOOLS}/cmake-scripts/setup-libutfcpp.cmake)
add_dependencies(_LIBARCHIVE ${LIBUTFCPP_PRJ})
set(PATCH_FOLLY ON)
if (NOT NO_PATCH)
set(PATCH_FOLLY ON)
endif(NOT NO_PATCH)
endif()

if ("${OSTYPE_TXT}" MATCHES "^darwin*")
include(${TOOLS}/cmake-scripts/macos-environment.cmake)
include(${TOOLS}/cmake-scripts/setup-libutfcpp.cmake)
add_dependencies(_LIBARCHIVE ${LIBUTFCPP_PRJ})
set(PATCH_FOLLY ON)
if (NOT NO_PATCH)
set(PATCH_FOLLY ON)
endif(NOT NO_PATCH)
endif()

if ("${OSTYPE_TXT}" MATCHES "msys")
Expand All @@ -213,8 +217,10 @@ if ("${OSTYPE_TXT}" MATCHES "msys")
# This is because of some new features of glog 0.7.0
add_definitions(-DGLOG_USE_GLOG_EXPORT)

set(PATCH_FOLLY ON)
set(PATCH_FBTHRIFT ON)
if (NOT NO_PATCH)
set(PATCH_FOLLY ON)
set(PATCH_FBTHRIFT ON)
endif(NOT NO_PATCH)
endif()

if (${PATCH_FOLLY})
Expand Down Expand Up @@ -251,9 +257,9 @@ if (${PATCH_FBTHRIFT})
)

if(PATCH_FBTHRIFT_RES EQUAL 0)
message(STATUS "Patched fbthrift at '${FOLLY_FBTHRIFT}'")
message(STATUS "Patched fbthrift at '${FBTHRIFT_ROOT}'")
else(PATCH_FBTHRIFT_RES EQUAL 0)
message(FATAL_ERROR "Failed to patch fbthrift at '${FOLLY_FBTHRIFT}': ${PATCH_FBTHRIFT_TXT}")
message(FATAL_ERROR "Failed to patch fbthrift at '${FBTHRIFT_ROOT}': ${PATCH_FBTHRIFT_TXT}")
endif(PATCH_FBTHRIFT_RES EQUAL 0)
endif(${PATCH_FBTHRIFT})

Expand Down Expand Up @@ -616,19 +622,19 @@ if("${TEBAKO_BUILD_SCOPE}" STREQUAL "ALL")
add_library(dwarfsextract_main src/dwarfsextract_main.cpp)

target_link_libraries(dwarfsck_main folly)
target_link_libraries(dwarfsbench_main folly )
target_link_libraries(dwarfsbench_main folly)
target_link_libraries(dwarfsextract_main folly)

add_executable(dwarfsck src/dwarfsck.cpp)
add_executable(dwarfsbench src/dwarfsbench.cpp)
add_executable(dwarfsextract src/dwarfsextract.cpp)
add_executable(dwarfsuniversal src/universal.cpp)

target_link_libraries(dwarfsck dwarfsck_main ws2_32 wsock32)
target_link_libraries(dwarfsck dwarfsck_main)
target_link_libraries(dwarfsbench dwarfsbench_main)
target_link_libraries(dwarfsextract dwarfsextract_main)
target_link_libraries(dwarfsuniversal mkdwarfs_main dwarfsck_main
dwarfsextract_main ws2_32 wsock32)
dwarfsextract_main)
set_target_properties(dwarfsuniversal PROPERTIES
RUNTIME_OUTPUT_DIRECTORY universal
OUTPUT_NAME dwarfs-universal)
Expand Down Expand Up @@ -995,7 +1001,8 @@ target_link_libraries(
thrift_light
folly
fsst
${Boost_LIBRARIES})
${Boost_LIBRARIES}
)

if(LIBLZ4_FOUND)
target_link_libraries(dwarfs PkgConfig::LIBLZ4)
Expand Down
21 changes: 16 additions & 5 deletions src/dwarfsck_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@

#include <boost/program_options.hpp>

#include <folly/File.h>
#include <folly/FileUtil.h>
// [maxirmx]
// Re: tebako patch
// folly::Files refers WinSocks that I am trying to avoid
// #include <folly/File.h>
// #include <folly/FileUtil.h>

#include <folly/detail/FileUtilDetail.h>
#include <folly/String.h>
#include <folly/json.h>
#include <folly/portability/Unistd.h>
Expand Down Expand Up @@ -132,13 +137,18 @@ int dwarfsck_main(int argc, sys_char** argv) {
auto mm = std::make_shared<mmap>(input);

if (!export_metadata.empty()) {
auto of = folly::File(export_metadata, O_RDWR | O_CREAT | O_TRUNC);
// [maxirmx]
// Re: tebako patch
// auto of = folly::File(export_metadata, O_RDWR | O_CREAT | O_TRUNC);
int fd = ::open(export_metadata.c_str(), O_RDWR | O_CREAT | O_TRUNC, 0666);
filesystem_v2 fs(lgr, mm, fsopts);
auto json = fs.serialize_metadata_as_json(false);
if (folly::writeFull(of.fd(), json.data(), json.size()) < 0) {
// if (folly::writeFull(of.fd(), json.data(), json.size()) < 0) {
if (folly::fileutil_detail::wrapFull(::write, fd, json.data(), json.size()) < 0) {
LOG_ERROR << "failed to export metadata";
}
of.close();
// of.close();
::close(fd);
} else if (json) {
filesystem_v2 fs(lgr, mm, fsopts);
std::cout << folly::toPrettyJson(fs.metadata_as_dynamic()) << "\n";
Expand All @@ -161,6 +171,7 @@ int dwarfsck_main(int argc, sys_char** argv) {
return 1;
}
}

} catch (system_error const& e) {
std::cerr << folly::exceptionStr(e) << "\n";
return 1;
Expand Down

0 comments on commit 0f9ea10

Please sign in to comment.