From 4644f3b0f650746a8068c6ffedbf7475770b81f7 Mon Sep 17 00:00:00 2001 From: Johan Engelen Date: Wed, 8 May 2024 17:20:41 +0200 Subject: [PATCH 1/3] Enable user-configuration of LLVM static/shared linking --- cmake/Modules/FindLLVM.cmake | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/cmake/Modules/FindLLVM.cmake b/cmake/Modules/FindLLVM.cmake index 9dfc883a31c..dc406424ab3 100644 --- a/cmake/Modules/FindLLVM.cmake +++ b/cmake/Modules/FindLLVM.cmake @@ -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 @@ -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 @@ -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) @@ -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}") From b0fece833aba10f17fb67fd669fefedcbf52457b Mon Sep 17 00:00:00 2001 From: Johan Engelen Date: Sun, 30 Jun 2024 23:41:21 +0200 Subject: [PATCH 2/3] statically linked LDC on Alpine --- .github/workflows/alpine_musl.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/alpine_musl.yml b/.github/workflows/alpine_musl.yml index f8bf629ca54..7b226628ef0 100644 --- a/.github/workflows/alpine_musl.yml +++ b/.github/workflows/alpine_musl.yml @@ -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} @@ -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" From 1952fb2399b0a117d50ee70eef93515b6a938ef9 Mon Sep 17 00:00:00 2001 From: Johan Engelen Date: Fri, 12 Jul 2024 12:29:34 +0200 Subject: [PATCH 3/3] musl no longer needs linking with libunwind --- runtime/CMakeLists.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index b392acb8bbc..1af2de9315a 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt @@ -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()