Truly independent web browser
Meta: Check at configure time that only the Compositor links Skia
Aliaksandr Kalenik7af9dcd8e15a
diff --git a/CMakeLists.txt b/CMakeLists.txtindex 9715d934087..a164bfa5f90 100644--- a/CMakeLists.txt+++ b/CMakeLists.txt@@ -140,6 +140,14 @@ endif()if (ENABLE_GUI_TARGETS)add_subdirectory(Services)add_subdirectory(UI)++ # Android has no Compositor process yet, so it keeps Skia elsewhere.+ if (NOT ANDROID AND NOT VCPKG_TARGET_ANDROID)+ include(check_skia_confinement)+ set(processes_without_skia ${ladybird_helper_processes} ladybird WebDriver)+ list(REMOVE_ITEM processes_without_skia Compositor)+ ladybird_check_skia_confinement(${processes_without_skia})+ endif()endif()add_custom_target(lint-shell-scriptsdiff --git a/Meta/CMake/check_skia_confinement.cmake b/Meta/CMake/check_skia_confinement.cmakenew file mode 100644index 00000000000..cd3ad4c7931--- /dev/null+++ b/Meta/CMake/check_skia_confinement.cmake@@ -0,0 +1,60 @@+# Only the Compositor process links Skia. ladybird_check_skia_confinement() walks the link dependencies of the given+# targets, through the shared libraries that they load and the static libraries that they take in, and fails the+# configuration if any of them reaches Skia.++function(_ladybird_skia_link_path target chain output)+ get_property(visited GLOBAL PROPERTY _LADYBIRD_SKIA_CHECK_VISITED)+ if ("${target}" IN_LIST visited)+ return()+ endif()+ set_property(GLOBAL APPEND PROPERTY _LADYBIRD_SKIA_CHECK_VISITED "${target}")++ get_target_property(aliased_target "${target}" ALIASED_TARGET)+ if (aliased_target)+ set(target "${aliased_target}")+ endif()+ if ("${target}" STREQUAL "${SKIA_TARGET}")+ set("${output}" "${chain}" PARENT_SCOPE)+ return()+ endif()++ get_target_property(type "${target}" TYPE)+ set(dependencies "")+ if (NOT "${type}" STREQUAL "INTERFACE_LIBRARY")+ get_target_property(link_libraries "${target}" LINK_LIBRARIES)+ if (link_libraries)+ list(APPEND dependencies ${link_libraries})+ endif()+ endif()+ get_target_property(interface_link_libraries "${target}" INTERFACE_LINK_LIBRARIES)+ if (interface_link_libraries)+ list(APPEND dependencies ${interface_link_libraries})+ endif()++ foreach (dependency IN LISTS dependencies)+ # A static library passes its private dependencies on as $<LINK_ONLY:...>. Other generator expressions do not+ # name Skia.+ string(REGEX REPLACE "^\\$<LINK_ONLY:(.+)>$" "\\1" dependency "${dependency}")+ if (dependency MATCHES "^\\$<" OR NOT TARGET "${dependency}")+ continue()+ endif()+ _ladybird_skia_link_path("${dependency}" "${chain} -> ${dependency}" found_chain)+ if (found_chain)+ set("${output}" "${found_chain}" PARENT_SCOPE)+ return()+ endif()+ endforeach()+endfunction()++function(ladybird_check_skia_confinement)+ foreach (target IN LISTS ARGN)+ if (NOT TARGET "${target}")+ continue()+ endif()+ set_property(GLOBAL PROPERTY _LADYBIRD_SKIA_CHECK_VISITED "")+ _ladybird_skia_link_path("${target}" "${target}" chain)+ if (chain)+ message(FATAL_ERROR "Only the Compositor may link Skia, but ${target} reaches it: ${chain}")+ endif()+ endforeach()+endfunction()