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

chore: Add fully static qtox build. #227

Merged
merged 1 commit into from
Dec 10, 2024
Merged
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
22 changes: 22 additions & 0 deletions .ci-scripts/build-qtox-linux-static.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh

set -eux

cmake \
-DCMAKE_TOOLCHAIN_FILE=/sysroot/static-toolchain.cmake \
-DCMAKE_PREFIX_PATH=/sysroot/opt/qt/lib/cmake \
-DCMAKE_BUILD_TYPE=Release \
-DSPELL_CHECK=OFF \
-DUPDATE_CHECK=ON \
-DSTRICT_OPTIONS=ON \
-DBUILD_TESTING=OFF \
-DFULLY_STATIC=ON \
-GNinja \
-B_build \
-H.

cmake --build _build

ls -lh _build/qtox
file _build/qtox
QT_QPA_PLATFORM=offscreen _build/qtox --help
19 changes: 19 additions & 0 deletions .github/workflows/build-test-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,25 @@ jobs:
- name: Run build
run: docker-compose run --rm alpine ./.ci-scripts/build-qtox-linux.sh --build-type ${{ matrix.build_type }} --${{ matrix.features }}

build-alpine-static:
name: Alpine (static)
if: github.event_name == 'pull_request'
runs-on: ubuntu-22.04
strategy:
matrix:
build_type: [Release]
steps:
- uses: actions/checkout@v4
- name: Set up ccache
uses: hendrikmuhs/ccache-action@v1.2
with:
key: ${{ github.job }}
append-timestamp: false
- name: Install docker-compose
run: sudo apt-get install -y docker-compose
- name: Run build
run: docker-compose run --rm alpine-static ./.ci-scripts/build-qtox-linux-static.sh --build-type ${{ matrix.build_type }}

build-debian:
name: Debian
if: github.event_name == 'pull_request'
Expand Down
18 changes: 17 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ option(ASAN "Compile with AddressSanitizer" OFF)
option(TSAN "Compile with ThreadSanitizer" OFF)
option(UBSAN "Compile with UndefinedBehaviorSanitizer" OFF)
option(STRICT_OPTIONS "Error on compile warning, used by CI" OFF)
option(BUILD_TESTING "Enable tests (turn OFF for static builds)" ON)
option(FULLY_STATIC
"Produce a fully statically linked qTox binary (experimental)" OFF)
option(GUI_TESTS
"Enable GUI rendering tests, likely tied to a specific Qt version" OFF)

Expand Down Expand Up @@ -654,7 +657,20 @@ set_target_properties(
QT_ANDROID_PACKAGE_SOURCE_DIR
"${CMAKE_CURRENT_SOURCE_DIR}/android/${Qt6Core_VERSION}")

include(Testing)
if(FULLY_STATIC)
target_link_directories(${PROJECT_NAME} PRIVATE
"/sysroot/opt/qt/plugins/platforms")
target_link_libraries(
${PROJECT_NAME}
PRIVATE Qt6::QLinuxFbIntegrationPlugin Qt6::QOffscreenIntegrationPlugin
Qt6::QVncIntegrationPlugin Qt6::QXcbGlxIntegrationPlugin
Qt6::QXcbIntegrationPlugin Qt6::QWaylandIntegrationPlugin)
target_link_options(${PROJECT_NAME} PRIVATE -static)
endif()

if(BUILD_TESTING)
include(Testing)
endif()
include(Installation)

if(DEFINED ENV{IN_NIX_SHELL})
Expand Down
2 changes: 1 addition & 1 deletion cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ if(SPELL_CHECK)
endif()

# Try to find cmake toxcore libraries
if(WIN32 OR ANDROID)
if(WIN32 OR ANDROID OR FULLY_STATIC)
search_dependency(TOXCORE PACKAGE toxcore LIBRARY toxcore OPTIONAL STATIC_PACKAGE MINIMUM_VERSION ${TOXCORE_MINIMUM_VERSION})
else()
search_dependency(TOXCORE PACKAGE toxcore LIBRARY toxcore OPTIONAL MINIMUM_VERSION ${TOXCORE_MINIMUM_VERSION})
Expand Down
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ services:
alpine:
image: toxchat/qtox:alpine
<<: *shared_params
alpine-static:
image: toxchat/qtox:alpine-static
<<: *shared_params
android_builder.armeabi-v7a.debug_6.2.4:
image: toxchat/qtox:android-builder.armeabi-v7a.debug_6.2.4
<<: *shared_params
Expand Down
10 changes: 10 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <QDebug>
#include <QGuiApplication>
#include <QtPlugin>

int main(int argc, char* argv[])
{
Expand All @@ -16,3 +17,12 @@ int main(int argc, char* argv[])
qDebug() << "Exit with status" << errorcode;
return errorcode;
}

#ifdef QT_STATIC
Q_IMPORT_PLUGIN(QLinuxFbIntegrationPlugin)
Q_IMPORT_PLUGIN(QOffscreenIntegrationPlugin)
Q_IMPORT_PLUGIN(QXcbIntegrationPlugin)
Q_IMPORT_PLUGIN(QXcbGlxIntegrationPlugin)
Q_IMPORT_PLUGIN(QVncIntegrationPlugin)
Q_IMPORT_PLUGIN(QWaylandIntegrationPlugin)
#endif
Loading