Truly independent web browser
Meta+UI: Support bundling shared Qt on Linux
Timothy Flynn46e2f5af0f99
diff --git a/Documentation/AdvancedBuildInstructions.md b/Documentation/AdvancedBuildInstructions.mdindex b97e5f8f835..35b20bf4d3c 100644--- a/Documentation/AdvancedBuildInstructions.md+++ b/Documentation/AdvancedBuildInstructions.md@@ -44,6 +44,7 @@ There are some optional features that can be enabled during compilation that are- `ENABLE_CLANG_PLUGINS_INVALID_FUNCTION_MEMBERS`: makes the Clang plugins also detect invalid function types as members of GC-allocated objects. Only applies with `ENABLE_CLANG_PLUGINS`.- `BUILD_SHARED_LIBS`: builds shared libraries instead of static ones. Enabled by default, and disabled by the `Distribution` preset.- `ENABLE_GUI_TARGETS`: builds the browser, its helper processes and the tests that need them. Enabled by default.+- `LADYBIRD_BUILD_QT`: builds and bundles Qt with vcpkg for Linux GUI builds. Disabled by default.- `LADYBIRD_ENABLE_CCACHE`: compiles through ccache when it is installed. Enabled by default.- `LAGOM_USE_LINKER`: sets the linker to use, such as `lld` or `mold`, instead of the compiler's default. On Linux and the BSDs, LLD or mold is picked automatically when one of them is installed.- `LAGOM_LINK_POOL_SIZE`: sets the maximum number of link jobs that run at once.diff --git a/Meta/CMake/check_for_dependencies.cmake b/Meta/CMake/check_for_dependencies.cmakeindex 4767a665bc4..db142b9b5c2 100644--- a/Meta/CMake/check_for_dependencies.cmake+++ b/Meta/CMake/check_for_dependencies.cmake@@ -158,5 +158,28 @@ if (ENABLE_GUI_TARGETS AND NOT ANDROID)set(QT_NO_PRIVATE_MODULE_WARNING ON)endif()- find_package(Qt6 6.10 REQUIRED COMPONENTS ${LADYBIRD_QT_COMPONENTS})+ if (LINUX AND "qt" IN_LIST VCPKG_MANIFEST_FEATURES)+ set(vcpkg_qt_package_dir "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/share")+ set(vcpkg_qt_dir "${vcpkg_qt_package_dir}/Qt6")++ # Cached package directories take priority over the search paths, including for Qt modules.+ get_cmake_property(cached_qt_dirs CACHE_VARIABLES)+ list(FILTER cached_qt_dirs INCLUDE REGEX "^Qt6.*_DIR$")+ foreach (cached_qt_dir IN LISTS cached_qt_dirs)+ cmake_path(IS_PREFIX vcpkg_qt_package_dir "$CACHE{${cached_qt_dir}}" NORMALIZE is_vcpkg_qt_dir)+ if (NOT is_vcpkg_qt_dir)+ unset("${cached_qt_dir}" CACHE)+ endif()+ endforeach()++ list(APPEND LADYBIRD_QT_COMPONENTS Svg)+ find_package(Qt6 6.10 REQUIRED COMPONENTS ${LADYBIRD_QT_COMPONENTS} PATHS "${vcpkg_qt_dir}" NO_DEFAULT_PATH)++ get_target_property(qt_core_type Qt6::Core TYPE)+ if (NOT qt_core_type STREQUAL "SHARED_LIBRARY" OR NOT Qt6_DIR STREQUAL vcpkg_qt_dir)+ message(FATAL_ERROR "The qt feature requires shared Qt from vcpkg.")+ endif()+ else()+ find_package(Qt6 6.10 REQUIRED COMPONENTS ${LADYBIRD_QT_COMPONENTS})+ endif()endif()diff --git a/Meta/CMake/cmake_options.cmake b/Meta/CMake/cmake_options.cmakeindex 2606d5c3f2c..7032bfc7652 100644--- a/Meta/CMake/cmake_options.cmake+++ b/Meta/CMake/cmake_options.cmake@@ -33,6 +33,7 @@ else()endif()option(ENABLE_GUI_TARGETS "Enable building GUI targets" ON)+option(LADYBIRD_BUILD_QT "Build and bundle Qt with vcpkg on Linux" OFF)option(ENABLE_INSTALL_HEADERS "Enable installing headers" ON)option(ENABLE_INSTALL_FREEDESKTOP_FILES "Enable installing .desktop and .service files" ${freedesktop_files_default})option(LADYBIRD_ENABLE_CPPTRACE "Enable use of cpptrace as the default library for stacktraces. If not available falls back to backtrace.h" ON)diff --git a/Meta/CMake/cpack_project_config.cmake b/Meta/CMake/cpack_project_config.cmakeindex 420680248e6..372e56cb0e6 100644--- a/Meta/CMake/cpack_project_config.cmake+++ b/Meta/CMake/cpack_project_config.cmake@@ -9,10 +9,9 @@ if (CPACK_GENERATOR MATCHES "^(DEB|RPM)$")set(CPACK_PRE_BUILD_SCRIPTS "${CMAKE_CURRENT_LIST_DIR}/cpack_package_format.cmake")endif()-# A Linux package links the Qt of the distribution version that built it, so its version names that distribution-# version: Debian packages like Ubuntu's backports do, RPM packages with the dist tag of rpmbuild. Builds for several-# versions of a distribution can then share a repository, and upgrading the distribution also moves Ladybird to the-# build for it.+# A Linux package targets the ABI of the distribution that built it, so its version names that distribution version:+# Debian packages like Ubuntu's backports do, RPM packages with the dist tag of rpmbuild. Builds for several versions+# of a distribution can then share a repository, and upgrading the distribution also moves Ladybird to the build for it.if (CPACK_GENERATOR STREQUAL "DEB")file(STRINGS /etc/os-release os_release REGEX "^(ID|VERSION_ID)=")foreach (line IN LISTS os_release)diff --git a/Meta/CMake/environment.cmake b/Meta/CMake/environment.cmakeindex f8dfa87c96a..d15b2d44c87 100644--- a/Meta/CMake/environment.cmake+++ b/Meta/CMake/environment.cmake@@ -20,9 +20,13 @@ if (DEFINED LADYBIRD_VCPKG_TYPE)# name. From packages/, host tools like Qt's moc can't find the libraries they link.set(VCPKG_INSTALL_OPTIONS "${VCPKG_INSTALL_OPTIONS};--clean-packages-after-build" CACHE STRING "" FORCE)endif()+# Each optional dependency is a feature of vcpkg.json that an option selects. The options are declared after# project(), so one that is not set yet has its default. Keep in sync with MANIFEST_FEATURE_OPTIONS in# Meta/Utils/vcpkg_deps.py.+ if (LADYBIRD_BUILD_QT AND (NOT DEFINED ENABLE_GUI_TARGETS OR ENABLE_GUI_TARGETS))+ list(APPEND VCPKG_MANIFEST_FEATURES "qt")+ endif()if ((NOT DEFINED LADYBIRD_ENABLE_UPDATE_CHECK OR LADYBIRD_ENABLE_UPDATE_CHECK)AND (NOT DEFINED LADYBIRD_ENABLE_SPARKLE OR LADYBIRD_ENABLE_SPARKLE))list(APPEND VCPKG_MANIFEST_FEATURES "sparkle")diff --git a/Meta/CMake/vcpkg/distribution-triplets/distribution.cmake b/Meta/CMake/vcpkg/distribution-triplets/distribution.cmakeindex 5b7f7502a23..c368e9c3ff2 100644--- a/Meta/CMake/vcpkg/distribution-triplets/distribution.cmake+++ b/Meta/CMake/vcpkg/distribution-triplets/distribution.cmake@@ -10,3 +10,11 @@ block(SCOPE_FOR VARIABLES PROPAGATE VCPKG_LIBRARY_LINKAGE VCPKG_HASH_ADDITIONAL_list(APPEND VCPKG_HASH_ADDITIONAL_FILES "${dynamic_ports_file}")endif()endblock()++if (VCPKG_CMAKE_SYSTEM_NAME STREQUAL "Linux" AND PORT STREQUAL "qtbase")+ # vcpkg disables the AT-SPI bridge. Enable it for the Linux Qt runtime using the system AT-SPI headers.+ list(APPEND VCPKG_CMAKE_CONFIGURE_OPTIONS+ -DCMAKE_DISABLE_FIND_PACKAGE_ATSPI2=OFF+ -DFEATURE_accessibility_atspi_bridge=ON+ )+endif()diff --git a/Meta/CMake/vcpkg/dynamic-ports.txt b/Meta/CMake/vcpkg/dynamic-ports.txtindex aa4abb95834..cf2049f19de 100644--- a/Meta/CMake/vcpkg/dynamic-ports.txt+++ b/Meta/CMake/vcpkg/dynamic-ports.txt@@ -7,5 +7,6 @@ libunistringqtbaseqtpositioningqtserialport+qtsvg# Qt and Ladybird must share one ICU, as Ladybird hands the ICU data to it once per process.icudiff --git a/Meta/Linters/check_flatpak.py b/Meta/Linters/check_flatpak.pyindex 1b37cd08441..40dc56151e6 100755--- a/Meta/Linters/check_flatpak.py+++ b/Meta/Linters/check_flatpak.py@@ -51,6 +51,7 @@ flatpak_runtime_libs = ["qtbase","qtpositioning","qtserialport",+ "qtsvg","sqlite3","tiff","vulkan",diff --git a/Meta/Utils/vcpkg_deps.py b/Meta/Utils/vcpkg_deps.pyindex 150d8114723..65b18ea1efd 100644--- a/Meta/Utils/vcpkg_deps.py+++ b/Meta/Utils/vcpkg_deps.py@@ -24,10 +24,11 @@ from Utils.host_platform import HostArchitecture # noqa: E402from Utils.host_platform import HostSystem # noqa: E402from Utils.host_platform import Platform # noqa: E402-# The features of vcpkg.json, each with the CMake options that all have to be on to select it. Keep in sync with-# Meta/CMake/environment.cmake.+# The features of vcpkg.json, with the CMake options and their defaults. All options for a feature must be on+# to select it. Keep in sync with Meta/CMake/environment.cmake.MANIFEST_FEATURE_OPTIONS = {- "sparkle": ("LADYBIRD_ENABLE_UPDATE_CHECK", "LADYBIRD_ENABLE_SPARKLE"),+ "qt": {"LADYBIRD_BUILD_QT": False, "ENABLE_GUI_TARGETS": True},+ "sparkle": {"LADYBIRD_ENABLE_UPDATE_CHECK": True, "LADYBIRD_ENABLE_SPARKLE": True},}DEPEND_INFO_REGEX = re.compile(r"^([a-zA-Z0-9-]+)(?:\[([^]]*)\])?(:host)?:\s*(.*)$")@@ -157,12 +158,11 @@ def common_vcpkg_arguments(triplet: str, preset: str) -> list[str]:]-def cmake_option_is_on(cache: str, option: str) -> bool:- # An option that is not in the cache has its default, which is ON. The values that count as off are the constants- # that CMake's if() takes as false.+def cmake_option_is_on(cache: str, option: str, default: bool) -> bool:+ # The values that count as off are the constants that CMake's if() takes as false.match = re.search(rf"^{option}:[A-Z]+=(.*)$", cache, re.MULTILINE)if not match:- return True+ return defaultvalue = match.group(1).strip().upper()return value not in ("", "0", "OFF", "NO", "FALSE", "N", "IGNORE", "NOTFOUND") and not value.endswith("-NOTFOUND")@@ -175,7 +175,7 @@ def manifest_feature_arguments(build_dir: Path) -> list[str]:return [f"--x-feature={feature}"for feature, options in MANIFEST_FEATURE_OPTIONS.items()- if all(cmake_option_is_on(cache, option) for option in options)+ if all(cmake_option_is_on(cache, option, default) for option, default in options.items())]diff --git a/UI/Qt/main.cpp b/UI/Qt/main.cppindex 96e7c4ea320..60df5098249 100644--- a/UI/Qt/main.cpp+++ b/UI/Qt/main.cpp@@ -22,6 +22,8 @@#include <UI/Qt/WebContentView.h>#include <QCoreApplication>+#include <QFile>+#include <QFileInfo>#include <QStyleHints>#include <QtGlobal>@@ -44,6 +46,14 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)}#endif+#ifdef LADYBIRD_QT_PLUGINS_PATH+ // Qt ignores the path when it is absent, so the build tree still uses vcpkg's plugins.+ if (auto executable_path = Core::System::current_executable_path(); !executable_path.is_error()) {+ auto executable_dir = QFileInfo(QFile::decodeName(executable_path.value().characters())).absolutePath();+ QCoreApplication::addLibraryPath(executable_dir + QStringLiteral("/" LADYBIRD_QT_PLUGINS_PATH));+ }+#endif+// The web content view is presented in a native child window. Without this attribute, a widget// gaining a native window would force every other widget in the browser window to become native// as well.diff --git a/UI/cmake/InstallRules.cmake b/UI/cmake/InstallRules.cmakeindex 37e3ede2134..a8b2bc483e5 100644--- a/UI/cmake/InstallRules.cmake+++ b/UI/cmake/InstallRules.cmake@@ -116,29 +116,93 @@ install(TARGETS ${all_required_lagom_libraries}if (vcpkg_runtime_dependencies)set(vcpkg_library_install_dir ${CMAKE_INSTALL_LIBDIR})+ set(qt_plugins "")if (APPLE)set(vcpkg_library_install_dir bundle/Ladybird.app/Contents/lib)+ set(qt_plugins_dir bundle/Ladybird.app/Contents/PlugIns)+ set(qt_conf_dir bundle/Ladybird.app/Contents/Resources)+ set(qt_conf_plugins PlugIns)- # Qt loads these at runtime, so nothing links them. Static builds of Qt link them into the executable instead.get_target_property(qt_core_type Qt6::Core TYPE)if (qt_core_type STREQUAL "SHARED_LIBRARY")- set(bundle_plugins_dir bundle/Ladybird.app/Contents/PlugIns)- foreach (plugin IN ITEMS platforms/QCocoaIntegrationPlugin styles/QMacStylePlugin imageformats/QGifPlugin- imageformats/QICOPlugin imageformats/QJpegPlugin)- cmake_path(GET plugin PARENT_PATH plugin_type)- cmake_path(GET plugin FILENAME plugin_target)- if (NOT TARGET Qt6::${plugin_target})- message(FATAL_ERROR "Ladybird.app needs the Qt plugin ${plugin_target}, which Qt was built without")- endif()- install(IMPORTED_RUNTIME_ARTIFACTS Qt6::${plugin_target}- RUNTIME_DEPENDENCY_SET ladybird_vcpkg_libraries- LIBRARY DESTINATION ${bundle_plugins_dir}/${plugin_type} COMPONENT ladybird_Runtime- )- endforeach()-- file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/qt.conf" "[Paths]\nPlugins = PlugIns\n")- install(FILES "${CMAKE_CURRENT_BINARY_DIR}/qt.conf" DESTINATION bundle/Ladybird.app/Contents/Resources- COMPONENT ladybird_Runtime)+ set(qt_plugins+ imageformats/QGifPlugin+ imageformats/QICOPlugin+ imageformats/QJpegPlugin+ platforms/QCocoaIntegrationPlugin+ styles/QMacStylePlugin+ )+ endif()+ elseif (LINUX AND "qt" IN_LIST VCPKG_MANIFEST_FEATURES)+ # Keep the vcpkg plugin layout, whose relative runtime paths point to lib/.+ set(qt_plugins_dir Qt6/plugins)++ # Add the installed plugin directory at startup without overriding Qt for other applications.+ cmake_path(ABSOLUTE_PATH ladybird_executable_install_dir BASE_DIRECTORY "${CMAKE_INSTALL_PREFIX}"+ NORMALIZE OUTPUT_VARIABLE qt_executable_dir)+ cmake_path(ABSOLUTE_PATH qt_plugins_dir BASE_DIRECTORY "${CMAKE_INSTALL_PREFIX}"+ NORMALIZE OUTPUT_VARIABLE qt_plugins_path)+ cmake_path(RELATIVE_PATH qt_plugins_path BASE_DIRECTORY "${qt_executable_dir}")+ target_compile_definitions(ladybird PRIVATE "LADYBIRD_QT_PLUGINS_PATH=\"${qt_plugins_path}\"")++ set(qt_plugins+ iconengines/QSvgIconPlugin+ imageformats/QGifPlugin+ imageformats/QICOPlugin+ imageformats/QJpegPlugin+ imageformats/QSvgPlugin+ platforminputcontexts/QComposePlatformInputContextPlugin+ platforminputcontexts/QIbusPlatformInputContextPlugin+ platforms/QOffscreenIntegrationPlugin+ platforms/QWaylandIntegrationPlugin+ platforms/QXcbIntegrationPlugin+ platformthemes/QXdgDesktopPortalThemePlugin+ position/QGeoPositionInfoSourceFactoryGeoclue2Plugin+ position/QGeoPositionInfoSourceFactoryNmeaPlugin+ wayland-decoration-client/QWaylandBradientDecorationPlugin+ wayland-graphics-integration-client/QWaylandEglClientBufferPlugin+ wayland-shell-integration/QWaylandXdgShellIntegrationPlugin+ xcbglintegrations/QXcbEglIntegrationPlugin+ xcbglintegrations/QXcbGlxIntegrationPlugin+ )+ install(DIRECTORY "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/sbom/"+ DESTINATION ${CMAKE_INSTALL_DATADIR}/doc/ladybird/qt+ COMPONENT ladybird_Runtime+ FILES_MATCHING PATTERN "qt*.spdx"+ )+ endif()++ # Qt loads these at runtime. Add them to the dependency set to collect their shared libraries as well.+ if (qt_plugins)+ foreach (plugin IN LISTS qt_plugins)+ cmake_path(GET plugin PARENT_PATH plugin_type)+ cmake_path(GET plugin FILENAME plugin_target)+ if (NOT TARGET Qt6::${plugin_target})+ message(FATAL_ERROR "Ladybird needs the Qt plugin ${plugin_target}, which Qt was built without.")+ endif()+ set(plugin_install_dir "${qt_plugins_dir}/${plugin_type}")+ install(IMPORTED_RUNTIME_ARTIFACTS Qt6::${plugin_target}+ RUNTIME_DEPENDENCY_SET ladybird_vcpkg_libraries+ LIBRARY DESTINATION ${plugin_install_dir} COMPONENT ladybird_Runtime+ )+ if (LINUX AND NOT vcpkg_library_install_dir STREQUAL "lib")+ # Make the imported plugin's runpath relative to the actual library destination.+ find_program(PATCHELF_EXECUTABLE patchelf REQUIRED)+ install(CODE "+ set(qt_library_dir \"${vcpkg_library_install_dir}\")+ set(qt_plugin_dir \"\${CMAKE_INSTALL_PREFIX}/${plugin_install_dir}\")+ cmake_path(ABSOLUTE_PATH qt_library_dir BASE_DIRECTORY \"\${CMAKE_INSTALL_PREFIX}\" NORMALIZE)+ cmake_path(RELATIVE_PATH qt_library_dir BASE_DIRECTORY \"\${qt_plugin_dir}\")+ execute_process(COMMAND \"${PATCHELF_EXECUTABLE}\" --set-rpath \"\$ORIGIN:\$ORIGIN/\${qt_library_dir}\"+ \"\$ENV{DESTDIR}\${qt_plugin_dir}/$<TARGET_FILE_NAME:Qt6::${plugin_target}>\"+ COMMAND_ERROR_IS_FATAL ANY)+ " COMPONENT ladybird_Runtime)+ endif()+ endforeach()++ if (APPLE)+ file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/qt.conf" "[Paths]\nPlugins = ${qt_conf_plugins}\n")+ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/qt.conf" DESTINATION ${qt_conf_dir} COMPONENT ladybird_Runtime)endif()endif()diff --git a/vcpkg.json b/vcpkg.jsonindex eaa999efe1e..8e75590fb50 100644--- a/vcpkg.json+++ b/vcpkg.json@@ -268,6 +268,48 @@"zmij"],"features": {+ "qt": {+ "description": "Build Qt for Linux distributions",+ "dependencies": [+ {+ "name": "qtbase",+ "platform": "linux",+ "default-features": false,+ "features": [+ "dbus",+ "doubleconversion",+ "egl",+ "fontconfig",+ "freetype",+ "harfbuzz",+ "icu",+ "jpeg",+ "network",+ "opengl",+ "openssl",+ "pcre2",+ "png",+ "thread",+ "vulkan",+ "wayland",+ "widgets",+ "xcb",+ "xcb-xlib",+ "zstd"+ ]+ },+ {+ "name": "qtpositioning",+ "platform": "linux",+ "default-features": false+ },+ {+ "name": "qtsvg",+ "platform": "linux",+ "default-features": false+ }+ ]+ },"sparkle": {"description": "Update the macOS app with Sparkle","dependencies": [@@ -406,6 +448,10 @@"name": "qtserialport","version": "6.11.3#0"},+ {+ "name": "qtsvg",+ "version": "6.11.3#0"+ },{"name": "sdl3","version": "3.4.20#0"