Enable LTO support for Chatterino builds (#4258)

This is disabled by default, and can be enabled by passing `-DCHATTERINO_LTO=On` to your cmake invocation.
This commit is contained in:
pajlada 2022-12-24 18:42:59 +01:00 committed by GitHub
parent 621134ffcb
commit 83dfb08aed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 50 additions and 4 deletions

View file

@ -12,6 +12,9 @@ concurrency:
group: build-${{ github.ref }}
cancel-in-progress: true
env:
C2_ENABLE_LTO: ${{ github.ref == 'refs/heads/master' }}
jobs:
build:
runs-on: ${{ matrix.os }}
@ -20,17 +23,25 @@ jobs:
os: [windows-latest, ubuntu-20.04, macos-latest]
qt-version: [5.15.2, 5.12.12]
pch: [true]
force-lto: [false]
include:
- os: ubuntu-20.04
qt-version: 5.15.2
pch: false
force-lto: true
fail-fast: false
steps:
- name: Force LTO
if: matrix.force-lto == true
run: |
echo "C2_ENABLE_LTO=ON" >> "$GITHUB_ENV"
shell: bash
- name: Set environment variables for windows-latest
if: matrix.os == 'windows-latest'
run: |
echo "vs_version=2022" >> $GITHUB_ENV
echo "vs_version=2022" >> "$GITHUB_ENV"
shell: bash
- uses: actions/checkout@v3
@ -80,7 +91,12 @@ jobs:
mkdir build
cd build
conan install .. -b missing
cmake -G"NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DUSE_CONAN=ON ..
cmake `
-G"NMake Makefiles" `
-DCMAKE_BUILD_TYPE=Release `
-DUSE_CONAN=ON `
-DCHATTERINO_LTO="$Env:C2_ENABLE_LTO" `
..
set cl=/MP
nmake /S /NOLOGO
windeployqt bin/chatterino.exe --release --no-compiler-runtime --no-translations --no-opengl-sw --dir Chatterino2/
@ -137,8 +153,9 @@ jobs:
-DPAJLADA_SETTINGS_USE_BOOST_FILESYSTEM=On \
-DUSE_PRECOMPILED_HEADERS=${{ matrix.pch }} \
-DCMAKE_EXPORT_COMPILE_COMMANDS=On \
-DCHATTERINO_LTO="$C2_ENABLE_LTO" \
..
make -j$(nproc)
make -j"$(nproc)"
shell: bash
- name: clang-tidy review
@ -203,8 +220,9 @@ jobs:
-DCMAKE_OSX_DEPLOYMENT_TARGET=10.15 \
-DOPENSSL_ROOT_DIR=/usr/local/opt/openssl \
-DUSE_PRECOMPILED_HEADERS=${{ matrix.pch }} \
-DCHATTERINO_LTO="$C2_ENABLE_LTO" \
..
make -j$(sysctl -n hw.logicalcpu)
make -j"$(sysctl -n hw.logicalcpu)"
shell: bash
- name: Package (MacOS)

View file

@ -17,6 +17,7 @@
- Dev: Remove protocol from QApplication's Organization Domain (so changed from `https://www.chatterino.com` to `chatterino.com`). (#4256)
- Dev: Ignore `WM_SHOWWINDOW` hide events, causing fewer attempted rescales. (#4198)
- Dev: Migrated to C++ 20 (#4252, #4257)
- Dev: Enable LTO for main branch builds. (#4258)
## 2.4.0

View file

@ -20,9 +20,18 @@ option(USE_PRECOMPILED_HEADERS "Use precompiled headers" ON)
option(BUILD_WITH_QT6 "Use Qt6 instead of default Qt5" OFF)
option(CHATTERINO_GENERATE_COVERAGE "Generate coverage files" OFF)
option(BUILD_SHARED_LIBS "" OFF)
option(CHATTERINO_LTO "Enable LTO for all targets" ON)
option(USE_CONAN "Use conan" OFF)
if(CHATTERINO_LTO)
include(CheckIPOSupported)
check_ipo_supported(RESULT CHATTERINO_ENABLE_LTO OUTPUT IPO_ERROR)
message(STATUS "LTO: Enabled (Supported: ${CHATTERINO_ENABLE_LTO})")
else()
message(STATUS "LTO: Disabled")
endif()
if (BUILD_WITH_QT6)
set(MAJOR_QT_VERSION "6")
else()

View file

@ -665,6 +665,12 @@ if (BUILD_APP)
DESTINATION share/icons/hicolor/256x256/apps
)
endif ()
if(CHATTERINO_ENABLE_LTO)
message(STATUS "Enabling LTO for ${EXECUTABLE_PROJECT}")
set_property(TARGET ${EXECUTABLE_PROJECT}
PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
endif ()
if (USE_PRECOMPILED_HEADERS)
@ -843,3 +849,9 @@ else ()
)
endif()
endif ()
if(CHATTERINO_ENABLE_LTO)
message(STATUS "Enabling LTO for ${LIBRARY_PROJECT}")
set_property(TARGET ${LIBRARY_PROJECT}
PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()

View file

@ -46,6 +46,12 @@ set_target_properties(${PROJECT_NAME}
RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_BINARY_DIR}/bin"
)
if(CHATTERINO_ENABLE_LTO)
message(STATUS "Enabling LTO for ${PROJECT_NAME}")
set_property(TARGET ${PROJECT_NAME}
PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
# gtest_add_tests manages to discover the tests because it looks through the source files
# HOWEVER, it fails to run, because we have some bug that causes the QApplication exit to stall when no network requests have been made.
# ctest runs each test individually, so for now we require that testers just run the ./bin/chatterino-test binary without any filters applied