Skip to content

Commit c68bff1

Browse files
authored
Merge pull request #4826 from kinke/gha_musl
GHA: Integrate Alpine musl job in main workflow
2 parents c71848f + dd9bf83 commit c68bff1

File tree

16 files changed

+162
-164
lines changed

16 files changed

+162
-164
lines changed

.github/actions/4c-test-dmd/action.yml

+14-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,20 @@ runs:
99
- name: 'Posix: Run DMD testsuite'
1010
if: runner.os != 'Windows'
1111
shell: bash
12-
run: cd ../build && ctest -V -R "dmd-testsuite"
12+
run: |
13+
set -eux
14+
repoDir=$PWD
15+
cd ../build
16+
if type -P apk &>/dev/null; then
17+
# Alpine: run full dmd-testsuite-debug
18+
ctest -V -R 'dmd-testsuite' -E '^dmd-testsuite$'
19+
# these two tests require extra flags "-link-defaultlib-debug -frame-pointer=all": https://github.com/ldc-developers/ldc/issues/4694
20+
# => remove before running optimized dmd-testsuite separately
21+
rm $repoDir/tests/dmd/runnable/{test17559.d,test19086.d}
22+
ctest -V -R '^dmd-testsuite$'
23+
else
24+
ctest -V -R "dmd-testsuite"
25+
fi
1326
1427
- name: 'Windows: Run DMD testsuite'
1528
if: runner.os == 'Windows'

.github/actions/6-integration-test/action.yml

+5-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ runs:
2121
fi
2222
installed/bin/ldc2 hello.d -link-defaultlib-shared
2323
./hello
24-
if [[ '${{ runner.os }}-${{ inputs.arch }}' == Linux-x86_64 ]]; then
24+
if [[ -d installed/lib32 ]]; then
2525
installed/bin/ldc2 hello.d -m32 -link-defaultlib-shared
2626
./hello
2727
fi
@@ -34,7 +34,7 @@ runs:
3434
for mode in thin full; do
3535
installed/bin/ldc2 hello.d -of=hello_$mode -flto=$mode -defaultlib=phobos2-ldc-lto,druntime-ldc-lto
3636
./hello_$mode
37-
if [[ '${{ runner.os }}-${{ inputs.arch }}' == Linux-x86_64 ]]; then
37+
if [[ -d installed/lib32 ]]; then
3838
installed/bin/ldc2 hello.d -m32 -of=hello_$mode-32 -flto=$mode -defaultlib=phobos2-ldc-lto,druntime-ldc-lto
3939
./hello_$mode-32
4040
fi
@@ -45,6 +45,9 @@ runs:
4545
run: |
4646
set -eux
4747
cd ..
48+
if type -P apk &>/dev/null; then
49+
exit 0 # Alpine: disabled dynamic-compile support
50+
fi
4851
if [[ '${{ runner.os }}' == Windows ]]; then
4952
# add ldc-jit.dll dir to PATH
5053
export PATH="$PWD/installed/bin:$PATH"

.github/actions/7-package/action.yml

