dmd/.azure-pipelines/windows.sh
Johan Engelen afc38e9dca
Make distinction between CC and CXX in the testsuite. (#16434)
Clang makes a distinction between clang and clang++. In particular, clang++ will give a warning when it is passed `.c` source files; and the extra output warning text means that dmd testsuite output checking fails. The warning can be silenced (-Wno-deprecated) but then other tests will fail because `#ifdef __cplusplus` will be true, leading to header file import issues.
2024-05-03 07:30:55 +08:00

195 lines
7.4 KiB
Bash

#!/bin/bash
set -eux -o pipefail
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
. "$DIR/lib.sh"
################################################################################
# Setup required tools
################################################################################
# WORKAROUND: install a newer grep version
# REASON: the preinstalled version is buggy (see also: https://github.com/dlang/dmd/pull/9398#issuecomment-468773638)
install_grep
if [ "$HOST_DMD_VERSION" == "LATEST" ]; then
download "https://downloads.dlang.org/releases/LATEST" LATEST
HOST_DMD_VERSION="$(cat LATEST)"
fi
echo "D_VERSION: $HOST_DMD_VERSION"
echo "VSINSTALLDIR: $VSINSTALLDIR"
echo "GREP_VERSION: $(grep --version)"
################################################################################
# Prepare DigitalMars make and C compiler
################################################################################
GNU_MAKE="$(which make)" # must be done before installing dmc (tampers with PATH)
if [ "$MODEL" == "32omf" ] ; then
install_host_dmc
CC="$PWD/dm/bin/dmc.exe"
CXX="$PWD/dm/bin/dmc.exe"
export CPPCMD="$PWD/dm/bin/sppn.exe"
else
CC="cl.exe"
CXX="cl.exe"
fi
################################################################################
# Install the host compiler
################################################################################
if [ "$D_COMPILER" == "dmd" ]; then
install_host_dmd
else
echo 'Invalid $D_COMPILER provided'.
exit 1
fi
################################################################################
# Checkout other repositories
################################################################################
clone_repos
################################################################################
# Prepare build flags
################################################################################
if [ "$MODEL" == "64" ] ; then
LIBNAME=phobos64.lib
elif [ "$MODEL" == "32" ] ; then
LIBNAME=phobos32mscoff.lib
else # 32omf
LIBNAME=phobos.lib
fi
################################################################################
# Build DMD (incl. building and running the unittests)
################################################################################
# no `-debug` for unittests build with old host compilers (to avoid compile errors)
disable_debug_for_unittests=()
if [[ "$HOST_DMD_VERSION" == "2.079.0" ]]; then
disable_debug_for_unittests=(ENABLE_DEBUG=0)
fi
# avoid the DMC runtime and its limitations for the compiler and {build,run}.d tools themselves
TOOL_MODEL="$MODEL"
if [[ "$MODEL" == "32omf" ]]; then
TOOL_MODEL=32
fi
cd "$DMD_DIR"
"$HOST_DC" -m$TOOL_MODEL compiler/src/build.d -ofgenerated/build.exe
generated/build.exe -j$N MODEL=$TOOL_MODEL HOST_DMD=$HOST_DC BUILD=debug "${disable_debug_for_unittests[@]}" unittest
generated/build.exe -j$N MODEL=$TOOL_MODEL HOST_DMD=$HOST_DC DFLAGS="-L-LARGEADDRESSAWARE" ENABLE_RELEASE=1 ENABLE_ASSERTS=1 dmd
DMD_BIN_PATH="$DMD_DIR/generated/windows/release/$TOOL_MODEL/dmd.exe"
################################################################################
# Build Druntime and Phobos
################################################################################
"$GNU_MAKE" -j$N -C "$DMD_DIR/druntime" MODEL=$MODEL DMD="$DMD_BIN_PATH"
"$GNU_MAKE" -j$N -C "$DMD_DIR/../phobos" MODEL=$MODEL DMD="$DMD_BIN_PATH" CC="$CC" DMD_DIR="$DMD_DIR"
################################################################################
# Run DMD testsuite
################################################################################
cd "$DMD_DIR/compiler/test"
# Rebuild dmd with ENABLE_COVERAGE for coverage tests
if [ "${DMD_TEST_COVERAGE:-0}" = "1" ] ; then
# Recompile debug dmd + unittests
rm -rf "$DMD_DIR/generated/windows"
../../generated/build.exe -j$N MODEL=$TOOL_MODEL DFLAGS="-L-LARGEADDRESSAWARE" ENABLE_DEBUG=1 ENABLE_COVERAGE=1 dmd
../../generated/build.exe -j$N MODEL=$TOOL_MODEL DFLAGS="-L-LARGEADDRESSAWARE" ENABLE_DEBUG=1 ENABLE_COVERAGE=1 unittest
fi
"$HOST_DC" -m$TOOL_MODEL -g -i run.d
if [ "$MODEL" == "32omf" ] ; then
# Pre-build the tools while the host compiler's sc.ini is untampered (see below).
./run tools
# WORKAROUND: Make Optlink use freshly built Phobos, not the host compiler's.
# Optlink apparently prefers LIB in sc.ini (in the same dir as optlink.exe)
# over the LIB env variable (and `-conf=` for DMD apparently doesn't prevent
# that, and there's apparently no sane way to specify a libdir for Optlink
# in the DMD cmdline either).
rm "$DMD_DIR/tools/dmd2/windows/bin/sc.ini"
# We also need to remove LIB from the freshly built compiler's sc.ini -
# not all test invocations use `-conf=`.
sed -i 's|^LIB=.*$||g' "$DMD_DIR/generated/windows/release/$TOOL_MODEL/sc.ini"
# Okay, now the lib directories are controlled by the LIB env variable.
# run.d prepends the dir containing freshly built phobos.lib; we still need
# the DMC and Windows libs from the host compiler.
export LIB="$DMD_DIR/tools/dmd2/windows/lib"
fi
targets=("all")
args=('ARGS=-O -inline -g') # no -release for faster builds
if [ "$HOST_DMD_VERSION" = "2.079.0" ] ; then
# skip runnable_cxx and unit_tests with older bootstrap compilers
targets=("runnable" "compilable" "fail_compilation" "dshell")
args=() # use default set of args
fi
./run --environment --jobs=$N "${targets[@]}" "${args[@]}" CC="$CC" CXX="$CXX"
###############################################################################
# Upload coverage reports and exit if ENABLE_COVERAGE is specified
################################################################################
if [ "${DMD_TEST_COVERAGE:-0}" = "1" ] ; then
# Skip druntime & phobos tests
exit 0
fi
################################################################################
# Build and run druntime tests
################################################################################
cd "$DMD_DIR/druntime"
"$GNU_MAKE" -j$N MODEL=$MODEL DMD="$DMD_BIN_PATH" CC="$CC" unittest
if [ "$MODEL" != "32omf" ] ; then
# run some tests for shared druntime
# no separate output for static or shared builds, so clean directories to force rebuild
rm -rf test/shared/generated
# the test_runner links against libdruntime-ut.dll and runs all unittests
# no matter what module name is passed in, so restrict to src/object.d
"$GNU_MAKE" -j$N unittest MODEL=$MODEL SHARED=1 DMD="$DMD_BIN_PATH" CC="$CC" UT_SRCS=src/object.d ADDITIONAL_TESTS=test/shared
fi
################################################################################
# Build and run Phobos unittests
################################################################################
if [ "$MODEL" = "32omf" ] ; then
echo "FIXME: cannot compile 32-bit OMF Phobos unittests ('more than 32767 symbols in object file')"
else
cd "$DMD_DIR/../phobos"
if [ "$MODEL" = "64" ] ; then
cp "$DMD_DIR/tools/dmd2/windows/bin64/libcurl.dll" .
else
cp "$DMD_DIR/tools/dmd2/windows/bin/libcurl.dll" .
fi
"$GNU_MAKE" -j$N MODEL=$MODEL DMD="$DMD_BIN_PATH" CC="$CC" DMD_DIR="$DMD_DIR" unittest
fi
################################################################################
# Prepare artifacts
################################################################################
mkdir -p "$DMD_DIR/artifacts"
cd "$DMD_DIR/artifacts"
cp "$DMD_DIR/../phobos/$LIBNAME" .
cp "$DMD_BIN_PATH" .