Repository: bitcoin/bitcoin (language: cpp)

Issue:
RFC: Boost Process requires boost::filesystem when compiling with mingw
Working on "Use std::filesystem. Remove Boost Filesystem & System" #20744, I found an unfortunate [pitfall](https://github.com/bitcoin/bitcoin/pull/20744#issuecomment-946046666) -- `boost/process.hpp` depends on `boost::filesystem` when cross-compiling for Windows. It happens in Guix environment as well.

The goal of this issue is to discuss and find a solution to get rid of `boost::filesystem`.


Discussion / hints:
Is it a problem that *something* uses `boost::filesystem`? Does it conflicts with our own (non-use), or is it a lot of extra code to build? At least it could be specifically gated for the windows build.

In the longer run `boost::process` could be replaced with another library, or some own solution. It doesn't seem like rocket science though it is tricky to get right in a cross-platform way (especially windows, I guess :smile:)
Cross-compiling is successful only when a build system has been configured with `--disable-external-signer`.

Fix patch:
diff --git a/configure.ac b/configure.ac
index 5a6b54a1ae822..bef39739963b5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -321,7 +321,7 @@ AC_ARG_ENABLE([werror],
 AC_ARG_ENABLE([external-signer],
     [AS_HELP_STRING([--enable-external-signer],[compile external signer support (default is yes, requires Boost::Process)])],
     [use_external_signer=$enableval],
-    [use_external_signer=yes])
+    [use_external_signer=auto])
 
 AC_ARG_ENABLE([lto],
     [AS_HELP_STRING([--enable-lto],[build using LTO (default is no)])],
@@ -1415,7 +1415,21 @@ if test "$use_boost" = "yes"; then
 fi
 
 if test "$use_external_signer" != "no"; then
-  AC_DEFINE([ENABLE_EXTERNAL_SIGNER], [], [Define if external signer support is enabled])
+  case $host in
+    *mingw*)
+      dnl Boost Process uses Boost Filesystem when targeting Windows. Also,
+      dnl since Boost 1.71.0, Process does not work with mingw-w64 without
+      dnl workarounds. See 67669ab425b52a2b6be3d2f3b3b7e3939b676a2c.
+      if test "$use_external_signer" = "yes"; then
+        AC_MSG_ERROR([External signing is not supported on Windows])
+      fi
+      use_external_signer="no";
+    ;;
+    *)
+      use_external_signer="yes"
+      AC_DEFINE([ENABLE_EXTERNAL_SIGNER], [1], [Define if external signer support is enabled])
+    ;;
+  esac
 fi
 AM_CONDITIONAL([ENABLE_EXTERNAL_SIGNER], [test "$use_external_signer" = "yes"])
 
diff --git a/src/util/system.cpp b/src/util/system.cpp
index 8f35b7b6c6ba7..e34cdc7fb93c4 100644
--- a/src/util/system.cpp
+++ b/src/util/system.cpp
@@ -6,11 +6,6 @@
 #include <util/system.h>
 
 #ifdef ENABLE_EXTERNAL_SIGNER
-#if defined(WIN32) && !defined(__kernel_entry)
-// A workaround for boost 1.71 incompatibility with mingw-w64 compiler.
-// For details see https://github.com/bitcoin/bitcoin/pull/22348.
-#define __kernel_entry
-#endif
 #include <boost/process.hpp>
 #endif // ENABLE_EXTERNAL_SIGNER
 


Test patch:
diff --git a/ci/test/00_setup_env_win64.sh b/ci/test/00_setup_env_win64.sh
index 44b6eb7ae3aea..661985242392f 100755
--- a/ci/test/00_setup_env_win64.sh
+++ b/ci/test/00_setup_env_win64.sh
@@ -13,4 +13,4 @@ export DPKG_ADD_ARCH="i386"
 export PACKAGES="python3 nsis g++-mingw-w64-x86-64 wine-binfmt wine64 wine32 file"
 export RUN_FUNCTIONAL_TESTS=false
 export GOAL="deploy"
-export BITCOIN_CONFIG="--enable-reduce-exports --disable-gui-tests --disable-external-signer"
+export BITCOIN_CONFIG="--enable-reduce-exports --disable-gui-tests"