Skip to content

Commit 3ca8953

Browse files
committed
GHA main: Add Alpine Linux job, to CI-test musl libc
Incl. some test fixes.
1 parent 047dfb5 commit 3ca8953

File tree

8 files changed

+99
-38
lines changed

8 files changed

+99
-38
lines changed

.github/workflows/main.yml

+14-4
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ jobs:
4949
os: ubuntu-22.04
5050
host_dmd: gdmd-9
5151
disable_debug_for_dmd_unittests: true # no `-debug` - host frontend too old
52+
- job_name: Alpine 3.21 x64, LDC
53+
os: ubuntu-latest
54+
container_image: alpine:3.21
55+
host_dmd: ldmd2
5256
# macOS
5357
- job_name: macOS 13 x64, DMD (latest)
5458
os: macos-13
@@ -74,6 +78,7 @@ jobs:
7478
model: 32
7579
name: ${{ matrix.job_name }}
7680
runs-on: ${{ matrix.os }}
81+
container: ${{ matrix.container_image }}
7782
timeout-minutes: 40
7883
env:
7984
# for ci/run.sh:
@@ -90,6 +95,11 @@ jobs:
9095
run:
9196
shell: bash
9297
steps:
98+
- name: 'Alpine container: Pre-install bash, git and sudo'
99+
if: startsWith(matrix.container_image, 'alpine')
100+
shell: sh
101+
run: apk add bash git sudo
102+
93103
- uses: actions/checkout@v4
94104
with:
95105
fetch-depth: 50
@@ -149,20 +159,20 @@ jobs:
149159
- name: Test dmd
150160
run: ci/run.sh test_dmd
151161
- name: Test druntime
152-
if: '!matrix.coverage'
162+
if: '!matrix.coverage && (success() || failure())'
153163
run: ci/run.sh test_druntime
154164
- name: 'Windows x86: Add 32-bit libcurl.dll to PATH (required for Phobos unittests)'
155-
if: runner.os == 'Windows' && env.MODEL == '32' && !matrix.coverage
165+
if: runner.os == 'Windows' && env.MODEL == '32' && !matrix.coverage && (success() || failure())
156166
run: |
157167
# LDC
158168
echo "$(dirname "$(which $DC)")/../lib32" >> $GITHUB_PATH
159169
# DMD
160170
echo "$(dirname "$(which $DC)")/../bin" >> $GITHUB_PATH
161171
- name: Test phobos
162-
if: '!matrix.coverage'
172+
if: '!matrix.coverage && (success() || failure())'
163173
run: ci/run.sh test_phobos
164174
- name: Test self-compile
165-
if: '!matrix.coverage' # already re-built with enabled coverage
175+
if: '!matrix.coverage && (success() || failure())' # already re-built with enabled coverage
166176
run: ENABLE_RELEASE=0 ci/run.sh rebuild
167177
- name: Upload coverage report
168178
if: matrix.coverage

ci/cirrusci.sh

+17-11
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,24 @@ if [ ! -z ${HOST_DC+x} ] ; then HOST_DMD=${HOST_DC}; fi
1515
if [ -z ${HOST_DMD+x} ] ; then echo "Variable 'HOST_DMD' needs to be set."; exit 1; fi
1616

