Skip to content

Commit

Permalink
druntime: Make most *test* Makefiles usable on Windows too
Browse files Browse the repository at this point in the history
Still to do: `test/{shared,stdcpp}`.
  • Loading branch information
kinke authored and thewilsonator committed Dec 17, 2023
1 parent 1bd0c93 commit b99b9d2
Show file tree
Hide file tree
Showing 38 changed files with 303 additions and 435 deletions.
11 changes: 6 additions & 5 deletions .azure-pipelines/windows-msbuild.bat
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
setlocal
@echo on

:: put bash and GNU tools in front of PATH
set PATH=C:\Program Files\Git\usr\bin;%PATH%

:: now set up MSVC environment (=> first link.exe etc. in PATH is MSVC's, not GNU's)
call "%VSINSTALLDIR%\VC\Auxiliary\Build\vcvarsall.bat" %ARCH%
@echo on

Expand Down Expand Up @@ -60,7 +65,6 @@ run.exe tools "BUILD=%CONFIGURATION%" "DMD_MODEL=%PLATFORM%" || exit /B 4
:: FIXME: skip unit_tests temporarily due to unclear (spurious?) CI failures
:: set DMD_TESTS=all
set DMD_TESTS=runnable runnable_cxx compilable fail_compilation dshell
set DRUNTIME_TESTS=test_all
cd "%DMD_DIR%"
if not "%C_RUNTIME%" == "mingw" goto not_mingw
rem install recent LLD and mingw libraries to built dmd
Expand All @@ -86,15 +90,12 @@ if not "%C_RUNTIME%" == "mingw" goto not_mingw
set DMD_TESTS=runnable compilable fail_compilation dshell
rem FIXME: debug info incomplete when linking through lld-link
del compiler\test\runnable\testpdb.d

set DRUNTIME_TESTS=test_mingw
:not_mingw

echo [STEP]: Building and running druntime tests
cd "%DMD_DIR%\druntime"
:: only build & run the debug unittests, skip the release ones (Azure CI running out of memory when doing these in parallel)
make -j%N% MODEL=%MODEL% "DMD=%DMD%" BUILD=debug unittest || exit /B 5
"%DM_MAKE%" -f win64.mak MODEL=%MODEL% "DMD=%DMD%" "VCDIR=%VCINSTALLDIR%." "CC=%MSVC_CC%" "MAKE=%DM_MAKE%" %DRUNTIME_TESTS% || exit /B 5
make -j%N% MODEL=%MODEL% "DMD=%DMD%" BUILD=debug "CC=%MSVC_CC%" unittest || exit /B 5

echo [STEP]: Running DMD testsuite
cd "%DMD_DIR%\compiler\test"
Expand Down
3 changes: 1 addition & 2 deletions .azure-pipelines/windows.sh
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,7 @@ fi
################################################################################

cd "$DMD_DIR/druntime"
"$GNU_MAKE" -j$N MODEL=$MODEL DMD="$DMD_BIN_PATH" unittest
"$DM_MAKE" "${LIBS_MAKE_ARGS[@]}" test_all
"$GNU_MAKE" -j$N MODEL=$MODEL DMD="$DMD_BIN_PATH" CC="$CC" unittest

################################################################################
# Build and run Phobos unittests
Expand Down
5 changes: 4 additions & 1 deletion compiler/src/osmodel.mak
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ endif
ifeq (windows,$(OS))
# Note: setting SHELL to an absolute path to bash.exe does NOT suffice.
# The GNU tools like {rm,cp,mkdir}.exe need to be in PATH.
export PATH:=C:\Program Files\Git\usr\bin;$(PATH)
ifeq (,$(findstring C:\Program Files\Git\usr\bin,$(PATH)))
export PATH:=C:\Program Files\Git\usr\bin;$(PATH)
endif
# setting SHELL is very special on Windows: https://www.gnu.org/software/make/manual/html_node/Choosing-the-Shell.html#Choosing-a-Shell-in-DOS-and-Windows
SHELL=bash.exe
$(info Using make SHELL "$(SHELL)", should be bash.)
endif
Expand Down
1 change: 0 additions & 1 deletion druntime/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ druntime.json
.DS_Store
trace.def
trace.log
/Makefile
/errno_c*.obj
/msvc*.obj
make
Expand Down
16 changes: 9 additions & 7 deletions druntime/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -410,14 +410,16 @@ $(DRUNTIME): $(OBJS) $(SRCS) $(DMD)
lib: $(DRUNTIME)

