Truly independent web browser
Meta+UI/Qt: Add an option to build the macOS app without Sparkle
Jelle Raaijmakers6ba0711fc06e
diff --git a/Documentation/AdvancedBuildInstructions.md b/Documentation/AdvancedBuildInstructions.mdindex f99aea74b9c..3e13046a0b9 100644--- a/Documentation/AdvancedBuildInstructions.md+++ b/Documentation/AdvancedBuildInstructions.md@@ -33,6 +33,7 @@ There are some optional features that can be enabled during compilation that are- `ENABLE_ALL_THE_DEBUG_MACROS`: used for checking whether debug code compiles on CI. This should not be set normally, as it clutters the console output and makes the system run very slowly. Instead, enable only the needed debug macros, as described below.- `ENABLE_COMPILETIME_FORMAT_CHECK`: checks for the validity of `std::format`-style format string during compilation. Enabled by default.- `ENABLE_JS_JIT`: builds the optimizing JIT for JavaScript. Enabled by default on x86-64 and AArch64 Linux and macOS and on x86-64 Windows, the platforms it generates code for. Without it, LibJS runs JavaScript in its interpreter alone, and the interpreter is built without the feedback collection and tier-up checks that only the JIT needs. See [the configuration of the JIT](../Libraries/LibJS/JIT/ARCHITECTURE.md#13-configuration).+- `LADYBIRD_ENABLE_SPARKLE`: updates the macOS app with [Sparkle](https://sparkle-project.org). Enabled by default. Without it, vcpkg doesn't build Sparkle, which needs Xcode, and Ladybird links to the release page of a newer version instead of installing it.- `LADYBIRD_BASELINE_CPU_TARGET`: builds C++ and Rust for a common CPU target instead of the build machine. Disabled by default and enabled by the `Distribution` preset; explicitly set `-DLADYBIRD_BASELINE_CPU_TARGET=ON` when packaging binaries for older machines with another configuration. On x86-64 this is x86-64-v2 (SSE4.2 and POPCNT), so distributed binaries run without AVX, AVX2, BMI or LZCNT. Both the JavaScript and WebAssembly JITs remain available; WebAssembly selects newer instructions at runtime when supported.- `INCLUDE_WASM_SPEC_TESTS`: downloads and includes the WebAssembly spec testsuite tests. In order to use this option, you will need to install `prettier` and `wasm-tools`.- `BUILD_BROWSER_TESTS_ONLY`: only builds the tests that run the browser's own executables, such as the LibWeb test suite and the WebDriver tests, and leaves out the test programs for individual libraries. Enabled by the `Distribution` preset.diff --git a/Meta/CMake/cmake_options.cmake b/Meta/CMake/cmake_options.cmakeindex cf31c2426fd..f48605c5952 100644--- a/Meta/CMake/cmake_options.cmake+++ b/Meta/CMake/cmake_options.cmake@@ -36,6 +36,7 @@ option(ENABLE_GUI_TARGETS "Enable building GUI targets" ON)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)+option(LADYBIRD_ENABLE_SPARKLE "Update the macOS app with Sparkle" ON)option(LADYBIRD_GENERATE_DSYM "Generate dSYM bundles for binaries and libraries (macOS only)" OFF)option(LADYBIRD_GENERATE_SYMBOL_FILES "Build with debug info and write the symbols of the installed executables to separate files" OFF)if (LADYBIRD_GENERATE_SYMBOL_FILES AND MSVC)diff --git a/Meta/CMake/environment.cmake b/Meta/CMake/environment.cmakeindex 96be3865ef4..4cb35a981db 100644--- a/Meta/CMake/environment.cmake+++ b/Meta/CMake/environment.cmake@@ -20,6 +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 (NOT DEFINED LADYBIRD_ENABLE_SPARKLE OR LADYBIRD_ENABLE_SPARKLE)+ list(APPEND VCPKG_MANIFEST_FEATURES "sparkle")+ endif()+set(VCPKG_OVERLAY_TRIPLETS "$ENV{LADYBIRD_SOURCE_DIR}/Meta/CMake/vcpkg/${LADYBIRD_VCPKG_TYPE}-triplets" CACHE STRING "" FORCE)set(ENV{VCPKG_BINARY_SOURCES} "clear;files,${LADYBIRD_CACHE_DIR}/vcpkg-binary-cache,readwrite;$ENV{VCPKG_BINARY_SOURCES}")diff --git a/Meta/Utils/vcpkg_deps.py b/Meta/Utils/vcpkg_deps.pyindex e810153b304..4764e687b5d 100644--- a/Meta/Utils/vcpkg_deps.py+++ b/Meta/Utils/vcpkg_deps.py@@ -24,6 +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 CMake options that each select a feature of vcpkg.json. Keep in sync with Meta/CMake/environment.cmake.+MANIFEST_FEATURE_OPTIONS = {+ "LADYBIRD_ENABLE_SPARKLE": "sparkle",+}+DEPEND_INFO_REGEX = re.compile(r"^([a-zA-Z0-9-]+)(?:\[([^]]*)\])?(:host)?:\s*(.*)$")@@ -151,6 +156,28 @@ 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.+ match = re.search(rf"^{option}:[A-Z]+=(.*)$", cache, re.MULTILINE)+ if not match:+ return True+ value = match.group(1).strip().upper()+ return value not in ("", "0", "OFF", "NO", "FALSE", "N", "IGNORE", "NOTFOUND") and not value.endswith("-NOTFOUND")+++def manifest_feature_arguments(build_dir: Path) -> list[str]:+ # Only a build directory that CMake configured before has options to go by.+ cache_path = build_dir / "CMakeCache.txt"+ cache = cache_path.read_text() if cache_path.exists() else ""++ return [+ f"--x-feature={feature}"+ for option, feature in MANIFEST_FEATURE_OPTIONS.items()+ if cmake_option_is_on(cache, option)+ ]++def vcpkg_install_arguments(vcpkg: Path, triplet: str, preset: str) -> list[str]:return [str(vcpkg), "install", *common_vcpkg_arguments(triplet, preset), "--no-print-usage"]@@ -162,13 +189,16 @@ class PortNode:self.dependencies: set[str] = set()-def query_dependency_graph(vcpkg: Path, triplet: str, preset: str, install_root: Path) -> dict[str, PortNode]:+def query_dependency_graph(+ vcpkg: Path, triplet: str, preset: str, install_root: Path, feature_arguments: list[str]+) -> dict[str, PortNode]:# NOTE: depend-info still takes the install root's lock, so keep it out of the source tree.result = subprocess.run([str(vcpkg),"depend-info",*common_vcpkg_arguments(triplet, preset),+ *feature_arguments,f"--x-install-root={install_root}","--format=list",],@@ -465,11 +495,19 @@ def run_quietly(arguments: list[str], log_path: Path, environment: dict[str, strraise subprocess.CalledProcessError(result.returncode, arguments)-def install_is_stale(deps_dir: Path, graph: dict[str, PortNode], install_root: Path) -> bool:+def restore_stamp_content(features: list[str]) -> str:+ return "features: " + " ".join(features) + "\n"+++def install_is_stale(deps_dir: Path, graph: dict[str, PortNode], install_root: Path, features: list[str]) -> bool:restore_stamp = deps_dir / ".restore-stamp"if not restore_stamp.exists() or not (install_root / "vcpkg").is_dir():return True+ # The stamp names the features that were installed, which change with the options of the build.+ if restore_stamp.read_text() != restore_stamp_content(features):+ return True+restore_time = restore_stamp.stat().st_mtimefor name in graph:stamp = deps_dir / name / ".stamp"@@ -508,7 +546,11 @@ def build_dependencies(write_if_changed(extra_vcpkg_variables_path(build_dir), extra_vcpkg_variables(platform, cc, cxx))+ # CMake can rewrite its cache while this runs, so everything below goes by one reading of the features.+ feature_arguments = manifest_feature_arguments(build_dir)+manifest_arguments = vcpkg_install_arguments(vcpkg, triplet, preset)+ manifest_arguments.extend(feature_arguments)manifest_arguments.append(f"--x-install-root={build_dir / 'vcpkg_installed'}")if fetch_only:@@ -519,7 +561,7 @@ def build_dependencies()return triplet- graph = query_dependency_graph(vcpkg, triplet, preset, build_dir / "vcpkg_installed")+ graph = query_dependency_graph(vcpkg, triplet, preset, build_dir / "vcpkg_installed", feature_arguments)generate_build_files(platform, preset, build_dir, vcpkg, triplet, graph)# Wipe the stamps if the binary cache is gone.@@ -563,10 +605,12 @@ def build_dependencies(os.close(fifo_fd)token_fifo.unlink(missing_ok=True)- if install_is_stale(deps_dir, graph, build_dir / "vcpkg_installed"):+ if install_is_stale(deps_dir, graph, build_dir / "vcpkg_installed", feature_arguments):print("Installing dependencies from the binary cache...")+ # A restore that stops halfway must not leave a stamp that vouches for what it removed.+ (deps_dir / ".restore-stamp").unlink(missing_ok=True)run_quietly(manifest_arguments, deps_dir / "restore.log", environment)- (deps_dir / ".restore-stamp").touch()+ (deps_dir / ".restore-stamp").write_text(restore_stamp_content(feature_arguments))finally:os.close(lock_fd)diff --git a/Tests/UI/Qt/CMakeLists.txt b/Tests/UI/Qt/CMakeLists.txtindex bc9aabfc41a..0d2cb07ecea 100644--- a/Tests/UI/Qt/CMakeLists.txt+++ b/Tests/UI/Qt/CMakeLists.txt@@ -107,7 +107,7 @@ endif()# The tests link Sparkle through ladybird_impl, but run from the build directory rather than from the app bundle that# carries Sparkle.framework, so they find it where vcpkg installed it.-if (APPLE)+if (APPLE AND LADYBIRD_ENABLE_SPARKLE)find_package(unofficial-sparkle CONFIG REQUIRED)get_target_property(sparkle_framework unofficial::sparkle::Sparkle IMPORTED_LOCATION)get_filename_component(sparkle_frameworks_directory "${sparkle_framework}" DIRECTORY)diff --git a/UI/CMakeLists.txt b/UI/CMakeLists.txtindex 33a984afec6..7ef5450a170 100644--- a/UI/CMakeLists.txt+++ b/UI/CMakeLists.txt@@ -18,6 +18,9 @@ if (APPLE)endif()set(LADYBIRD_SPARKLE_PLIST_ENTRIES "")+endif()++if (APPLE AND LADYBIRD_ENABLE_SPARKLE)set(LADYBIRD_SPARKLE_FEED_URL "https://download.ladybird.org/macos/appcast.xml" CACHE STRING "The appcast that Sparkle finds updates in")set(LADYBIRD_SPARKLE_PUBLIC_KEY "30mib/1Ke84cNc8KkKajhTkCP9Zu3iZRgophONX53Ik=" CACHE STRING "The public EdDSA key, in base64, that the appcast and its updates are signed with")@@ -98,29 +101,36 @@ function(create_ladybird_bundle target_name))endif()- # Sparkle installs updates with programs of its own in its framework, which are signed before the app.- get_target_property(sparkle_framework unofficial::sparkle::Sparkle IMPORTED_LOCATION)- set(bundled_sparkle_framework "${bundle_dir}/Contents/Frameworks/Sparkle.framework")- set_property(TARGET ${target_name} APPEND PROPERTY BUILD_RPATH "@executable_path/../Frameworks")- set_property(TARGET ${target_name} APPEND PROPERTY INSTALL_RPATH "@executable_path/../Frameworks")+ if (LADYBIRD_ENABLE_SPARKLE)+ # Sparkle installs updates with programs of its own in its framework, which are signed before the app.+ get_target_property(sparkle_framework unofficial::sparkle::Sparkle IMPORTED_LOCATION)+ set(bundled_sparkle_framework "${bundle_dir}/Contents/Frameworks/Sparkle.framework")+ set_property(TARGET ${target_name} APPEND PROPERTY BUILD_RPATH "@executable_path/../Frameworks")+ set_property(TARGET ${target_name} APPEND PROPERTY INSTALL_RPATH "@executable_path/../Frameworks")- ladybird_codesign_command(sparkle_autoupdate_codesign_command "${target_name}-sparkle-autoupdate" -o runtime "${bundled_sparkle_framework}/Versions/B/Autoupdate")- ladybird_codesign_command(sparkle_updater_codesign_command "${target_name}-sparkle-updater" -o runtime "${bundled_sparkle_framework}/Versions/B/Updater.app")- ladybird_codesign_command(sparkle_codesign_command "${target_name}-sparkle" "${bundled_sparkle_framework}")+ ladybird_codesign_command(sparkle_autoupdate_codesign_command "${target_name}-sparkle-autoupdate" -o runtime "${bundled_sparkle_framework}/Versions/B/Autoupdate")+ ladybird_codesign_command(sparkle_updater_codesign_command "${target_name}-sparkle-updater" -o runtime "${bundled_sparkle_framework}/Versions/B/Updater.app")+ ladybird_codesign_command(sparkle_codesign_command "${target_name}-sparkle" "${bundled_sparkle_framework}")- add_custom_command(TARGET ${target_name} POST_BUILD- COMMAND "${CMAKE_COMMAND}" -E rm -rf "${bundled_sparkle_framework}"- COMMAND "${CMAKE_COMMAND}" -E make_directory "${bundle_dir}/Contents/Frameworks"- COMMAND ditto "${sparkle_framework}" "${bundled_sparkle_framework}"- COMMAND "${CMAKE_COMMAND}" -E rm -rf- "${bundled_sparkle_framework}/Headers" "${bundled_sparkle_framework}/Versions/B/Headers"- "${bundled_sparkle_framework}/PrivateHeaders" "${bundled_sparkle_framework}/Versions/B/PrivateHeaders"- "${bundled_sparkle_framework}/Modules" "${bundled_sparkle_framework}/Versions/B/Modules"- COMMAND ${sparkle_autoupdate_codesign_command}- COMMAND ${sparkle_updater_codesign_command}- COMMAND ${sparkle_codesign_command}- VERBATIM- )+ add_custom_command(TARGET ${target_name} POST_BUILD+ COMMAND "${CMAKE_COMMAND}" -E rm -rf "${bundled_sparkle_framework}"+ COMMAND "${CMAKE_COMMAND}" -E make_directory "${bundle_dir}/Contents/Frameworks"+ COMMAND ditto "${sparkle_framework}" "${bundled_sparkle_framework}"+ COMMAND "${CMAKE_COMMAND}" -E rm -rf+ "${bundled_sparkle_framework}/Headers" "${bundled_sparkle_framework}/Versions/B/Headers"+ "${bundled_sparkle_framework}/PrivateHeaders" "${bundled_sparkle_framework}/Versions/B/PrivateHeaders"+ "${bundled_sparkle_framework}/Modules" "${bundled_sparkle_framework}/Versions/B/Modules"+ COMMAND ${sparkle_autoupdate_codesign_command}+ COMMAND ${sparkle_updater_codesign_command}+ COMMAND ${sparkle_codesign_command}+ VERBATIM+ )+ else()+ add_custom_command(TARGET ${target_name} POST_BUILD+ COMMAND "${CMAKE_COMMAND}" -E rm -rf "${bundle_dir}/Contents/Frameworks/Sparkle.framework"+ VERBATIM+ )+ endif()# Note: This symlink is removed in the install commands# This makes the bundle in the build directory *NOT* relocatablediff --git a/UI/Qt/Application.cpp b/UI/Qt/Application.cppindex 4cad914afe2..c5a63902179 100644--- a/UI/Qt/Application.cpp+++ b/UI/Qt/Application.cpp@@ -83,10 +83,13 @@# include <UI/Qt/MacWindow.h># include <UI/Qt/MicrophoneAuthorizerMacOS.h># include <UI/Qt/ScrollbarPreferencesMac.h>-# include <UI/Qt/SoftwareUpdaterMac.h># include <UI/Qt/SpellCheckerMac.h>#endif+#if defined(LADYBIRD_HAS_SPARKLE)+# include <UI/Qt/SoftwareUpdaterMac.h>+#endif+#if defined(LADYBIRD_HAS_TRANSLATOR)# include <UI/Qt/TranslatorMac.h>#endif@@ -1226,7 +1229,7 @@ void Application::create_platform_actions()if (auto* hub = HubConnection::the_if_connected())hub->send_settings_changes(settings);};-#if defined(AK_OS_MACOS)+#if defined(LADYBIRD_HAS_SPARKLE)m_software_updater = SoftwareUpdater::create();m_software_updater->on_will_relaunch = [this] {m_restart = Restart::ByUpdater;@@ -2486,9 +2489,9 @@ void Application::display_update_check_result(WebView::UpdateCheckResult::Kind kif (first_is_one_of(install_method, WebView::InstallMethod::DEB, WebView::InstallMethod::RPM, WebView::InstallMethod::Flatpak)) {text = qformatted("You have Ladybird {}. Update it with your system's software updater.", current_version);buttons.append({ "Remind me later", PageCard::ButtonRole::Primary, {} });+#if defined(LADYBIRD_HAS_SPARKLE)} else if (install_method == WebView::InstallMethod::MacOSApp) {buttons.append({ "Remind me later", PageCard::ButtonRole::Secondary, {} });-#if defined(AK_OS_MACOS)buttons.append({ "Install update", PageCard::ButtonRole::Primary, [trigger] {auto* software_updater = Application::the().software_updater();if (!software_updater)diff --git a/UI/Qt/Application.h b/UI/Qt/Application.hindex f3e3e47a61c..43dbe23dcb2 100644--- a/UI/Qt/Application.h+++ b/UI/Qt/Application.h@@ -173,7 +173,7 @@ public:BrowserWindow* active_window_if_any() const { return m_active_window; }BrowserWindow* non_private_window_if_any() const;-#if defined(AK_OS_MACOS)+#if defined(LADYBIRD_HAS_SPARKLE)SoftwareUpdater* software_updater() { return m_software_updater.ptr(); }#endif@@ -361,7 +361,7 @@ private:OwnPtr<WebView::MicrophoneAuthorizer> m_microphone_authorizer;OwnPtr<WebView::DefaultBrowser> m_default_browser;OwnPtr<WebView::Settings> m_settings;-#if defined(AK_OS_MACOS)+#if defined(LADYBIRD_HAS_SPARKLE)OwnPtr<SoftwareUpdater> m_software_updater;#endifOwnPtr<SessionStore> m_session_store;diff --git a/UI/Qt/CMakeLists.txt b/UI/Qt/CMakeLists.txtindex aca157eee8c..f03130a7dd1 100644--- a/UI/Qt/CMakeLists.txt+++ b/UI/Qt/CMakeLists.txt@@ -169,15 +169,13 @@ if (APPLE)Menu.mmPlatformColorsMac.mmScrollbarPreferencesMac.mm- SoftwareUpdaterMac.mmSpellCheckerMac.mmSystemAppearanceMac.mmTranslateIconMac.mmWebContentViewAccessibility.mmWebContentViewMac.mm)- find_package(unofficial-sparkle CONFIG REQUIRED)- target_link_libraries(ladybird_impl PRIVATE Qt::GuiPrivate unofficial::sparkle::Sparkle "-framework ApplicationServices" "-framework AVFoundation" "-framework Carbon" "-framework Cocoa" "-framework CoreServices" "-framework IOSurface" "-framework QuartzCore")+ target_link_libraries(ladybird_impl PRIVATE Qt::GuiPrivate "-framework ApplicationServices" "-framework AVFoundation" "-framework Carbon" "-framework Cocoa" "-framework CoreServices" "-framework IOSurface" "-framework QuartzCore")set_source_files_properties(DefaultBrowserMacOS.mmLadybirdAccessibilityElement.mm@@ -191,6 +189,13 @@ if (APPLE)PROPERTIES COMPILE_FLAGS "-fobjc-arc")+ if (LADYBIRD_ENABLE_SPARKLE)+ find_package(unofficial-sparkle CONFIG REQUIRED)+ target_sources(ladybird_impl PRIVATE SoftwareUpdaterMac.mm)+ target_link_libraries(ladybird_impl PRIVATE unofficial::sparkle::Sparkle)+ target_compile_definitions(ladybird_impl PUBLIC LADYBIRD_HAS_SPARKLE)+ endif()+# The Translation framework has no Objective-C API, so the browser reaches it through a small Swift library. The# API it uses came in the macOS 26.4 SDK, and CMake builds Swift for one architecture at a time. So a build with an# older SDK, or a universal build, leaves the translator out, and the browser doesn't offer to translate pages.diff --git a/vcpkg.json b/vcpkg.jsonindex 0bcec3320f5..eaa999efe1e 100644--- a/vcpkg.json+++ b/vcpkg.json@@ -243,10 +243,6 @@"vulkan"]},- {- "name": "sparkle",- "platform": "osx"- },"sqlite3",{"name": "tiff",@@ -271,6 +267,17 @@"zlib","zmij"],+ "features": {+ "sparkle": {+ "description": "Update the macOS app with Sparkle",+ "dependencies": [+ {+ "name": "sparkle",+ "platform": "osx"+ }+ ]+ }+ },"overrides": [{"name": "angle",