Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

musl CI: link LLVM statically (and everything else too) #4699

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .github/workflows/alpine_musl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,12 @@ jobs:
cd bootstrap
cmake -G Ninja .. \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX="/opt/ldc2" \
-DCMAKE_EXE_LINKER_FLAGS=-static-libstdc++ \
-DD_COMPILER_FLAGS=-link-defaultlib-shared=false \
-DBUILD_SHARED_LIBS=OFF
ninja obj/ldc2.o all
bin/ldc2 --version
cd ..

# TODO: Add '-DLLVM_IS_SHARED=OFF' when static linking is fully supported
# TSan and XRay do not work.
- name: Build LDC & LDC D unittests & defaultlib unittest runners
shell: alpine.sh {0}
Expand All @@ -50,7 +47,9 @@ jobs:
-DD_COMPILER=./bootstrap/bin/ldmd2 \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX="/opt/ldc2" \
-DCMAKE_EXE_LINKER_FLAGS=-static-libstdc++ \
-DINCLUDE_INSTALL_DIR="/opt/ldc2/import" \
-DLLVM_IS_SHARED=OFF \
-DCMAKE_EXE_LINKER_FLAGS=-static \
-DD_COMPILER_FLAGS=-link-defaultlib-shared=false \
-DBUILD_SHARED_LIBS=OFF \
-DTEST_COMPILER_RT_LIBRARIES="profile;lsan;asan;msan;fuzzer"
Expand Down
30 changes: 21 additions & 9 deletions cmake/Modules/FindLLVM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,14 @@ else()
if(LLVM_FIND_QUIETLY)
set(_quiet_arg ERROR_QUIET)
endif()
if (LLVM_IS_SHARED)
set(sharedstatic "--link-shared")
else()
set(sharedstatic "--link-static")
endif()
set(result_code)
execute_process(
COMMAND ${LLVM_CONFIG} --${flag}
COMMAND ${LLVM_CONFIG} ${sharedstatic} --${flag}
RESULT_VARIABLE result_code
OUTPUT_VARIABLE LLVM_${var}
OUTPUT_STRIP_TRAILING_WHITESPACE
Expand All @@ -97,9 +102,14 @@ else()
if(LLVM_FIND_QUIETLY)
set(_quiet_arg ERROR_QUIET)
endif()
if (LLVM_IS_SHARED)
set(sharedstatic "--link-shared")
else()
set(sharedstatic "--link-static")
endif()
set(result_code)
execute_process(
COMMAND ${LLVM_CONFIG} --${flag} ${components}
COMMAND ${LLVM_CONFIG} ${sharedstatic} --${flag} ${components}
RESULT_VARIABLE result_code
OUTPUT_VARIABLE tmplibs
OUTPUT_STRIP_TRAILING_WHITESPACE
Expand All @@ -113,6 +123,15 @@ else()
endif()
endmacro()

if (NOT DEFINED LLVM_IS_SHARED)
llvm_set(SHARED_MODE shared-mode)
if(LLVM_SHARED_MODE STREQUAL "shared")
set(LLVM_IS_SHARED ON)
else()
set(LLVM_IS_SHARED OFF)
endif()
endif()

llvm_set(VERSION_STRING version)
llvm_set(CXXFLAGS cxxflags)
llvm_set(INCLUDE_DIRS includedir true)
Expand All @@ -124,13 +143,6 @@ else()
string(REGEX REPLACE "([0-9]+).*" "\\1" LLVM_VERSION_MAJOR "${LLVM_VERSION_STRING}" )
string(REGEX REPLACE "[0-9]+\\.([0-9]+).*[A-Za-z]*" "\\1" LLVM_VERSION_MINOR "${LLVM_VERSION_STRING}" )

llvm_set(SHARED_MODE shared-mode)
if(LLVM_SHARED_MODE STREQUAL "shared")
set(LLVM_IS_SHARED ON)
else()
set(LLVM_IS_SHARED OFF)
endif()

llvm_set(LDFLAGS ldflags)
llvm_set(SYSTEM_LIBS system-libs)
string(REPLACE "\n" " " LLVM_LDFLAGS "${LLVM_LDFLAGS} ${LLVM_SYSTEM_LIBS}")
Expand Down
3 changes: 0 additions & 3 deletions runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,6 @@ if("${C_SYSTEM_LIBS}" STREQUAL "AUTO")
set(C_SYSTEM_LIBS m c)
elseif("${TARGET_SYSTEM}" MATCHES "Linux")
set(C_SYSTEM_LIBS m pthread rt dl)
if("${TARGET_SYSTEM}" MATCHES "musl")
list(APPEND C_SYSTEM_LIBS "unwind")
endif()
elseif("${TARGET_SYSTEM}" MATCHES "FreeBSD")
set(C_SYSTEM_LIBS m pthread execinfo z)
else()
Expand Down
Loading