UT_MODULES:=$(patsubst src/%.d,$(ROOT)/unittest/%,$(SRCS))
# TODO: Windows
HAS_ADDITIONAL_TESTS:=$(if $(findstring $(OS),windows),,$(shell test -d test && echo 1))
HAS_ADDITIONAL_TESTS:=$(shell test -d test && echo 1)
ifeq ($(HAS_ADDITIONAL_TESTS),1)
ADDITIONAL_TESTS:=test/init_fini test/exceptions test/coverage test/profile test/cycles test/allocations test/typeinfo \
test/aa test/cpuid test/gc test/hash test/lifetime \
test/thread test/unittest test/imports test/betterc test/stdcpp test/config \
test/traits test/valgrind
ADDITIONAL_TESTS+=$(if $(SHARED),test/shared,)
ADDITIONAL_TESTS:=test/init_fini test/exceptions test/coverage test/profile test/cycles test/allocations test/typeinfo \
test/aa test/cpuid test/gc test/hash test/lifetime \
test/thread test/unittest test/imports test/betterc test/config \
test/traits test/uuid test/valgrind
ifneq (windows,$(OS)) # FIXME
ADDITIONAL_TESTS+=test/stdcpp
endif
ADDITIONAL_TESTS+=$(if $(SHARED),test/shared,)
endif

.PHONY : unittest
Expand Down
4 changes: 2 additions & 2 deletions druntime/test/aa/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ TESTS:=test_aa
.PHONY: all clean
all: $(addprefix $(ROOT)/,$(addsuffix .done,$(TESTS)))

$(ROOT)/test_aa.done: $(ROOT)/%.done : $(ROOT)/%
$(ROOT)/%.done: $(ROOT)/%$(DOTEXE)
@echo Testing $*
$(QUIET)$(TIMELIMIT)$(ROOT)/$* $(RUN_ARGS)
@touch $@

$(ROOT)/%: $(SRC)/%.d
$(ROOT)/%$(DOTEXE): $(SRC)/%.d
$(QUIET)$(DMD) $(DFLAGS) -of$@ $<

clean:
Expand Down
10 changes: 5 additions & 5 deletions druntime/test/allocations/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ SED:=sed
.PHONY: all clean
all: $(addprefix $(ROOT)/,$(addsuffix .done,$(TESTS)))

$(ROOT)/alloc_from_assert.done: $(ROOT)/alloc_from_assert
$(ROOT)/alloc_from_assert.done: $(ROOT)/alloc_from_assert$(DOTEXE)
@echo Testing $*
$(QUIET)$(TIMELIMIT)$(ROOT)/alloc_from_assert $(RUN_ARGS)
@touch $@

$(ROOT)/overflow_from_zero.done: STDERR_EXP="Memory allocation failed"
$(ROOT)/overflow_from_existing.done: STDERR_EXP="Memory allocation failed"
$(ROOT)/%.done: $(ROOT)/%
$(ROOT)/%.done: $(ROOT)/%$(DOTEXE)
@echo Testing $*
$(NEGATE) $(QUIET)$(TIMELIMIT)$(ROOT)/$* $(RUN_ARGS) 2>&1 1>/dev/null | head -n 1 | grep -qF $(STDERR_EXP)
$(NEGATE) $(QUIET)$(TIMELIMIT)$(ROOT)/$* $(RUN_ARGS) 2>&1 1>/dev/null | head -n 2 | grep -qF $(STDERR_EXP)
@touch $@

$(ROOT)/unittest_assert: DFLAGS+=-unittest -version=CoreUnittest
$(ROOT)/%: $(SRC)/%.d
$(ROOT)/unittest_assert$(DOTEXE): DFLAGS+=-unittest -version=CoreUnittest
$(ROOT)/%$(DOTEXE): $(SRC)/%.d
$(QUIET)$(DMD) $(DFLAGS) -of$@ $<

clean:
Expand Down
12 changes: 0 additions & 12 deletions druntime/test/allocations/win64.mak

This file was deleted.

16 changes: 12 additions & 4 deletions druntime/test/betterc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,23 @@ include ../common.mak
TESTS:=test18828 test19416 test19421 test19561 test20088 test20613 test19924 test22336 test19933

.PHONY: all clean
all: $(addprefix $(ROOT)/,$(addsuffix ,$(TESTS))) $(addprefix $(ROOT)/,test19924.done)
all: $(addprefix $(ROOT)/,$(addsuffix .done,$(TESTS)))

$(ROOT)/test19924.done: $(ROOT)/%.done : $(ROOT)/%
$(ROOT)/%.done: $(ROOT)/%$(DOTEXE)
@echo Running $*
$(QUIET)$(TIMELIMIT)$(ROOT)/$* $(RUN_ARGS)
@touch $@

$(ROOT)/%: $(SRC)/%.d
$(QUIET)$(DMD) -betterC -of$@ $<
# for the Windows MinGW CI job:
ifneq (,$(findstring -mscrtlib=msvcrt120,$(DFLAGS)))
# DFLAGS=-mscrtlib=msvcrt120 takes precedence over any command line flags, so
# specify vcruntime140.lib explicitly for using mingw with Universal CRT.
$(ROOT)/test19933$(DOTEXE): $(SRC)/test19933.d
$(QUIET)$(DMD) $(MODEL_FLAG) -I../../src -betterC -of$@ $< -Lvcruntime140.lib -Llegacy_stdio_definitions.lib -L/NODEFAULTLIB:msvcrt120.lib
endif

$(ROOT)/%$(DOTEXE): $(SRC)/%.d
$(QUIET)$(DMD) $(MODEL_FLAG) -I../../src -betterC -of$@ $<