1717
if [ "$OS_NAME" == "linux" ]; then
18-
export DEBIAN_FRONTEND=noninteractive
19-
packages="git-core make g++ gdb gnupg curl libcurl4 tzdata zip unzip xz-utils llvm valgrind libc6-dbg"
20-
if [ "$MODEL" == "32" ]; then
21-
dpkg --add-architecture i386
22-
packages="$packages g++-multilib libcurl4:i386 libc6-dbg:i386"
18+
if type -P apk &>/dev/null; then
19+
# Alpine
20+
apk add git make g++ ldc \
21+
bash grep coreutils diffutils curl gdb linux-headers dub
22+
else
23+
export DEBIAN_FRONTEND=noninteractive
24+
packages="git-core make g++ gdb gnupg curl libcurl4 tzdata zip unzip xz-utils llvm valgrind libc6-dbg"
25+
if [ "$MODEL" == "32" ]; then
26+
dpkg --add-architecture i386
27+
packages="$packages g++-multilib libcurl4:i386 libc6-dbg:i386"
28+
fi
29+
if [ "${HOST_DMD:0:4}" == "gdmd" ]; then
30+
# ci/run.sh uses `sudo add-apt-repository ...` to add a PPA repo
31+
packages="$packages sudo software-properties-common"
32+
fi
33+
apt-get -q update
34+
apt-get install -yq $packages
2335
fi
24-
if [ "${HOST_DMD:0:4}" == "gdmd" ]; then
25-
# ci/run.sh uses `sudo add-apt-repository ...` to add a PPA repo
26-
packages="$packages sudo software-properties-common"
27-
fi
28-
apt-get -q update
29-
apt-get install -yq $packages
3036
elif [ "$OS_NAME" == "osx" ]; then
3137
# upgrade GNU make
3238
brew install make

ci/run.sh

