Add Windows to TravisCI
Implement the generation of Travis jobs for Windows. Currently, the generated jobs replicate Appveyor setup and complete successfully. There is support for MinGW GCC and MSVC compilers as well as 64 and 32 bit compilation. Linux and MacOS jobs behave identically, but some environment variables change - CROSS_COMPILE_32BIT=yes is added for builds with cross compilation, empty COMPILER_FLAGS are not set anymore.
This commit is contained in:
committed by
Alexander Lapenkov
parent
b798fabdf7
commit
01a293fc08
83
scripts/windows/before_install.sh
Normal file
83
scripts/windows/before_install.sh
Normal file
@@ -0,0 +1,83 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
# The purpose of this script is to install build dependencies and set
|
||||
# $build_env to a function that sets appropriate environment variables,
|
||||
# to enable (mingw32|mingw64) environment if we want to compile with gcc, or
|
||||
# (mingw32|mingw64) + vcvarsall.bat if we want to compile with cl.exe
|
||||
|
||||
if [[ "$TRAVIS_OS_NAME" != "windows" ]]; then
|
||||
echo "Incorrect \$TRAVIS_OS_NAME: expected windows, got $TRAVIS_OS_NAME"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
[[ ! -f C:/tools/msys64/msys2_shell.cmd ]] && rm -rf C:/tools/msys64
|
||||
choco uninstall -y mingw
|
||||
choco upgrade --no-progress -y msys2
|
||||
|
||||
msys_shell_cmd="cmd //C RefreshEnv.cmd && set MSYS=winsymlinks:nativestrict && C:\\tools\\msys64\\msys2_shell.cmd"
|
||||
|
||||
msys2() { $msys_shell_cmd -defterm -no-start -msys2 -c "$*"; }
|
||||
mingw32() { $msys_shell_cmd -defterm -no-start -mingw32 -c "$*"; }
|
||||
mingw64() { $msys_shell_cmd -defterm -no-start -mingw64 -c "$*"; }
|
||||
|
||||
if [[ "$CROSS_COMPILE_32BIT" == "yes" ]]; then
|
||||
mingw=mingw32
|
||||
mingw_gcc_package_arch=i686
|
||||
else
|
||||
mingw=mingw64
|
||||
mingw_gcc_package_arch=x86_64
|
||||
fi
|
||||
|
||||
if [[ "$CC" == *"gcc"* ]]; then
|
||||
$mingw pacman -S --noconfirm --needed \
|
||||
autotools \
|
||||
git \
|
||||
mingw-w64-${mingw_gcc_package_arch}-make \
|
||||
mingw-w64-${mingw_gcc_package_arch}-gcc \
|
||||
mingw-w64-${mingw_gcc_package_arch}-binutils
|
||||
build_env=$mingw
|
||||
elif [[ "$CC" == *"cl"* ]]; then
|
||||
$mingw pacman -S --noconfirm --needed \
|
||||
autotools \
|
||||
git \
|
||||
mingw-w64-${mingw_gcc_package_arch}-make \
|
||||
mingw-w64-${mingw_gcc_package_arch}-binutils
|
||||
|
||||
# In order to use MSVC compiler (cl.exe), we need to correctly set some environment
|
||||
# variables, namely PATH, INCLUDE, LIB and LIBPATH. The correct values of these
|
||||
# variables are set by a batch script "vcvarsall.bat". The code below generates
|
||||
# a batch script that calls "vcvarsall.bat" and prints the environment variables.
|
||||
#
|
||||
# Then, those environment variables are transformed from cmd to bash format and put
|
||||
# into a script $apply_vsenv. If cl.exe needs to be used from bash, one can
|
||||
# 'source $apply_vsenv' and it will apply the environment variables needed for cl.exe
|
||||
# to be located and function correctly.
|
||||
#
|
||||
# At last, a function "mingw_with_msvc_vars" is generated which forwards user input
|
||||
# into a correct mingw (32 or 64) subshell that automatically performs 'source $apply_vsenv',
|
||||
# making it possible for autotools to discover and use cl.exe.
|
||||
vcvarsall="vcvarsall.tmp.bat"
|
||||
echo "@echo off" > $vcvarsall
|
||||
echo "call \"c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\\\vcvarsall.bat\" $USE_MSVC" >> $vcvarsall
|
||||
echo "set" >> $vcvarsall
|
||||
|
||||
apply_vsenv="./apply_vsenv.sh"
|
||||
cmd //C $vcvarsall | grep -E "^PATH=" | sed -n -e 's/\(.*\)=\(.*\)/export \1=$PATH:"\2"/g' \
|
||||
-e 's/\([a-zA-Z]\):[\\\/]/\/\1\//g' \
|
||||
-e 's/\\/\//g' \
|
||||
-e 's/;\//:\//gp' > $apply_vsenv
|
||||
cmd //C $vcvarsall | grep -E "^(INCLUDE|LIB|LIBPATH)=" | sed -n -e 's/\(.*\)=\(.*\)/export \1="\2"/gp' >> $apply_vsenv
|
||||
|
||||
cat $apply_vsenv
|
||||
mingw_with_msvc_vars() { $msys_shell_cmd -defterm -no-start -$mingw -c "source $apply_vsenv && ""$*"; }
|
||||
build_env=mingw_with_msvc_vars
|
||||
|
||||
rm -f $vcvarsall
|
||||
else
|
||||
echo "Unknown C compiler: $CC"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Build environment function: $build_env"
|
20
scripts/windows/before_script.sh
Normal file
20
scripts/windows/before_script.sh
Normal file
@@ -0,0 +1,20 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
if [[ "$TRAVIS_OS_NAME" != "windows" ]]; then
|
||||
echo "Incorrect \$TRAVIS_OS_NAME: expected windows, got $TRAVIS_OS_NAME"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
$build_env autoconf
|
||||
$build_env ./configure $CONFIGURE_FLAGS
|
||||
# mingw32-make simply means "make", unrelated to mingw32 vs mingw64.
|
||||
# Simply disregard the prefix and treat is as "make".
|
||||
$build_env mingw32-make -j3
|
||||
# At the moment, it's impossible to make tests in parallel,
|
||||
# seemingly due to concurrent writes to '.pdb' file. I don't know why
|
||||
# that happens, because we explicitly supply '/Fs' to the compiler.
|
||||
# Until we figure out how to fix it, we should build tests sequentially
|
||||
# on Windows.
|
||||
$build_env mingw32-make tests
|
10
scripts/windows/script.sh
Normal file
10
scripts/windows/script.sh
Normal file
@@ -0,0 +1,10 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
if [[ "$TRAVIS_OS_NAME" != "windows" ]]; then
|
||||
echo "Incorrect \$TRAVIS_OS_NAME: expected windows, got $TRAVIS_OS_NAME"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
$build_env mingw32-make -k check
|
Reference in New Issue
Block a user