clean:
rm -rf $(ROOT)
50 changes: 0 additions & 50 deletions druntime/test/betterc/win64.mak

This file was deleted.

46 changes: 30 additions & 16 deletions druntime/test/common.mak
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# set from top makefile
# set explicitly in the make cmdline in druntime/Makefile (`test/%/.run` rule):
OS:=
MODEL:=
BUILD:=
Expand All @@ -8,30 +8,44 @@ DRUNTIMESO:=
LINKDL:=
QUIET:=
TIMELIMIT:=
LDL:=$(subst -L,,$(LINKDL)) # -ldl
PIC:=

# Windows: set up bash shell
ifeq (windows,$(OS))
include ../../../compiler/src/osmodel.mak
endif

LDL:=$(subst -L,,$(LINKDL)) # -ldl
SRC:=src
GENERATED:=./generated
ROOT:=$(GENERATED)/$(OS)/$(BUILD)/$(MODEL)

ifneq (default,$(MODEL))
MODEL_FLAG:=-m$(MODEL)
MODEL_FLAG:=$(if $(findstring $(MODEL),default),,-m$(MODEL))
CFLAGS_BASE:=$(if $(findstring $(OS),windows),/Wall,$(MODEL_FLAG) $(PIC) -Wall)
ifeq (osx64,$(OS)$(MODEL))
CFLAGS_BASE+=--target=x86_64-darwin-apple # ARM cpu is not supported by dmd
endif
CFLAGS_BASE:= $(MODEL_FLAG) $(PIC) -Wall
ifeq (osx,$(OS))
ifeq (64,$(MODEL))
CFLAGS_BASE+=--target=x86_64-darwin-apple # ARM cpu is not supported by dmd
endif
endif
DFLAGS:=$(MODEL_FLAG) $(PIC) -w -I../../src -I../../import -I$(SRC) -defaultlib= -debuglib= -preview=dip1000 -L-lpthread -L-lm $(LINKDL)
DFLAGS:=$(MODEL_FLAG) $(PIC) -w -I../../src -I../../import -I$(SRC) -defaultlib= -preview=dip1000 $(if $(findstring $(OS),windows),,-L-lpthread -L-lm $(LINKDL))
# LINK_SHARED may be set by importing makefile
DFLAGS+=$(if $(LINK_SHARED),-L$(DRUNTIMESO),-L$(DRUNTIME))
ifeq ($(BUILD),debug)
DFLAGS += -g -debug
CFLAGS := $(CFLAGS_BASE) -g
DFLAGS+=-g -debug
CFLAGS:=$(CFLAGS_BASE) $(if $(findstring $(OS),windows),/Zi,-g)
else
DFLAGS += -O -release
CFLAGS := $(CFLAGS_BASE) -O3
DFLAGS+=-O -release
CFLAGS:=$(CFLAGS_BASE) $(if $(findstring $(OS),windows),/O2,-O3)
endif
CXXFLAGS_BASE := $(CFLAGS_BASE)
CXXFLAGS_BASE:=$(CFLAGS_BASE)
CXXFLAGS:=$(CFLAGS)

ifeq (windows,$(OS))
DOTEXE:=.exe
DOTDLL:=.dll
DOTLIB:=.lib
DOTOBJ:=.obj
else
DOTEXE:=
DOTDLL:=$(if $(findstring $(OS),osx),.dylib,.so)
DOTLIB:=.a
DOTOBJ:=.o
endif
10 changes: 5 additions & 5 deletions druntime/test/config/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@ TESTS:=test19433 test20459 test22523
.PHONY: all clean
all: $(addprefix $(ROOT)/,$(addsuffix .done,$(TESTS)))

$(ROOT)/%: $(SRC)/%.d
$(ROOT)/%$(DOTEXE): $(SRC)/%.d
$(QUIET)$(DMD) $(DFLAGS) -of$@ $<

$(ROOT)/test19433.done: $(ROOT)/test19433
$(ROOT)/test19433.done: $(ROOT)/test19433$(DOTEXE)
@echo Testing test19433
$(QUIET)$(ROOT)/test19433 --DRT-dont-eat-me
@touch $@

$(ROOT)/test20459.done: $(ROOT)/test20459
$(ROOT)/test20459.done: $(ROOT)/test20459$(DOTEXE)
@echo Testing test20459
$(QUIET)$(ROOT)/test20459 foo bar -- --DRT-gcopts=profile:1
@touch $@


$(ROOT)/test22523.done: $(SRC)/test22523.d
@echo Testing $<
$(QUIET)$(DMD) $(DFLAGS) -unittest -of$(ROOT)/test22523 $<
$(QUIET) $(ROOT)/test22523 -- --DRT-testmode=run-main
$(QUIET)$(DMD) $(DFLAGS) -unittest -of$(ROOT)/test22523$(DOTEXE) $<
$(QUIET)$(ROOT)/test22523 -- --DRT-testmode=run-main
@touch $@

clean:
Expand Down
Loading

0 comments on commit b99b9d2

Please sign in to comment.