diff --git a/CMakeLists.txt b/CMakeLists.txt index e5fb1e4b..7585be01 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,7 +32,7 @@ find_package(uriparser REQUIRED) find_package(tomlplusplus REQUIRED) find_package(nlohmann_json REQUIRED) -set(SYNCSPIRIT_VERSION "v0.3.0") +set(SYNCSPIRIT_VERSION "v0.3.1") configure_file(misc/syncspirit-config.h.in include/syncspirit-config.h @ONLY) set(Protobuf_IMPORT_DIRS ${syncspirit_SOURCE_DIR}/src/protobuf) @@ -177,6 +177,7 @@ set(BUILD_SHARED_LIBS false CACHE BOOL "BUILD_SHARED_LIBS") set(MDBX_BUILD_TOOLS false CACHE BOOL "MDBX_BUILD_TOOLS") set(MDBX_ENABLE_TESTS false CACHE BOOL "MDBX_ENABLE_TESTS") set(MDBX_BUILD_CXX false CACHE BOOL "MDBX_BUILD_CXX") +set(MDBX_BUILD_SHARED_LIBRARY true CACHE BOOL "MDBX_BUILD_SHARED_LIBRARY") add_subdirectory("lib/mbdx") @@ -203,7 +204,7 @@ target_link_libraries(syncspirit_lib tomlplusplus::tomlplusplus nlohmann_json::nlohmann_json lz4::lz4 - mdbx-static + $,mdbx,mdbx-static> $<$:iphlpapi> $<$:ws2_32> ) diff --git a/README.md b/README.md index a2b90e24..4eda4ef6 100644 --- a/README.md +++ b/README.md @@ -117,6 +117,10 @@ after the core completion. # changes +## 0.3.1 (23-Apr-2024) +- [feature] added `syncspirit` binary fow windows xp +- [build, docs] improved build documentation + ## 0.3.0 (14-Apr-2024) - [feature] implemented complete files syncrhonisation - [feature] added local files watcher and updates streamer diff --git a/docs/building.md b/docs/building.md index 3f09ae9b..122c9c4f 100644 --- a/docs/building.md +++ b/docs/building.md @@ -41,7 +41,7 @@ make -j`nproc` ``` -## cross building on linus for windows (single executable) +## cross building on linux for windows (single executable, simple way) Install mingw on linux (something like `cross-x86_64-w64-mingw32`) @@ -84,6 +84,155 @@ cmake .. -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=$PWD/conan_toolchain.cmake \ make -j`nproc` ``` +## cross building on linux for modern windows (single executable, more reliable way) + +Download [mxe](https://mxe.cc); make sure all requirements are met. + +Your `settings.mk` should contain something like: + +``` +MXE_TARGETS := x86_64-w64-mingw32.static +``` + + +Validate, that everything is OK via typing in mxe dir something like + +``` +make zip +``` + + +Add $mxe_dir/uer/bin to your `PATH`, and make sure something like that works: + +``` +export PATH=`pwd`/usr/bin:$PATH +x86_64-w64-mingw32.static-g++ --version +x86_64-w64-mingw32.static-g++ (GCC) 11.2.0 +``` + +Make a conan profile for mingw: + +``` +cat ~/.conan2/profiles/mxe +[settings] +os=Windows +arch=x86_64 +compiler=gcc +build_type=Release +compiler.cppstd=gnu17 +compiler.libcxx=libstdc++11 +compiler.version=11 +[buildenv] +CC=x86_64-w64-mingw32.static-gcc +CXX=x86_64-w64-mingw32.static-g++ +LD=x86_64-w64-mingw32.static-ld +RC=x86_64-w64-mingw32.static-windres + +[options] +boost/*:without_fiber=True +boost/*:without_graph=True +boost/*:without_log=True +boost/*:without_stacktrace=True +boost/*:without_test=True +boost/*:without_wave=True +``` + +Go to `syncspirit` dir and then make a build + + +``` +cd syncspirit +mkdir build.release && cd build.release +conan install --build=missing -o '*:shared=False' -o shared=False --output-folder . \ + -s build_type=Release --profile:build=default --profile:host=mxe .. +source ./conanbuild.sh +cmake .. -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=$PWD/conan_toolchain.cmake \ + -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=off +make -j`nproc` +``` + +## cross building on linux for windows xp + +Download [mxe](https://mxe.cc); make sure all requirements are met. + +Your `settings.mk` should contain something like: + +``` +MXE_TARGETS := i686-w64-mingw32.static +MXE_PLUGIN_DIRS=plugins/windows-xp +``` + + +Validate, that everything is OK via typing in mxe dir something like + +``` +make zip +``` + +Copy the resulting `zip.exe` to windows xp host and launch, i.e. make sure +everything is ok with the toolchain. + + +Add $mxe_dir/uer/bin to your `PATH`, and make sure something like that works: + +``` +export PATH=`pwd`/usr/bin:$PATH +i686-w64-mingw32.static-g++ --version +i686-w64-mingw32.static-g++ (GCC) 11.2.0 +``` + +Make a conan profile for mingw: + +``` +cat ~/.conan2/profiles/xp +[settings] +os=Windows +arch=x86 +compiler=gcc +build_type=Release +compiler.cppstd=gnu17 +compiler.libcxx=libstdc++11 +compiler.version=12 +[buildenv] +CC=i686-w64-mingw32.static-gcc +CXX=i686-w64-mingw32.static-g++ +LD=i686-w64-mingw32.static-ld +RC=i686-w64-mingw32.static-windres + +[options] +boost/*:without_fiber=True +boost/*:without_graph=True +boost/*:without_log=True +boost/*:without_stacktrace=True +boost/*:without_test=True +boost/*:without_wave=True + +[conf] +tools.build:cflags=["-D_WIN32_WINNT=0x0501"] +tools.build:cxxflags=["-D_WIN32_WINNT=0x0501"] +``` + +The supped libmbdx should be patched for windows xp support: + +``` +cd syncspirit/lib/mbdx + patch -p1 < ../windows-xp.patch +``` + +Go to `syncspirit` dir and then make a build + +``` +cd syncspirit +mkdir build.release && cd build.release +conan install --build=missing -o '*:shared=False' -o shared=False --output-folder . \ + -s build_type=Release --profile:build=default --profile:host=xp .. +source ./conanbuild.sh +cmake .. -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=$PWD/conan_toolchain.cmake \ + -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=off \ + -DCMAKE_CXX_FLAGS="-D_WIN32_WINNT=0x0501 -DBOOST_ASIO_ENABLE_CANCELIO=1" +make -j`nproc` +``` + ## cross building on linux for old linux (ubuntu 16.04 etc.) @@ -128,7 +277,7 @@ boost/*:without_wave=True ``` ``` -conan install --build=missing -o '*:shared=False' -o shared=False --output-folder . +conan install --build=missing -o '*:shared=False' -o shared=False --output-folder . \ -s build_type=Release --profile:build=default --profile:host=old_linux .. source ./conanbuild.sh cmake .. -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=$PWD/conan_toolchain.cmake \ diff --git a/lib/windows-xp.patch b/lib/windows-xp.patch new file mode 100644 index 00000000..1faaa5e8 --- /dev/null +++ b/lib/windows-xp.patch @@ -0,0 +1,13 @@ +diff --git a/src/osal.c b/src/osal.c +index 5a0ae633..ec56591c 100644 +--- a/src/osal.c ++++ b/src/osal.c +@@ -1090,7 +1090,7 @@ MDBX_INTERNAL_FUNC void osal_ioring_reset(osal_ioring_t *ior) { + for (ior_item_t *item = ior->pool; item <= ior->last;) { + if (!HasOverlappedIoCompleted(&item->ov)) { + assert(ior->overlapped_fd); +- CancelIoEx(ior->overlapped_fd, &item->ov); ++ CancelIo(ior->overlapped_fd); + } + if (item->ov.hEvent && item->ov.hEvent != ior) + ior_put_event(ior, item->ov.hEvent); diff --git a/src/net/db_actor.cpp b/src/net/db_actor.cpp index edd9518f..b1758d74 100644 --- a/src/net/db_actor.cpp +++ b/src/net/db_actor.cpp @@ -6,6 +6,8 @@ #include "utils/platform.h" #include "db/prefix.h" #include "db/utils.h" +#include "../../lib/mbdx/src/internals.h" +#include "src/internals.h" #include "db/error_code.h" #include "model/diff/load/blocks.h" #include "model/diff/load/close_transaction.h" @@ -43,13 +45,24 @@ r::plugin::resource_id_t db = 0; } } // namespace +#if 0 +static void _my_log(MDBX_log_level_t loglevel, const char *function,int line, const char *fmt, va_list args) noexcept +{ + vprintf(fmt, args); +} +#endif + db_actor_t::db_actor_t(config_t &config) : r::actor_base_t{config}, env{nullptr}, db_dir{config.db_dir}, db_config{config.db_config}, cluster{config.cluster} { log = utils::get_logger("net.db"); + + // mdbx_module_handler({}, {}, {}); + // mdbx_setup_debug(MDBX_LOG_TRACE, MDBX_DBG_ASSERT, &_my_log); + auto r = mdbx_env_create(&env); if (r != MDBX_SUCCESS) { - LOG_CRITICAL(log, "{}, mbdx environment creation error ({}): {}", log->name(), r, mdbx_strerror(r)); + LOG_CRITICAL(log, "{}, mbdx environment creation error ({}): {}", "net::db", r, mdbx_strerror(r)); throw std::runtime_error(std::string(mdbx_strerror(r))); } } diff --git a/src/utils/network_interface.cpp b/src/utils/network_interface.cpp index 01558d8c..034168d3 100644 --- a/src/utils/network_interface.cpp +++ b/src/utils/network_interface.cpp @@ -115,8 +115,7 @@ static uri_container_t _local_interfaces(logger_t &log, std::uint16_t port) noex // IPv4 SOCKADDR_IN *ipv4 = reinterpret_cast(address->Address.lpSockaddr); - char host[INET_ADDRSTRLEN] = {0}; - inet_ntop(AF_INET, &(ipv4->sin_addr), host, INET_ADDRSTRLEN); + auto host = inet_ntoa(ipv4->sin_addr); auto full = fmt::format("tcp://{}:{}/", host, port); auto uri = utils::parse(full).value(); r.emplace_back(std::move(uri));