From c44041653c52397d137980e5b50a25cb10ce3101 Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Mon, 11 Mar 2024 18:18:55 -0700 Subject: [PATCH] build: greatly speed up build times using pch --- CMakeLists.txt | 24 ++++++++++++++++++++++- README.md | 2 ++ default.nix | 4 ++-- docs | 2 +- shell.nix | 2 +- src/core/CMakeLists.txt | 1 + src/io/CMakeLists.txt | 4 ++++ src/wayland/CMakeLists.txt | 16 ++++++++++++--- src/wayland/session_lock/CMakeLists.txt | 1 + src/wayland/wlr_layershell/CMakeLists.txt | 3 +++ 10 files changed, 51 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b27bc294..953d72af 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.20) -project(quickshell VERSION "0.1.0") +project(quickshell VERSION "0.1.0" LANGUAGES CXX C) set(QT_MIN_VERSION "6.6.0") set(CMAKE_CXX_STANDARD 20) @@ -65,6 +65,28 @@ find_package(Qt6 REQUIRED COMPONENTS ${QT_FPDEPS}) qt_standard_project_setup(REQUIRES 6.6) set(QT_QML_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/qml_modules) +file(GENERATE + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/pchstub.cpp + CONTENT "" +) + +add_library(qt-pch ${CMAKE_CURRENT_BINARY_DIR}/pchstub.cpp) +target_link_libraries(qt-pch PRIVATE ${QT_DEPS}) +target_precompile_headers(qt-pch PUBLIC + + + + + + + +) + +function (qs_pch target) + target_precompile_headers(${target} REUSE_FROM qt-pch) + target_link_libraries(${target} PRIVATE ${QT_DEPS}) # required for gcc to accept the pch on plugin targets +endfunction() + add_subdirectory(src/core) add_subdirectory(src/io) diff --git a/README.md b/README.md index 43d00cff..37fd30f5 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,8 @@ This repo has a nix flake you can use to install the package directly: Quickshell's binary is available at `quickshell.packages..default` to be added to lists such as `environment.systemPackages` or `home.packages`. +Note: by default this package is built with clang as it is significantly faster. + ## Manual If not using nix, you'll have to build from source. diff --git a/default.nix b/default.nix index a2655402..e29c216c 100644 --- a/default.nix +++ b/default.nix @@ -3,7 +3,7 @@ nix-gitignore, pkgs, keepDebugInfo, - stdenv ? (keepDebugInfo pkgs.stdenv), + buildStdenv ? pkgs.clang17Stdenv, cmake, ninja, @@ -23,7 +23,7 @@ else "unknown"), debug ? false, enableWayland ? true, -}: stdenv.mkDerivation { +}: buildStdenv.mkDerivation { pname = "quickshell${lib.optionalString debug "-debug"}"; version = "0.1.0"; src = nix-gitignore.gitignoreSource "/docs\n/examples\n" ./.; diff --git a/docs b/docs index 2d0b15bb..b4587482 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit 2d0b15bbd52ea61bd79880b89fae0a589010d1f3 +Subproject commit b4587482d7835818e78f8a84b29057b88c35c567 diff --git a/shell.nix b/shell.nix index 484bf70a..07b5b57d 100644 --- a/shell.nix +++ b/shell.nix @@ -10,7 +10,7 @@ rev = "1f062cc198d1112d13e5128fa1f2ee3dbffe613b"; sha256 = "kbt0Zc1qHE5fhqBkKz8iue+B+ZANjF1AR/RdgmX1r0I="; }) { inherit pkgs; }; -in pkgs.mkShell { +in pkgs.mkShell.override { stdenv = quickshell.stdenv; } { inputsFrom = [ quickshell ]; nativeBuildInputs = with pkgs; [ diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 2e347467..a14a5a1e 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -22,6 +22,7 @@ set_source_files_properties(main.cpp PROPERTIES COMPILE_DEFINITIONS GIT_REVISION qt_add_qml_module(quickshell URI Quickshell VERSION 0.1) target_link_libraries(quickshell PRIVATE ${QT_DEPS}) +qs_pch(quickshell) if (BUILD_TESTING) add_subdirectory(test) diff --git a/src/io/CMakeLists.txt b/src/io/CMakeLists.txt index 6fe0f409..23758064 100644 --- a/src/io/CMakeLists.txt +++ b/src/io/CMakeLists.txt @@ -16,6 +16,10 @@ target_link_libraries(quickshell-io-init PRIVATE ${QT_DEPS}) target_link_libraries(quickshell PRIVATE quickshell-ioplugin quickshell-io-init) +qs_pch(quickshell-io) +qs_pch(quickshell-ioplugin) +qs_pch(quickshell-io-init) + if (BUILD_TESTING) add_subdirectory(test) endif() diff --git a/src/wayland/CMakeLists.txt b/src/wayland/CMakeLists.txt index 3300a5fd..e56c0430 100644 --- a/src/wayland/CMakeLists.txt +++ b/src/wayland/CMakeLists.txt @@ -37,9 +37,15 @@ function (wl_proto target name path) execute_process(COMMAND ${qtwaylandscanner} client-header ${path} OUTPUT_FILE ${PROTO_BUILD_PATH}/qwayland-${name}.h) execute_process(COMMAND ${qtwaylandscanner} client-code ${path} OUTPUT_FILE ${PROTO_BUILD_PATH}/qwayland-${name}.cpp) - target_sources(${target} PRIVATE ${PROTO_BUILD_PATH}/wayland-${name}.c) - target_sources(${target} PRIVATE ${PROTO_BUILD_PATH}/qwayland-${name}.cpp) - target_include_directories(${target} PRIVATE ${PROTO_BUILD_PATH}) + add_library(wl-proto-${name} + ${PROTO_BUILD_PATH}/wayland-${name}.c + ${PROTO_BUILD_PATH}/qwayland-${name}.cpp + ) + + target_include_directories(wl-proto-${name} INTERFACE ${PROTO_BUILD_PATH}) + target_link_libraries(wl-proto-${name} Qt6::WaylandClient Qt6::WaylandClientPrivate) + + target_link_libraries(${target} PRIVATE wl-proto-${name}) endfunction() # ----- @@ -65,4 +71,8 @@ endif() target_link_libraries(quickshell-wayland PRIVATE ${QT_DEPS}) target_link_libraries(quickshell-wayland-init PRIVATE ${QT_DEPS}) +qs_pch(quickshell-wayland) +qs_pch(quickshell-waylandplugin) +qs_pch(quickshell-wayland-init) + target_link_libraries(quickshell PRIVATE quickshell-waylandplugin quickshell-wayland-init) diff --git a/src/wayland/session_lock/CMakeLists.txt b/src/wayland/session_lock/CMakeLists.txt index 23d90393..d6224a8b 100644 --- a/src/wayland/session_lock/CMakeLists.txt +++ b/src/wayland/session_lock/CMakeLists.txt @@ -8,5 +8,6 @@ qt_add_library(quickshell-wayland-sessionlock STATIC wl_proto(quickshell-wayland-sessionlock ext-session-lock-v1 "${WAYLAND_PROTOCOLS}/staging/ext-session-lock/ext-session-lock-v1.xml") target_link_libraries(quickshell-wayland-sessionlock PRIVATE ${QT_DEPS} wayland-client) +qs_pch(quickshell-wayland-sessionlock) target_link_libraries(quickshell-wayland PRIVATE quickshell-wayland-sessionlock) diff --git a/src/wayland/wlr_layershell/CMakeLists.txt b/src/wayland/wlr_layershell/CMakeLists.txt index 27a85ca0..9f82826b 100644 --- a/src/wayland/wlr_layershell/CMakeLists.txt +++ b/src/wayland/wlr_layershell/CMakeLists.txt @@ -9,4 +9,7 @@ qt_add_qml_module(quickshell-wayland-layershell URI Quickshell.Wayland._WlrLayer wl_proto(quickshell-wayland-layershell wlr-layer-shell-unstable-v1 "${CMAKE_CURRENT_SOURCE_DIR}/wlr-layer-shell-unstable-v1.xml") target_link_libraries(quickshell-wayland-layershell PRIVATE ${QT_DEPS} wayland-client) +qs_pch(quickshell-wayland-layershell) +qs_pch(quickshell-wayland-layershellplugin) + target_link_libraries(quickshell-wayland PRIVATE quickshell-wayland-layershellplugin)