+26-7
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ runs:
4949
cd dlang-tools
5050
git checkout "$(cat ../ldc/packaging/dlang-tools_version)"
5151
52+
# Alpine: build these tools as fully static executables
53+
if [[ '${{ inputs.os }}' == 'alpine' ]]; then
54+
export DFLAGS="-Xcc=-static${DFLAGS:+ $DFLAGS}"
55+
fi
56+
5257
mkdir bin
5358
$DMD -w -de -dip1000 rdmd.d -of=bin/rdmd
5459
$DMD -w -de -dip1000 ddemangle.d -of=bin/ddemangle
@@ -73,16 +78,29 @@ runs:
7378
"$(dirname "$DMD")/ldc2" -run list_payload.d .
7479
fi
7580
76-
# use host compiler's dub, which is guaranteed to be native
77-
DFLAGS="-O -linkonce-templates ${DFLAGS:-}" dub build -v \
78-
--build-mode=allAtOnce --combined $archFlag \
79-
--compiler="$(dirname "$DMD")/ldc2"
81+
# prefer host compiler's dub, which is guaranteed to be native
82+
PATH="$PATH:$PWD/../installed/bin" \
83+
DFLAGS="-O -linkonce-templates ${DFLAGS:-}" \
84+
dub build -v \
85+
--build-mode=allAtOnce --combined $archFlag \
86+
--compiler="$(dirname "$DMD")/ldc2"
8087
cp bin/reggae ../installed/bin/
8188
8289
if [[ '${{ inputs.cross_target_triple }}' == '' ]]; then
8390
../installed/bin/reggae --version -b ninja
8491
fi
8592
93+
- name: 'Linux: List executable dependencies'
94+
if: runner.os == 'Linux'
95+
shell: bash
96+
run: |
97+
set -euxo pipefail
98+
cd ../installed/bin
99+
for i in *; do
100+
ls -lh $i
101+
readelf -d $i | grep NEEDED || true
102+
done
103+
86104
- name: Pack installation dir
87105
shell: bash
88106
run: |
@@ -120,10 +138,11 @@ runs:
120138
chmod -R go=rX $artifactName
121139
if [[ '${{ runner.os }}' == macOS ]]; then
122140
sudo chown -R root:wheel $artifactName
123-
tar -cf - $artifactName | 7za a artifacts/$artifactName.tar.xz -si -txz -mx9
124-
else
125-
tar -cf - --owner=0 --group=0 $artifactName | 7za a artifacts/$artifactName.tar.xz -si -txz -mx9
141+
# note: already running as root in Alpine container, *and* potential busybox complication
142+
elif [[ $os != alpine ]]; then
143+
sudo chown -R 0:0 $artifactName
126144
fi
145+
tar -cf - $artifactName | 7za a artifacts/$artifactName.tar.xz -si -txz -mx9
127146
fi
128147
129148
# export ARTIFACT_{ID,NAME}

.github/workflows/alpine_musl.yml

-84
This file was deleted.

.github/workflows/main.yml

+41-4
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,27 @@ jobs:
5353
-DEXTRA_CXXFLAGS=-flto=full
5454
with_pgo: true
5555

56+
- job_name: Alpine musl x86_64
57+
os: ubuntu-latest
58+
container_image: alpine:3.20
59+
arch: x86_64
60+
bootstrap_cmake_flags: -DBUILD_LTO_LIBS=ON
61+
# TSan and XRay do not work.
62+
extra_cmake_flags: >-
63+
-DBUILD_LTO_LIBS=ON
64+
-DLLVM_IS_SHARED=OFF
65+
-DLDC_ENABLE_PLUGINS=OFF
66+
-DLDC_DYNAMIC_COMPILE=OFF
67+
-DLDC_INSTALL_LTOPLUGIN=OFF
68+
-DCOMPILER_RT_LIBDIR_OS=linux
69+
-DLDC_INSTALL_LLVM_RUNTIME_LIBS_ARCH=x86_64
70+
-DTEST_COMPILER_RT_LIBRARIES="profile;lsan;asan;msan;fuzzer"
71+
-DCMAKE_EXE_LINKER_FLAGS=-static-libstdc++
72+
-DLDC_FULLY_STATIC=ON
73+
-DD_COMPILER_FLAGS="-O -flto=full"
74+
# FIXME: -defaultlib=phobos2-ldc-lto,druntime-ldc-lto
75+
with_pgo: false
76+
5677
- job_name: macOS x86_64
5778
os: macos-13
5879
arch: x86_64
@@ -108,18 +129,33 @@ jobs:
108129
env:
109130
MACOSX_DEPLOYMENT_TARGET: ${{ matrix.arch == 'arm64' && '11.0' || '10.12' }}
110131
steps:
111-
- name: 'Container: Install git and sudo'
132+
- name: 'Set up Linux container'
112133
if: matrix.container_image
113-
shell: bash
114134
run: |
115135
set -eux
116-
apt-get -q update
117-
DEBIAN_FRONTEND=noninteractive apt-get -yq install git-core sudo
136+
if type -P apt-get &>/dev/null; then
137+
# Ubuntu: pre-install git and sudo
138+
apt-get -q update
139+
DEBIAN_FRONTEND=noninteractive apt-get -yq install git-core sudo
140+
else
141+
# set up Alpine container
142+
apk add \
143+
git cmake ninja-is-really-ninja g++ ldc llvm-dev llvm-static compiler-rt \
144+
libxml2-static zstd-static zlib-static \
145+
bash grep diffutils make curl 7zip perl
146+
# create missing 7za symlink
147+
ln -s 7z /usr/bin/7za
148+
# create ../llvm symlink to distro LLVM (no prebuilt LDC-LLVM for musl)
149+
ln -s /usr/lib/llvm17 $(dirname $(pwd))/llvm
150+
../llvm/bin/llvm-config --version
151+
fi
118152
- uses: actions/checkout@v4
119153
with:
120154
submodules: true
121155
fetch-depth: 50
122156
- name: Install prerequisites
157+
if: |
158+
!startsWith(matrix.container_image, 'alpine')
123159
uses: ./.github/actions/1-setup
124160
with:
125161
llvm_version: ${{ matrix.llvm_version || env.LLVM_VERSION }}
@@ -194,6 +230,7 @@ jobs:
194230
uses: ./.github/actions/7-package
195231
with:
196232
arch: ${{ matrix.arch }}
233+
os: ${{ startsWith(matrix.container_image, 'alpine') && 'alpine' || '' }}
197234

