Ladybird+Meta: Extract AK into its own library on Lagom

We currently bundle AK with LibCore on Lagom. This means that to use AK,
all libraries must also depend on LibCore. This will create circular
dependencies when we create LibURL, as LibURL will depend on LibUnicode,
which will depend on LibCore, which will depend on LibURL.
This commit is contained in:
Timothy Flynn 2024-01-21 18:24:43 -05:00 committed by Tim Flynn
parent 1e7b06aa11
commit 5945cdc054
Notes: sideshowbarker 2024-07-17 04:03:27 +09:00
8 changed files with 75 additions and 78 deletions

View File

@ -175,7 +175,7 @@ target_sources(ladybird PUBLIC FILE_SET ladybird TYPE HEADERS
BASE_DIRS ${SERENITY_SOURCE_DIR}
FILES ${LADYBIRD_HEADERS}
)
target_link_libraries(ladybird PRIVATE LibCore LibFileSystem LibGfx LibImageDecoderClient LibIPC LibJS LibMain LibWeb LibWebView LibProtocol)
target_link_libraries(ladybird PRIVATE AK LibCore LibFileSystem LibGfx LibImageDecoderClient LibIPC LibJS LibMain LibWeb LibWebView LibProtocol)
target_include_directories(ladybird PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_include_directories(ladybird PRIVATE ${SERENITY_SOURCE_DIR}/Userland/)
@ -189,7 +189,7 @@ add_executable(headless-browser
Utilities.cpp)
target_include_directories(headless-browser PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(headless-browser PRIVATE LibWeb LibWebView LibWebSocket LibCrypto LibFileSystem LibGemini LibHTTP LibImageDecoderClient LibJS LibGfx LibMain LibTLS LibIPC LibDiff LibProtocol)
target_link_libraries(headless-browser PRIVATE AK LibCore LibWeb LibWebView LibWebSocket LibCrypto LibFileSystem LibGemini LibHTTP LibImageDecoderClient LibJS LibGfx LibMain LibTLS LibIPC LibDiff LibProtocol)
if (ANDROID)
include(cmake/AndroidExtras.cmake)

View File

@ -224,9 +224,11 @@ function(lagom_lib target_name fs_name)
OUTPUT_NAME lagom-${fs_name}
)
target_link_libraries(${target_name} PRIVATE ${LAGOM_LIBRARY_LIBS})
if (NOT ${target_name} STREQUAL "LibCore")
target_link_libraries(${target_name} PRIVATE LibCore)
if (NOT "${target_name}" STREQUAL "AK")
target_link_libraries(${target_name} PRIVATE AK)
endif()
# FIXME: Clean these up so that we don't need so many include dirs
target_include_directories(${target_name} INTERFACE
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/Services>
@ -262,7 +264,7 @@ function(lagom_test source)
get_filename_component(LAGOM_TEST_NAME ${source} NAME_WE)
endif()
add_executable(${LAGOM_TEST_NAME} ${source})
target_link_libraries(${LAGOM_TEST_NAME} PRIVATE LibCore LibFileSystem LibTest LibTestMain ${LAGOM_TEST_LIBS})
target_link_libraries(${LAGOM_TEST_NAME} PRIVATE AK LibCore LibFileSystem LibTest LibTestMain ${LAGOM_TEST_LIBS})
add_test(
NAME ${LAGOM_TEST_NAME}
COMMAND ${LAGOM_TEST_NAME}
@ -275,7 +277,7 @@ function(lagom_utility name)
cmake_parse_arguments(LAGOM_UTILITY "" "" "SOURCES;LIBS" ${ARGN})
add_executable("${name}" ${LAGOM_UTILITY_SOURCES})
target_link_libraries("${name}" PRIVATE LibCore ${LAGOM_UTILITY_LIBS})
target_link_libraries("${name}" PRIVATE AK LibCore ${LAGOM_UTILITY_LIBS})
endfunction()
function(serenity_test test_src sub_dir)
@ -345,9 +347,11 @@ add_library(NoCoverage INTERFACE)
# "install" these special targets to placate CMake
install(TARGETS LibC LibCrypt LibSystem NoCoverage EXPORT LagomTargets)
# AK/LibCore
# Note: AK is included in LibCore for the host build instead of LibC per the target build
# AK
add_serenity_subdirectory(AK)
lagom_lib(AK ak SOURCES ${AK_SOURCES})
# LibCore
add_serenity_subdirectory(Userland/Libraries/LibCore)
target_link_libraries(LibCore PRIVATE Threads::Threads)
if (${CMAKE_SYSTEM_NAME} MATCHES "NetBSD")
@ -366,7 +370,6 @@ if (HAIKU)
# Haiku has networking related functions in the network library
target_link_libraries(LibCore PRIVATE network)
endif()
target_sources(LibCore PRIVATE ${AK_SOURCES})
# LibMain
add_serenity_subdirectory(Userland/Libraries/LibMain)
@ -499,7 +502,7 @@ if (BUILD_LAGOM)
list(TRANSFORM LIBGUI_SOURCES PREPEND "${SERENITY_PROJECT_ROOT}/Userland/Libraries/LibGUI/")
lagom_lib(LibGUI gui
SOURCES ${LIBGUI_SOURCES}
LIBS LibGfx LibSyntax)
LIBS LibCore LibGfx LibSyntax)
# FIXME: How about we don't include Kernel/API from random high-level libraries?
install(FILES ${SERENITY_PROJECT_ROOT}/Kernel/API/KeyCode.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/Kernel/API")
@ -563,7 +566,7 @@ if (BUILD_LAGOM)
lagom_utility(js SOURCES ../../Userland/Utilities/js.cpp LIBS LibCrypto LibJS LibLine LibLocale LibMain LibTextCodec Threads::Threads)
if (EMSCRIPTEN)
lagom_utility(libjs Wasm/js_repl.cpp LIBS LibJS LibLocale LibTimeZone LibUnicode)
lagom_utility(libjs SOURCES Wasm/js_repl.cpp LIBS LibJS LibLocale LibTimeZone LibUnicode)
target_link_options(libjs PRIVATE
-sEXPORTED_FUNCTIONS=_initialize_repl,_execute
-sEXPORTED_RUNTIME_METHODS=allocateUTF8
@ -612,7 +615,7 @@ if (BUILD_LAGOM)
LibTest
${LIBTEST_SOURCES}
)
target_link_libraries(LibTest PRIVATE LibCore LibFileSystem)
target_link_libraries(LibTest PRIVATE AK LibCore LibFileSystem)
set_target_properties(LibTest PROPERTIES OUTPUT_NAME lagom-test)
add_library(
LibTestMain
@ -677,14 +680,14 @@ if (BUILD_LAGOM)
# test-jpeg-roundtrip
add_executable(test-jpeg-roundtrip
../../Userland/Utilities/test-jpeg-roundtrip.cpp)
target_link_libraries(test-jpeg-roundtrip LibGfx LibMain)
target_link_libraries(test-jpeg-roundtrip AK LibGfx LibMain)
# JavaScriptTestRunner + LibTest tests
# test-js
add_executable(test-js
../../Tests/LibJS/test-js.cpp
../../Userland/Libraries/LibTest/JavaScriptTestRunnerMain.cpp)
target_link_libraries(test-js LibCore LibFileSystem LibTest LibJS)
target_link_libraries(test-js AK LibCore LibFileSystem LibTest LibJS)
add_test(
NAME JS
COMMAND test-js --show-progress=false
@ -699,7 +702,7 @@ if (BUILD_LAGOM)
add_executable(test-spreadsheet
../../Tests/Spreadsheet/test-spreadsheet.cpp
../../Userland/Libraries/LibTest/JavaScriptTestRunnerMain.cpp)
target_link_libraries(test-spreadsheet LibCore LibFileSystem LibTest LibJS)
target_link_libraries(test-spreadsheet AK LibCore LibFileSystem LibTest LibJS)
add_test(
NAME Spreadsheet
COMMAND test-spreadsheet --show-progress=false
@ -710,7 +713,7 @@ if (BUILD_LAGOM)
add_executable(test-wasm
../../Tests/LibWasm/test-wasm.cpp
../../Userland/Libraries/LibTest/JavaScriptTestRunnerMain.cpp)
target_link_libraries(test-wasm LibCore LibFileSystem LibTest LibWasm LibJS LibCrypto)
target_link_libraries(test-wasm AK LibCore LibFileSystem LibTest LibWasm LibJS LibCrypto)
add_test(
NAME WasmParser
COMMAND test-wasm --show-progress=false ${CMAKE_CURRENT_BINARY_DIR}/Userland/Libraries/LibWasm/Tests

View File

@ -24,7 +24,7 @@ add_executable(MacPDF MACOSX_BUNDLE
target_compile_options(MacPDF PRIVATE
-fobjc-arc
)
target_link_libraries(MacPDF PRIVATE LibCore LibGfx LibPDF)
target_link_libraries(MacPDF PRIVATE AK LibCore LibGfx LibPDF)
target_link_libraries(MacPDF PRIVATE
"-framework Cocoa"
"-framework UniformTypeIdentifiers"
@ -39,7 +39,7 @@ set_target_properties(MacPDF PROPERTIES
)
# Normally you'd set `RESOURCE "${RESOURCES}"` on the MacPDF target properties
# and add `"${RESOURCES}" to the sources in add_executable()
# and add `"${RESOURCES}" to the sources in add_executable()
# and CMake would add build steps to compile the xib files to nib files and
# add them to the bundle.
# But with CMake's ninja generator that seems to not work, so do it manually.
@ -51,7 +51,7 @@ foreach(xib ${RESOURCES})
# FIXME: This is gross! It makes the link at least as slow as compiling all xib files.
# Better to have a separate command for the compiles and to only do the copying in the postbuild.
add_custom_command(TARGET MacPDF POST_BUILD
COMMAND ${IBTOOL} --errors --warnings --notices --output-format human-readable-text
COMMAND ${IBTOOL} --errors --warnings --notices --output-format human-readable-text
--compile "$<TARGET_BUNDLE_DIR:MacPDF>/Contents/Resources/${nib}"
"${CMAKE_CURRENT_SOURCE_DIR}/${xib}"
COMMENT "Compiling ${CMAKE_CURRENT_SOURCE_DIR}/${xib}.xib")

View File

@ -6,18 +6,18 @@ function(add_simple_fuzzer name)
configure_file("${name}.dict" "${FUZZER_DICTIONARY_DIRECTORY}/${name}.dict" COPYONLY)
endif()
target_link_libraries(${name}
PUBLIC ${ARGN} LibCore)
PUBLIC ${ARGN} AK LibCore)
elseif (ENABLE_FUZZERS_LIBFUZZER)
target_compile_options(${name}
PRIVATE $<$<CXX_COMPILER_ID:Clang>:-g -O1 -fsanitize=fuzzer>
)
target_link_libraries(${name}
PUBLIC ${ARGN} LibCore
PUBLIC ${ARGN} AK LibCore
PRIVATE $<$<CXX_COMPILER_ID:Clang>:-fsanitize=fuzzer>
)
else()
target_sources(${name} PRIVATE "EntryShim.cpp")
target_link_libraries(${name} PUBLIC ${ARGN} LibCore)
target_link_libraries(${name} PUBLIC ${ARGN} AK LibCore)
endif()
endfunction()
@ -36,7 +36,7 @@ target_compile_options(FuzzilliJs
PRIVATE $<$<CXX_COMPILER_ID:Clang>:-g -O1 -fsanitize-coverage=trace-pc-guard>
)
target_link_libraries(FuzzilliJs
PUBLIC LibCore LibJS
PUBLIC AK LibCore LibJS
PRIVATE $<$<CXX_COMPILER_ID:Clang>:-fsanitize-coverage=trace-pc-guard>
)
endif()

View File

@ -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} LibCore LibFileSystem ${LAGOM_TOOL_LIBS})
target_link_libraries(${tool} AK LibCore LibFileSystem ${LAGOM_TOOL_LIBS})
install(
TARGETS ${tool}
EXPORT LagomTargets

View File

@ -7,20 +7,24 @@ config("ak_headers") {
]
}
source_set("AK") {
shared_library("AK") {
output_name = "ak"
public_configs = [ ":ak_headers" ]
public_deps = [ ":ak_debug_gen" ]
# NOTE: Headers only!
# FIXME: Split out non-kernel sources to their own set
sources = [
"AllOf.h",
"AnyOf.h",
"ArbitrarySizedEnum.h",
"Array.h",
"Assertions.cpp",
"Assertions.h",
"Atomic.h",
"AtomicRefCounted.h",
"Badge.h",
"Base64.cpp",
"Base64.h",
"BigIntBase.h",
"BinaryBufferWriter.h",
@ -35,21 +39,27 @@ source_set("AK") {
"BumpAllocator.h",
"ByteBuffer.h",
"ByteReader.h",
"ByteString.cpp",
"ByteString.h",
"CharacterTypes.h",
"Checked.h",
"CheckedFormatString.h",
"CircularBuffer.cpp",
"CircularBuffer.h",
"CircularDeque.h",
"CircularQueue.h",
"Complex.h",
"Concepts.h",
"ConstrainedStream.cpp",
"ConstrainedStream.h",
"CountingStream.cpp",
"CountingStream.h",
"DOSPackedTime.cpp",
"DOSPackedTime.h",
"DateConstants.h",
"DefaultDelete.h",
"Demangle.h",
"DeprecatedFlyString.cpp",
"DeprecatedFlyString.h",
"Diagnostics.h",
"DisjointChunks.h",
@ -57,23 +67,30 @@ source_set("AK") {
"DoublyLinkedList.h",
"Endian.h",
"EnumBits.h",
"Error.cpp",
"Error.h",
"FPControl.h",
"Find.h",
"FixedArray.h",
"FixedPoint.h",
"FloatingPoint.h",
"FloatingPointStringConversions.cpp",
"FloatingPointStringConversions.h",
"FlyString.cpp",
"FlyString.h",
"Format.cpp",
"Format.h",
"Forward.h",
"Function.h",
"FuzzyMatch.cpp",
"FuzzyMatch.h",
"GenericLexer.cpp",
"GenericLexer.h",
"GenericShorthands.h",
"HashFunctions.h",
"HashMap.h",
"HashTable.h",
"Hex.cpp",
"Hex.h",
"IDAllocator.h",
"IPv4Address.h",
@ -88,26 +105,34 @@ source_set("AK") {
"Iterator.h",
"JsonArray.h",
"JsonArraySerializer.h",
"JsonObject.cpp",
"JsonObject.h",
"JsonObjectSerializer.h",
"JsonParser.cpp",
"JsonParser.h",
"JsonPath.cpp",
"JsonPath.h",
"JsonValue.cpp",
"JsonValue.h",
"LEB128.h",
"LexicalPath.cpp",
"LexicalPath.h",
"MACAddress.h",
"Math.h",
"MaybeOwned.h",
"MemMem.h",
"Memory.h",
"MemoryStream.cpp",
"MemoryStream.h",
"NeverDestroyed.h",
"NoAllocationGuard.h",
"Noncopyable.h",
"NonnullOwnPtr.h",
"NonnullRefPtr.h",
"NumberFormat.cpp",
"NumberFormat.h",
"NumericLimits.h",
"OptionParser.cpp",
"OptionParser.h",
"Optional.h",
"OwnPtr.h",
@ -117,6 +142,7 @@ source_set("AK") {
"Queue.h",
"QuickSelect.h",
"QuickSort.h",
"Random.cpp",
"Random.h",
"RecursionDecision.h",
"RedBlackTree.h",
@ -134,26 +160,38 @@ source_set("AK") {
"Singleton.h",
"SinglyLinkedList.h",
"SinglyLinkedListSizePolicy.h",
"SipHash.cpp",
"SipHash.h",
"Slugify.cpp",
"Slugify.h",
"SourceGenerator.h",
"SourceLocation.h",
"Span.h",
"Stack.h",
"StackInfo.cpp",
"StackInfo.h",
"Statistics.h",
"StdLibExtraDetails.h",
"StdLibExtras.h",
"Stream.cpp",
"Stream.h",
"String.cpp",
"String.h",
"StringBase.cpp",
"StringBase.h",
"StringBuilder.cpp",
"StringBuilder.h",
"StringFloatingPointConversions.cpp",
"StringFloatingPointConversions.h",
"StringHash.h",
"StringImpl.cpp",
"StringImpl.h",
"StringUtils.cpp",
"StringUtils.h",
"StringView.cpp",
"StringView.h",
"TemporaryChange.h",
"Time.cpp",
"Time.h",
"Traits.h",
"Trie.h",
@ -166,74 +204,30 @@ source_set("AK") {
"UBSanitizer.h",
"UFixedBigInt.h",
"UFixedBigIntDivision.h",
"URL.cpp",
"URL.h",
"URLParser.cpp",
"URLParser.h",
"UUID.cpp",
"UUID.h",
"UnicodeUtils.h",
"Userspace.h",
"Utf16View.cpp",
"Utf16View.h",
"Utf32View.cpp",
"Utf32View.h",
"Utf8View.cpp",
"Utf8View.h",
"Variant.h",
"Vector.h",
"WeakPtr.h",
"Weakable.h",
"kmalloc.cpp",
"kmalloc.h",
"kstdio.h",
]
}
source_set("sources") {
deps = [ ":AK" ]
# FIXME: Split out non-kernel sources to their own set
sources = [
"Assertions.cpp",
"Base64.cpp",
"ByteString.cpp",
"CircularBuffer.cpp",
"ConstrainedStream.cpp",
"CountingStream.cpp",
"DOSPackedTime.cpp",
"DeprecatedFlyString.cpp",
"Error.cpp",
"FloatingPointStringConversions.cpp",
"FlyString.cpp",
"Format.cpp",
"FuzzyMatch.cpp",
"GenericLexer.cpp",
"Hex.cpp",
"JsonObject.cpp",
"JsonParser.cpp",
"JsonPath.cpp",
"JsonValue.cpp",
"LexicalPath.cpp",
"MemoryStream.cpp",
"NumberFormat.cpp",
"OptionParser.cpp",
"Random.cpp",
"SipHash.cpp",
"Slugify.cpp",
"StackInfo.cpp",
"Stream.cpp",
"String.cpp",
"StringBase.cpp",
"StringBuilder.cpp",
"StringFloatingPointConversions.cpp",
"StringImpl.cpp",
"StringUtils.cpp",
"StringView.cpp",
"Time.cpp",
"URL.cpp",
"URLParser.cpp",
"UUID.cpp",
"Utf16View.cpp",
"Utf32View.cpp",
"Utf8View.cpp",
"kmalloc.cpp",
]
}
write_cmake_config("ak_debug_gen") {
input = "Debug.h.in"
output = "$root_gen_dir/AK/Debug.h"

View File

@ -144,6 +144,7 @@ executable("headless-browser") {
include_dirs = [ "//Userland/Services" ]
configs += [ ":ladybird_config" ]
deps = [
"//AK",
"//Userland/Libraries/LibCore",
"//Userland/Libraries/LibCrypto",
"//Userland/Libraries/LibDiff",

View File

@ -136,7 +136,6 @@ shared_library("LibCore") {
deps = [
":filewatcher",
":sources",
"//AK:sources",
"//Meta/gn/build/libs/crypt",
"//Meta/gn/build/libs/pthread",
"//Userland/Libraries/LibSystem",