From 148f80f0779f42c1aa7d2f07c04a63507446662c Mon Sep 17 00:00:00 2001 From: Bennett Goble Date: Wed, 10 Apr 2024 19:54:10 -0700 Subject: Linux: build with clang, link with mold --- .github/workflows/build.yaml | 22 ++++++++++++++++-- build.sh | 1 + indra/cmake/00-Common.cmake | 54 ++++++++++++++++++++++++++++---------------- indra/cmake/Linker.cmake | 11 +++++++++ 4 files changed, 66 insertions(+), 22 deletions(-) create mode 100644 indra/cmake/Linker.cmake diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 1f5d8ee47a..b5be5bb00c 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -98,8 +98,19 @@ jobs: ${{ runner.os }}-64- - name: Install Linux dependencies - if: runner.os == 'linux' - run: sudo apt update && sudo apt install -y libsndio-dev libpulse-dev libfltk1.3-dev libunwind-dev libgl1-mesa-dev libglu1-mesa-dev libx11-dev libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev libxext-dev libxrender-dev libxfixes-dev libxxf86vm-dev libxss-dev libdbus-1-dev libudev-dev libssl-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libfreetype6-dev ninja-build libxft-dev + if: runner.os == 'Linux' + run: | + sudo apt update + sudo apt install -y \ + libsndio-dev libpulse-dev libfltk1.3-dev \ + libunwind-dev libgl1-mesa-dev libglu1-mesa-dev \ + libx11-dev libxrandr-dev libxinerama-dev \ + libxcursor-dev libxi-dev libxext-dev \ + libxrender-dev libxfixes-dev libxxf86vm-dev \ + libxss-dev libdbus-1-dev libudev-dev \ + libssl-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev \ + libfreetype6-dev ninja-build libxft-dev \ + llvm mold - name: Install windows dependencies if: runner.os == 'Windows' @@ -208,6 +219,13 @@ jobs: fi export PYTHON_COMMAND_NATIVE="$(native_path "$PYTHON_COMMAND")" + # Compile with clang, link with mold on linux. + if [[ "$RUNNER_OS" == "Linux" ]]; then + export CC=clang + export CXX=clang++ + export CMAKE_OPTIONS='-DLINK_WITH_MOLD=ON' + fi + ./build.sh # Each artifact is downloaded as a distinct .zip file. Multiple jobs diff --git a/build.sh b/build.sh index 2f034f3c51..88dd665ba6 100755 --- a/build.sh +++ b/build.sh @@ -205,6 +205,7 @@ pre_build() -DVIEWER_CHANNEL:STRING="${viewer_channel}" \ -DGRID:STRING="\"$viewer_grid\"" \ -DTEMPLATE_VERIFIER_OPTIONS:STRING="$template_verifier_options" $template_verifier_master_url \ + $CMAKE_OPTIONS \ "${SIGNING[@]}" \ || fatal "$variant configuration failed" diff --git a/indra/cmake/00-Common.cmake b/indra/cmake/00-Common.cmake index d46ebc4960..21242a32be 100644 --- a/indra/cmake/00-Common.cmake +++ b/indra/cmake/00-Common.cmake @@ -15,6 +15,7 @@ include_guard() include(Variables) +include(Linker) # We go to some trouble to set LL_BUILD to the set of relevant compiler flags. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} $ENV{LL_BUILD}") @@ -127,23 +128,37 @@ if (LINUX) APPID=secondlife LL_IGNORE_SIGCHLD ) + add_compile_options( - -fexceptions - -fno-math-errno - -fno-strict-aliasing - -fsigned-char - -msse2 - -mfpmath=sse - -pthread - -Wno-parentheses - -Wno-deprecated - -Wno-c++20-compat - -Wno-pessimizing-move - -Wno-stringop-overflow - -Wno-stringop-truncation - -Wno-dangling-pointer - -fvisibility=hidden + -fexceptions + -fno-math-errno + -fno-strict-aliasing + -fsigned-char + -msse2 + -mfpmath=sse + -pthread + -fvisibility=hidden + ) + + set(GCC_CLANG_COMPATIBLE_WARNINGS + -Wno-parentheses + -Wno-deprecated + -Wno-c++20-compat + -Wno-pessimizing-move + ) + + set(CLANG_WARNINGS + ${GCC_CLANG_COMPATIBLE_WARNINGS} + # Put clang specific warning configuration here ) + + set(GCC_WARNINGS + ${GCC_CLANG_COMPATIBLE_WARNINGS} + -Wno-stringop-overflow + -Wno-stringop-truncation + -Wno-dangling-pointer + ) + add_link_options( -Wl,--no-keep-memory -Wl,--build-id @@ -156,12 +171,15 @@ if (LINUX) # this stops us requiring a really recent glibc at runtime add_compile_options(-fno-stack-protector) - # ND: clang is a bit more picky than GCC, the latter seems to auto include -lstdc++ and -lm. The former not so and thus fails to link if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + # ND: clang is a bit more picky than GCC, the latter seems to auto include -lstdc++ and -lm. The former not so and thus fails to link add_link_options( -lstdc++ -lm ) + add_compile_options(${CLANG_WARNINGS}) + else() + add_compile_options(${GCC_WARNINGS}) endif() endif (LINUX) @@ -191,10 +209,6 @@ if (DARWIN) list(APPEND GCC_WARNINGS -Wno-reorder -Wno-non-virtual-dtor ) - if(LINUX) - list(APPEND GCC_WARNINGS -Wno-maybe-uninitialized -Wno-dangling-pointer ) - endif() - add_compile_options(${GCC_WARNINGS}) add_compile_options(-m${ADDRESS_SIZE}) endif () diff --git a/indra/cmake/Linker.cmake b/indra/cmake/Linker.cmake new file mode 100644 index 0000000000..292aa25c57 --- /dev/null +++ b/indra/cmake/Linker.cmake @@ -0,0 +1,11 @@ +include_guard(GLOBAL) + +if (${LINK_WITH_MOLD}) + find_program(MOLD_BIN mold REQUIRED) + if(MOLD_BIN) + message(STATUS "Mold linker found: ${MOLD_BIN}. Enabling mold as active linker.") + add_link_options("-fuse-ld=${MOLD_BIN}") + else() + message(STATUS "Mold linker not found. Using default linker.") + endif() +endif() -- cgit v1.2.3