198235

199236
# Cross-compilation jobs for non-native targets.

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#### Big news
44
- LLVM for prebuilt packages bumped to v19.1.7. (#4822)
5+
- New prebuilt package for Alpine Linux x86_64 with musl libc. It's currently generated on Alpine v3.20, using its default LLVM 17. Most bundled executables are fully static and can be run on ~all distros. (#4826)
56
- Revived dynamic-compile (JIT) functionality (formerly unsupported since LLVM 12), supporting LLVM 18+ now. (#4774)
67
- ldc2.conf: `%%ldcversion%%` placeholder added, allowing to refer to version-specific directories.
78

CMakeLists.txt

+10-4
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,12 @@ else()
315315
separate_arguments(LLVM_LDFLAGS UNIX_COMMAND "${LLVM_LDFLAGS}")
316316
endif()
317317

318+
option(LDC_FULLY_STATIC "Posix: Link most executables (compiler and tools) as fully-static binaries" OFF)
319+
set(FULLY_STATIC_LDFLAG)
320+
if(UNIX AND LDC_FULLY_STATIC)
321+
set(FULLY_STATIC_LDFLAG "-static")
322+
endif()
323+
318324
# Suppress superfluous randlib warnings about "*.a" having no symbols on MacOSX.
319325
if (APPLE)
320326
set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
@@ -708,7 +714,7 @@ build_d_executable(
708714
"${LDC_EXE_FULL}"
709715
"${LDC_D_SOURCE_FILES}"
710716
"${DFLAGS_BUILD_TYPE} ${DFLAGS_LDC}"
711-
"${ALTERNATIVE_MALLOC_O};${LDC_LINKERFLAG_LIST}"
717+
"${ALTERNATIVE_MALLOC_O};${LDC_LINKERFLAG_LIST};${FULLY_STATIC_LDFLAG}"
712718
"${FE_RES}"
713719
"${LDC_LIB}"
714720
${COMPILE_D_MODULES_SEPARATELY}
@@ -743,7 +749,7 @@ build_d_executable(
743749
"${LDMD_EXE_FULL}"
744750
"${LDMD_D_SOURCE_FILES}"
745751
"${DFLAGS_BUILD_TYPE}"
746-
"${LDC_LINKERFLAG_LIST}"
752+
"${LDC_LINKERFLAG_LIST};${FULLY_STATIC_LDFLAG}"
747753
""
748754
"LDMD_CXX_LIB"
749755
${COMPILE_D_MODULES_SEPARATELY}
@@ -927,7 +933,7 @@ build_d_executable(
927933
"${LDC_UNITTEST_EXE_FULL}"
928934
"${LDC_D_SOURCE_FILES}"
929935
"-g -unittest ${DFLAGS_LDC}"
930-
"${LDC_LINKERFLAG_LIST}"
936+
"${LDC_LINKERFLAG_LIST};${FULLY_STATIC_LDFLAG}"
931937
""
932938
"${LDC_LIB}"
933939
${COMPILE_D_MODULES_SEPARATELY}
@@ -957,7 +963,7 @@ build_d_executable(
957963
"${LDC_BUILD_RUNTIME_EXE_FULL}"
958964
"${PROJECT_BINARY_DIR}/ldc-build-runtime.d"
959965
"${DFLAGS_BUILD_TYPE}"
960-
""
966+
"" # must not be fully static for std.net.curl support (loading libcurl dynamically)
961967
"${PROJECT_SOURCE_DIR}/runtime/ldc-build-runtime.d.in"
962968
""
963969
${COMPILE_D_MODULES_SEPARATELY}

cmake/Modules/BuildDExecutable.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ function(build_d_executable target_name output_exe d_src_files compiler_args lin
9595
list(APPEND dep_libs "-L$<TARGET_LINKER_FILE:${l}>")
9696
endforeach()
9797

98-
set(full_linker_args ${CMAKE_EXE_LINKER_FLAGS} ${linker_args})
98+
set(full_linker_args ${CMAKE_EXE_LINKER_FLAGS} ${linker_args} ${D_LINKER_ARGS})
9999
translate_linker_args(full_linker_args translated_linker_args)
100100

101101
# We need to link against the C++ runtime library.

cmake/Modules/FindLLVM.cmake

+23-9
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,16 @@ else()
8080
if(LLVM_FIND_QUIETLY)
8181
set(_quiet_arg ERROR_QUIET)
8282
endif()
83+
if(DEFINED LLVM_IS_SHARED)
84+
if(LLVM_IS_SHARED)
85+
set(_sharedstatic "--link-shared")
86+
else()
87+
set(_sharedstatic "--link-static")
88+
endif()
89+
endif()
8390
set(result_code)
8491
execute_process(
85-
COMMAND ${LLVM_CONFIG} --${flag}
92+
COMMAND ${LLVM_CONFIG} ${_sharedstatic} --${flag}
8693
RESULT_VARIABLE result_code
8794
OUTPUT_VARIABLE LLVM_${var}
8895
OUTPUT_STRIP_TRAILING_WHITESPACE
@@ -100,9 +107,14 @@ else()
100107
if(LLVM_FIND_QUIETLY)
101108
set(_quiet_arg ERROR_QUIET)
102109
endif()
110+
if (LLVM_IS_SHARED)
111+
set(_sharedstatic "--link-shared")
112+
else()
113+
set(_sharedstatic "--link-static")
114+
endif()
103115
set(result_code)
104116
execute_process(
105-
COMMAND ${LLVM_CONFIG} --${flag} ${components}
117+
COMMAND ${LLVM_CONFIG} ${_sharedstatic} --${flag} ${components}
106118
RESULT_VARIABLE result_code
107119
OUTPUT_VARIABLE tmplibs
108120
OUTPUT_STRIP_TRAILING_WHITESPACE
@@ -116,6 +128,15 @@ else()
116128
endif()
117129
endmacro()
118130

131+
if (NOT DEFINED LLVM_IS_SHARED)
132+
llvm_set(SHARED_MODE shared-mode)
133+
if(LLVM_SHARED_MODE STREQUAL "shared")
134+
set(LLVM_IS_SHARED ON)
135+
else()
136+
set(LLVM_IS_SHARED OFF)
137+
endif()
138+
endif()
139+
119140
llvm_set(VERSION_STRING version)
120141
llvm_set(CXXFLAGS cxxflags)
121142
llvm_set(INCLUDE_DIRS includedir true)
@@ -127,13 +148,6 @@ else()
127148
string(REGEX REPLACE "([0-9]+).*" "\\1" LLVM_VERSION_MAJOR "${LLVM_VERSION_STRING}" )
128149
string(REGEX REPLACE "[0-9]+\\.([0-9]+).*[A-Za-z]*" "\\1" LLVM_VERSION_MINOR "${LLVM_VERSION_STRING}" )
129150

130-
llvm_set(SHARED_MODE shared-mode)
131-
if(LLVM_SHARED_MODE STREQUAL "shared")
132-
set(LLVM_IS_SHARED ON)
133-
else()
134-
set(LLVM_IS_SHARED OFF)
135-
endif()
136-
137151
llvm_set(LDFLAGS ldflags)
138152
llvm_set(SYSTEM_LIBS system-libs)
139153
string(REPLACE "\n" " " LLVM_LDFLAGS "${LLVM_LDFLAGS} ${LLVM_SYSTEM_LIBS}")

0 commit comments

Comments
 (0)