+10
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ test_dmd() {
123123
local args=(ARGS="-O -inline -release")
124124
fi
125125

126+
if type -P apk &>/dev/null; then
127+
# Alpine: no TLS variables support with gdb, https://gitlab.alpinelinux.org/alpine/aports/-/issues/11154
128+
rm compiler/test/runnable/gdb4181.d
129+
fi
130+
126131
$build_path/dmd -g -i -Icompiler/test -release compiler/test/run.d -ofgenerated/run
127132
generated/run -j$N --environment MODEL=$MODEL HOST_DMD=$build_path/dmd "${args[@]}"
128133
}
@@ -262,6 +267,11 @@ install_host_compiler() {
262267
echo "export DMD=gdmd-$gdc_version" > ~/dlang/gdc-$gdc_version/activate
263268
echo "deactivate(){ echo;}" >> ~/dlang/gdc-$gdc_version/activate
264269
fi
270+
elif type -P apk &>/dev/null; then
271+
# fake install script and create a fake 'activate' script
272+
mkdir -p ~/dlang/$HOST_DMD
273+
echo "export DMD=$HOST_DMD" > ~/dlang/$HOST_DMD/activate
274+
echo "deactivate(){ echo;}" >> ~/dlang/$HOST_DMD/activate
265275
else
266276
local install_sh="install.sh"
267277
download_install_sh "$install_sh"

druntime/test/exceptions/Makefile

+18-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
1-
TESTS=stderr_msg unittest_assert invalid_memory_operation unknown_gc static_dtor \
1+
ifeq ($(OS),linux)
2+
# FIXME: detect musl libc robustly; just checking Alpine Linux' apk tool for now
3+
ifeq (1,$(shell which apk &>/dev/null && echo 1))
4+
IS_MUSL:=1
5+
endif
6+
endif
7+
8+
TESTS=stderr_msg unittest_assert invalid_memory_operation static_dtor \
29
future_message refcounted rt_trap_exceptions_drt catch_in_finally \
310
message_with_null
411

12+
# FIXME: segfaults with musl libc
13+
ifneq ($(IS_MUSL),1)
14+
TESTS += unknown_gc
15+
endif
16+
517
# fails on 32 bit linux
618
ifneq ($(OS),linux)
719
TESTS += assert_fail
@@ -12,8 +24,11 @@ SED:=sed
1224
GDB:=gdb
1325

1426
ifeq ($(OS),linux)
15-
TESTS+=line_trace line_trace_21656 long_backtrace_trunc rt_trap_exceptions cpp_demangle \
16-
memoryerror_null_read memoryerror_null_write memoryerror_null_call memoryerror_stackoverflow
27+
TESTS+=line_trace line_trace_21656 long_backtrace_trunc rt_trap_exceptions cpp_demangle
28+
# registerMemoryAssertHandler requires glibc
29+
ifneq ($(IS_MUSL),1)
30+
TESTS+=memoryerror_null_read memoryerror_null_write memoryerror_null_call memoryerror_stackoverflow
31+
endif
1732
line_trace_dflags:=-L--export-dynamic
1833
endif
1934

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
TESTS := importc_compare
22

3+
# FIXME: fails on Alpine v3.21 with conflicting struct declarations in the C headers:
4+
# /usr/include/asm-generic/fcntl.h(195): Error: struct `importc_includes.flock` conflicts with struct `importc_includes.flock` at /usr/include/fcntl.h(24)
5+
ifeq ($(OS),linux)
6+
ifeq (1,$(shell which apk &>/dev/null && echo 1))
7+
TESTS :=
8+
endif
9+
endif
10+
311
include ../common.mak
412

513
extra_dflags += -d

druntime/test/shared/src/finalize.d

+10-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void main(string[] args)
4444
auto nf1 = new NoFinalize;
4545
auto nf2 = new NoFinalizeBig;
4646

47-
shared size_t finalizeCounter;
47+
static shared size_t finalizeCounter;
4848
SetFinalizeCounter setFinalizeCounter;
4949
loadSym(h, setFinalizeCounter, "setFinalizeCounter");
5050
setFinalizeCounter(&finalizeCounter);
@@ -57,8 +57,15 @@ void main(string[] args)
5757
auto r = Runtime.unloadLibrary(h);
5858
if (!r)
5959
assert(0);
60-
if (finalizeCounter != 4)
61-
assert(0);
60+
version (CRuntime_Musl)
61+
{
62+
// On Musl, dlclose is a no-op
63+
}
64+
else
65+
{
66+
if (finalizeCounter != 4)
67+
assert(0);
68+
}
6269
if (nf1._finalizeCounter)
6370
assert(0);
6471
if (nf2._finalizeCounter)

druntime/test/shared/src/load.d

+19-12
Original file line numberDiff line numberDiff line change
@@ -135,21 +135,28 @@ void main(string[] args)
135135

136136
runTests(name);
137137

138-
// lib is no longer resident
139-
name ~= '\0';
140-
version (Windows)
138+
version (CRuntime_Musl)
141139
{
142-
import core.sys.windows.winbase;
143-
assert(!GetModuleHandleA(name.ptr));
140+
// On Musl, dlclose is a no-op
144141
}
145142
else
146143
{
147-
import core.sys.posix.dlfcn : dlopen, RTLD_LAZY;
148-
assert(dlopen(name.ptr, RTLD_LAZY | RTLD_NOLOAD) is null);
144+
// lib is no longer resident
145+
name ~= '\0';
146+
version (Windows)
147+
{
148+
import core.sys.windows.winbase;
149+
assert(!GetModuleHandleA(name.ptr));
150+
}
151+
else
152+
{
153+
import core.sys.posix.dlfcn : dlopen, RTLD_LAZY;
154+
assert(dlopen(name.ptr, RTLD_LAZY | RTLD_NOLOAD) is null);
155+
}
156+
name = name[0 .. $-1];
157+
158+
auto thr = new Thread({runTests(name);});
159+
thr.start();
160+
thr.join();
149161
}
150-
name = name[0 .. $-1];
151-
152-
auto thr = new Thread({runTests(name);});
153-
thr.start();
154-
thr.join();
155162
}

druntime/test/shared/src/load_13414.d

+3-5
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,15 @@ void runTest(string name)
2020
*pLibSharedStaticDtorHook = &sharedStaticDtorHook;
2121

2222
const unloaded = Runtime.unloadLibrary(h);
23+
assert(unloaded);
24+
assert(tlsDtor == 1);
2325
version (CRuntime_Musl)
2426
{
25-
// On Musl, unloadLibrary is a no-op because dlclose is a no-op
26-
assert(!unloaded);
27-
assert(tlsDtor == 0);
27+
// On Musl, dlclose is a no-op
2828
assert(dtor == 0);
2929
}
3030
else
3131
{
32-
assert(unloaded);
33-
assert(tlsDtor == 1);
3432
assert(dtor == 1);
3533
}
3634
}

0 commit comments

Comments
 (0)