From 4ae7bbda5295fe488592732066bb677958c7e0f5 Mon Sep 17 00:00:00 2001 From: Matthew Olsson Date: Mon, 15 Apr 2024 18:50:49 -0700 Subject: [PATCH] Lagom: Add ClangPlugins to the build system --- CMakeLists.txt | 3 +++ Kernel/CMakeLists.txt | 2 ++ Kernel/Prekernel/CMakeLists.txt | 1 + Meta/CMake/common_options.cmake | 2 ++ Meta/CMake/utils.cmake | 2 ++ Meta/Lagom/CMakeLists.txt | 17 +++++++++++++++++ Meta/Lagom/ClangPlugins/CMakeLists.txt | 5 +++++ Meta/Lagom/Tools/CMakeLists.txt | 2 +- Userland/Libraries/LibJS/CMakeLists.txt | 1 + 9 files changed, 34 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6a118ce79b6..e154c91fe61 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -264,3 +264,6 @@ if (ENABLE_USB_IDS_DOWNLOAD AND NOT EXISTS "${USB_IDS_INSTALL_PATH}/${USB_IDS_FI download_file("${USB_IDS_URL}" "${USB_IDS_DOWNLOAD_PATH}") install(FILES "${USB_IDS_DOWNLOAD_PATH}" DESTINATION "${USB_IDS_INSTALL_PATH}") endif() + +add_library(GenericClangPlugin INTERFACE) +add_library(JSClangPlugin INTERFACE) diff --git a/Kernel/CMakeLists.txt b/Kernel/CMakeLists.txt index 4772925f749..d572e0dff12 100644 --- a/Kernel/CMakeLists.txt +++ b/Kernel/CMakeLists.txt @@ -798,9 +798,11 @@ add_link_options(LINKER:-z,notext) add_library(kernel_heap STATIC ${KERNEL_HEAP_SOURCES}) add_dependencies(kernel_heap install_libc_headers) +target_link_libraries(kernel_heap PUBLIC GenericClangPlugin) add_executable(Kernel ${SOURCES}) add_dependencies(Kernel generate_EscapeSequenceStateMachine.h generate_version_header install_libc_headers) +target_link_libraries(Kernel PUBLIC GenericClangPlugin) if("${SERENITY_ARCH}" STREQUAL "aarch64") target_link_options(Kernel PRIVATE LINKER:-T ${CMAKE_CURRENT_SOURCE_DIR}/Arch/aarch64/linker.ld -nostdlib LINKER:--no-pie) diff --git a/Kernel/Prekernel/CMakeLists.txt b/Kernel/Prekernel/CMakeLists.txt index 567981ed4ed..7951deab7c1 100644 --- a/Kernel/Prekernel/CMakeLists.txt +++ b/Kernel/Prekernel/CMakeLists.txt @@ -22,6 +22,7 @@ target_compile_options(${PREKERNEL_TARGET} PRIVATE -no-pie -fno-pic -fno-threads target_link_options(${PREKERNEL_TARGET} PRIVATE LINKER:-T ${CMAKE_CURRENT_SOURCE_DIR}/linker.ld -nostdlib LINKER:--no-pie) set_target_properties(${PREKERNEL_TARGET} PROPERTIES LINK_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/linker.ld) +target_link_libraries(${PREKERNEL_TARGET} PUBLIC GenericClangPlugin) if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") target_link_libraries(${PREKERNEL_TARGET} PRIVATE gcc) elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang$") diff --git a/Meta/CMake/common_options.cmake b/Meta/CMake/common_options.cmake index 6d61cc186ab..cfd575684e5 100644 --- a/Meta/CMake/common_options.cmake +++ b/Meta/CMake/common_options.cmake @@ -31,3 +31,5 @@ serenity_option(JAKT_SOURCE_DIR "" CACHE STRING "Pre-existing jakt language sour serenity_option(SERENITY_CACHE_DIR "${PROJECT_BINARY_DIR}/../caches" CACHE PATH "Location of shared cache of downloaded files") serenity_option(ENABLE_NETWORK_DOWNLOADS ON CACHE BOOL "Allow downloads of required files. If OFF, required files must already be present in SERENITY_CACHE_DIR") + +serenity_option(ENABLE_CLANG_PLUGINS OFF CACHE BOOL "Enable building with the Clang plugins") diff --git a/Meta/CMake/utils.cmake b/Meta/CMake/utils.cmake index ecc7fbd8967..589f9dd4b5f 100644 --- a/Meta/CMake/utils.cmake +++ b/Meta/CMake/utils.cmake @@ -52,6 +52,7 @@ if (NOT COMMAND serenity_lib) add_library(${target_name} ${SERENITY_LIB_TYPE} ${SOURCES} ${GENERATED_SOURCES}) set_target_properties(${target_name} PROPERTIES EXCLUDE_FROM_ALL TRUE) set_target_properties(${target_name} PROPERTIES VERSION "serenity") + target_link_libraries(${target_name} PUBLIC GenericClangPlugin) install(TARGETS ${target_name} DESTINATION ${CMAKE_INSTALL_LIBDIR} OPTIONAL) set_target_properties(${target_name} PROPERTIES OUTPUT_NAME ${fs_name}) serenity_generated_sources(${target_name}) @@ -80,6 +81,7 @@ if (NOT COMMAND serenity_bin) function(serenity_bin target_name) serenity_install_sources() add_executable(${target_name} ${SOURCES}) + target_link_libraries(${target_name} PUBLIC GenericClangPlugin) set_target_properties(${target_name} PROPERTIES EXCLUDE_FROM_ALL TRUE) install(TARGETS ${target_name} RUNTIME DESTINATION bin OPTIONAL) serenity_generated_sources(${target_name}) diff --git a/Meta/Lagom/CMakeLists.txt b/Meta/Lagom/CMakeLists.txt index f2f16b91351..63cc62c3b57 100644 --- a/Meta/Lagom/CMakeLists.txt +++ b/Meta/Lagom/CMakeLists.txt @@ -135,6 +135,11 @@ endif() CHECK_INCLUDE_FILE(pulse/pulseaudio.h HAVE_PULSEAUDIO) +add_library(JSClangPlugin INTERFACE) +add_library(GenericClangPlugin INTERFACE) +# These need to be installed to avoid CMake complaining about them not being in the export set +install(TARGETS GenericClangPlugin JSClangPlugin EXPORT LagomTargets) + if (CMAKE_CXX_COMPILER_ID MATCHES "Clang$") add_compile_options(-Wno-overloaded-virtual) # FIXME: Re-enable this check when the warning stops triggering, or document why we can't stop it from triggering. @@ -147,6 +152,11 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang$") set(LINKER_FLAGS "${LINKER_FLAGS} -fsanitize=fuzzer") endif() + if (ENABLE_CLANG_PLUGINS) + add_subdirectory(ClangPlugins) + depend_on_clang_plugin(JSClangPlugin LibJSGCClangPlugin) + depend_on_clang_plugin(GenericClangPlugin LambdaCaptureClangPlugin) + endif() elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") if (ENABLE_FUZZERS_LIBFUZZER) message(FATAL_ERROR @@ -224,6 +234,7 @@ function(lagom_lib target_name fs_name) OUTPUT_NAME lagom-${fs_name} ) target_link_libraries(${target_name} PRIVATE ${LAGOM_LIBRARY_LIBS}) + target_link_libraries(${target_name} PUBLIC GenericClangPlugin) if (NOT "${target_name}" STREQUAL "AK") target_link_libraries(${target_name} PRIVATE AK) @@ -289,6 +300,7 @@ endfunction() function(serenity_bin name) add_executable(${name} ${SOURCES} ${GENERATED_SOURCES}) add_executable(Lagom::${name} ALIAS ${name}) + target_link_libraries(${name} PUBLIC GenericClangPlugin) install( TARGETS ${target_name} EXPORT LagomTargets @@ -630,6 +642,8 @@ if (BUILD_LAGOM) OBJECT "${SERENITY_PROJECT_ROOT}/Userland/Libraries/LibTest/TestMain.cpp" ) + target_link_libraries(LibTest PUBLIC GenericClangPlugin) + target_link_libraries(LibTestMain PUBLIC GenericClangPlugin) # LibTest tests from Tests/ set(TEST_DIRECTORIES @@ -659,6 +673,9 @@ if (BUILD_LAGOM) if (LINUX) list(APPEND TEST_DIRECTORIES LibELF) endif() + if (ENABLE_CLANG_PLUGINS AND CMAKE_CXX_COMPILER_ID MATCHES "Clang$") + list(APPEND TEST_DIRECTORIES ClangPlugins) + endif() foreach (dir IN LISTS TEST_DIRECTORIES) add_serenity_subdirectory("Tests/${dir}") diff --git a/Meta/Lagom/ClangPlugins/CMakeLists.txt b/Meta/Lagom/ClangPlugins/CMakeLists.txt index 7f9d78b73ee..d3fcc41041d 100644 --- a/Meta/Lagom/ClangPlugins/CMakeLists.txt +++ b/Meta/Lagom/ClangPlugins/CMakeLists.txt @@ -15,3 +15,8 @@ endfunction() clang_plugin(LambdaCaptureClangPlugin SOURCES LambdaCapturePluginAction.cpp) clang_plugin(LibJSGCClangPlugin SOURCES LibJSGCPluginAction.cpp) + +function(depend_on_clang_plugin target_name plugin_name) + add_dependencies(${target_name} ${plugin_name}Target) + target_compile_options(${target_name} INTERFACE -fplugin=$) +endfunction() diff --git a/Meta/Lagom/Tools/CMakeLists.txt b/Meta/Lagom/Tools/CMakeLists.txt index 5515bdcfb4c..11016d41144 100644 --- a/Meta/Lagom/Tools/CMakeLists.txt +++ b/Meta/Lagom/Tools/CMakeLists.txt @@ -3,7 +3,7 @@ function(lagom_tool tool) add_executable(${tool} ${SOURCES} ${LAGOM_TOOL_SOURCES}) # alias for parity with exports add_executable(Lagom::${tool} ALIAS ${tool}) - target_link_libraries(${tool} AK LibCoreMinimal LibFileSystem ${LAGOM_TOOL_LIBS}) + target_link_libraries(${tool} AK LibCoreMinimal LibFileSystem GenericClangPlugin ${LAGOM_TOOL_LIBS}) install( TARGETS ${tool} EXPORT LagomTargets diff --git a/Userland/Libraries/LibJS/CMakeLists.txt b/Userland/Libraries/LibJS/CMakeLists.txt index adff8fbe896..94ee25b090e 100644 --- a/Userland/Libraries/LibJS/CMakeLists.txt +++ b/Userland/Libraries/LibJS/CMakeLists.txt @@ -282,3 +282,4 @@ if("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "i.86.*") endif() target_compile_options(LibJS PRIVATE -fno-omit-frame-pointer) +target_link_libraries(LibJS PUBLIC JSClangPlugin)