summaryrefslogtreecommitdiffstats
path: root/mingw_conf.sh
diff options
context:
space:
mode:
authorLucian Petrut <lpetrut@cloudbasesolutions.com>2023-04-07 12:39:59 +0200
committerLucian Petrut <lpetrut@cloudbasesolutions.com>2023-08-30 14:59:00 +0200
commit3ce1e4a5c64bc0d71d3e6ad9ece040e4884d0378 (patch)
treef070707ab8f925665eb6f6d0a54e047e715bf719 /mingw_conf.sh
parenttest/dokan: avoid runtime dependent assertion (diff)
downloadceph-3ce1e4a5c64bc0d71d3e6ad9ece040e4884d0378.tar.xz
ceph-3ce1e4a5c64bc0d71d3e6ad9ece040e4884d0378.zip
win32_build.sh: mingw-llvm support
winpthreads is a library that emulates the pthreads API using Windows primitives. It's also used by the mingw/gcc libstdc++ for std::thread. The issue is that winpthreads isn't well maintained. There have been numerous bugs that haven't been addressed in years. Specifically, we've been hitting deadlocks because of the winpthreads rw lock implementation. This change will allow building Ceph for Windows using mingw/llvm, which uses libc++ and doesn't rely on winpthreads. Signed-off-by: Lucian Petrut <lpetrut@cloudbasesolutions.com>
Diffstat (limited to 'mingw_conf.sh')
-rw-r--r--mingw_conf.sh130
1 files changed, 86 insertions, 44 deletions
diff --git a/mingw_conf.sh b/mingw_conf.sh
index aa1ac941849..7c0d527e1e2 100644
--- a/mingw_conf.sh
+++ b/mingw_conf.sh
@@ -1,3 +1,5 @@
+#!/usr/bin/env bash
+
# MINGW Settings:
# Due to inconsistencies between distributions, mingw versions, binaries,
# and directories must be determined (or defined) prior to building.
@@ -8,6 +10,16 @@
# * MINGW_CMAKE_FILE - if set, a cmake toolchain file will be created
# * MINGW_POSIX_FLAGS - if set, Mingw Posix compatibility mode will be
# enabled by defining the according flags.
+# * USE_MINGW_LLVM - allows using the mingw llvm toolchain
+# * MINGW_LLVM_DIR - allows specifying the mingw-llvm toolchain location.
+# If unset, we'll use the default path from build.deps.
+
+SCRIPT_DIR="$(dirname "$BASH_SOURCE")"
+SCRIPT_DIR="$(realpath "$SCRIPT_DIR")"
+
+if [[ -n $USE_MINGW_LLVM ]]; then
+ MINGW_LLVM_DIR=${MINGW_LLVM_DIR:-"$SCRIPT_DIR/build.deps/mingw-llvm"}
+fi
# -Common mingw settings-
MINGW_PREFIX="x86_64-w64-mingw32-"
@@ -17,60 +29,82 @@ MINGW_DLLTOOL="${MINGW_BASE}-dlltool"
MINGW_WINDRES="${MINGW_BASE}-windres"
MINGW_STRIP="${MINGW_BASE}-strip"
MINGW_OBJCOPY="${MINGW_BASE}-objcopy"
-# -Distribution specific mingw settings-
-case "$OS" in
- ubuntu)
- mingwPosix="-posix"
- mingwLibDir="/usr/lib/gcc"
- mingwVersion="$(${MINGW_CPP}${mingwPosix} -dumpversion)"
- mingwTargetLibDir="${mingwLibDir}/${MINGW_BASE}/${mingwVersion}"
- mingwLibpthreadDir="/usr/${MINGW_BASE}/lib"
- PTW32Include=/usr/share/mingw-w64/include
- PTW32Lib=/usr/x86_64-w64-mingw32/lib
- ;;
- rhel)
- mingwPosix=""
- mingwLibDir="/usr/lib64/gcc"
- mingwVersion="$(${MINGW_CPP}${mingwPosix} -dumpversion)"
- mingwTargetLibDir="/usr/${MINGW_BASE}/sys-root/mingw/bin"
- mingwLibpthreadDir="$mingwTargetLibDir"
- PTW32Include=/usr/x86_64-w64-mingw32/sys-root/mingw/include
- PTW32Lib=/usr/x86_64-w64-mingw32/sys-root/mingw/lib
- ;;
- suse)
- mingwPosix=""
- mingwLibDir="/usr/lib64/gcc"
- mingwVersion="$(${MINGW_CPP}${mingwPosix} -dumpversion)"
- mingwTargetLibDir="/usr/${MINGW_BASE}/sys-root/mingw/bin"
- mingwLibpthreadDir="$mingwTargetLibDir"
- PTW32Include=/usr/x86_64-w64-mingw32/sys-root/mingw/include
- PTW32Lib=/usr/x86_64-w64-mingw32/sys-root/mingw/lib
- ;;
- *)
- echo "$ID is unknown, automatic mingw configuration is not possible."
- exit 1
- ;;
-esac
-# -Common mingw settings, dependent upon distribution specific settings-
-MINGW_FIND_ROOT_LIB_PATH="${mingwLibDir}/\${TOOLCHAIN_PREFIX}/${mingwVersion}"
-MINGW_CC="${MINGW_BASE}-gcc${mingwPosix}"
-MINGW_CXX="${MINGW_BASE}-g++${mingwPosix}"
+
+if [[ -n $USE_MINGW_LLVM ]]; then
+ # This package isn't currently provided by Linux distributions, we're
+ # fetching it from Github.
+ export PATH="$MINGW_LLVM_DIR/bin:$PATH"
+ mingwPosix=""
+ mingwVersion="$(${MINGW_CPP}${mingwPosix} -dumpversion)"
+ mingwX64IncludeDir="$MINGW_LLVM_DIR/x86_64-w64-mingw32/include"
+ mingwX64BinDir="$MINGW_LLVM_DIR/x86_64-w64-mingw32/bin"
+ mingwX64LibDir="$MINGW_LLVM_DIR/x86_64-w64-mingw32/lib"
+ mingwTargetLibDir="$mingwX64BinDir"
+ mingwLibpthreadDir="$mingwX64BinDir"
+ PTW32Include="$mingwX64IncludeDir"
+ PTW32Lib="$mingwX64LibDir"
+
+ MINGW_CC="${MINGW_BASE}-clang${mingwPosix}"
+ MINGW_CXX="${MINGW_BASE}-clang++${mingwPosix}"
+
+ MINGW_FIND_ROOT_PATH="$MINGW_LLVM_DIR/x86_64-w64-mingw32"
+else
+ # -Distribution specific mingw settings-
+ case "$OS" in
+ ubuntu)
+ mingwPosix="-posix"
+ mingwLibDir="/usr/lib/gcc"
+ mingwVersion="$(${MINGW_CPP}${mingwPosix} -dumpversion)"
+ mingwTargetLibDir="${mingwLibDir}/${MINGW_BASE}/${mingwVersion}"
+ mingwLibpthreadDir="/usr/${MINGW_BASE}/lib"
+ PTW32Include=/usr/share/mingw-w64/include
+ PTW32Lib=/usr/x86_64-w64-mingw32/lib
+ ;;
+ rhel)
+ mingwPosix=""
+ mingwLibDir="/usr/lib64/gcc"
+ mingwVersion="$(${MINGW_CPP}${mingwPosix} -dumpversion)"
+ mingwTargetLibDir="/usr/${MINGW_BASE}/sys-root/mingw/bin"
+ mingwLibpthreadDir="$mingwTargetLibDir"
+ PTW32Include=/usr/x86_64-w64-mingw32/sys-root/mingw/include
+ PTW32Lib=/usr/x86_64-w64-mingw32/sys-root/mingw/lib
+ ;;
+ suse)
+ mingwPosix=""
+ mingwLibDir="/usr/lib64/gcc"
+ mingwVersion="$(${MINGW_CPP}${mingwPosix} -dumpversion)"
+ mingwTargetLibDir="/usr/${MINGW_BASE}/sys-root/mingw/bin"
+ mingwLibpthreadDir="$mingwTargetLibDir"
+ PTW32Include=/usr/x86_64-w64-mingw32/sys-root/mingw/include
+ PTW32Lib=/usr/x86_64-w64-mingw32/sys-root/mingw/lib
+ ;;
+ *)
+ echo "$ID is unknown, automatic mingw configuration is not possible."
+ exit 1
+ ;;
+ esac
+ MINGW_CC="${MINGW_BASE}-gcc${mingwPosix}"
+ MINGW_CXX="${MINGW_BASE}-g++${mingwPosix}"
+
+ # -Common mingw settings, dependent upon distribution specific settings-
+ MINGW_FIND_ROOT_LIB_PATH="${mingwLibDir}/${MINGW_BASE}/${mingwVersion}"
+ MINGW_FIND_ROOT_PATH="/usr/${MINGW_BASE} ${MINGW_FIND_ROOT_LIB_PATH}"
+fi
# End MINGW configuration
if [[ -n $MINGW_CMAKE_FILE ]]; then
cat > $MINGW_CMAKE_FILE <<EOL
set(CMAKE_SYSTEM_NAME Windows)
-set(TOOLCHAIN_PREFIX ${MINGW_BASE})
set(CMAKE_SYSTEM_PROCESSOR x86_64)
# We'll need to use posix threads in order to use
# C++11 features, such as std::thread.
-set(CMAKE_C_COMPILER \${TOOLCHAIN_PREFIX}-gcc${mingwPosix})
-set(CMAKE_CXX_COMPILER \${TOOLCHAIN_PREFIX}-g++${mingwPosix})
-set(CMAKE_RC_COMPILER \${TOOLCHAIN_PREFIX}-windres)
+set(CMAKE_C_COMPILER ${MINGW_CC})
+set(CMAKE_CXX_COMPILER ${MINGW_CXX})
+set(CMAKE_RC_COMPILER ${MINGW_WINDRES})
-set(CMAKE_FIND_ROOT_PATH /usr/\${TOOLCHAIN_PREFIX} ${MINGW_FIND_ROOT_LIB_PATH})
+set(CMAKE_FIND_ROOT_PATH ${MINGW_FIND_ROOT_PATH})
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# TODO: consider switching this to "ONLY". The issue with
# that is that all our libs should then be under
@@ -88,4 +122,12 @@ add_definitions(-D_POSIX_=1)
add_definitions(-D_POSIX_THREADS=1)
EOL
fi
-fi \ No newline at end of file
+
+ if [[ -n $USE_MINGW_LLVM ]]; then
+ cat >> $MINGW_CMAKE_FILE <<EOL
+add_definitions(-I$mingwX64IncludeDir)
+add_definitions(-march=native)
+add_definitions(-Wno-unknown-attributes)
+EOL
+ fi
+fi