Browse Source

LibCore: Separate some LibCore sources into a minimal object library

We have been dancing around circular dependencies between LibCore and
generated sources. For example, LibURL currently cannot depend on
LibUnicode because the LibUnicode generators depend on LibCore, and
LibCore depends on LibURL. LibTimeZone is in a similar situation.

To alleviate this, we can define the minimal sources that the code
generators need as an object library. This will allow the generators to
depend on this library, rather than the full LibCore.
Timothy Flynn 1 year ago
parent
commit
f7ddcb1f98

+ 34 - 19
Meta/gn/secondary/Userland/Libraries/LibCore/BUILD.gn

@@ -1,25 +1,48 @@
-source_set("sources") {
+# These are the minimal set of sources needed to build the code generators. We separate them to allow
+# LibCore to depend on generated sources.
+source_set("minimal") {
   include_dirs = [ "//Userland/Libraries" ]
-  deps = [ "//AK" ]
+
   sources = [
-    "AnonymousBuffer.cpp",
-    "AnonymousBuffer.h",
     "ArgsParser.cpp",
     "ArgsParser.h",
-    "Command.cpp",
-    "Command.h",
     "ConfigFile.cpp",
     "ConfigFile.h",
-    "DateTime.cpp",
-    "DateTime.h",
-    "Debounce.h",
-    "DeferredInvocationContext.h",
     "DirIterator.cpp",
     "DirIterator.h",
     "Directory.cpp",
     "Directory.h",
     "DirectoryEntry.cpp",
     "DirectoryEntry.h",
+    "File.cpp",
+    "File.h",
+    "Forward.h",
+    "StandardPaths.cpp",
+    "StandardPaths.h",
+    "System.cpp",
+    "System.h",
+    "Version.cpp",
+    "Version.h",
+  ]
+
+  deps = [
+    "//AK",
+    "//Userland/Libraries/LibSystem",
+  ]
+}
+
+source_set("sources") {
+  include_dirs = [ "//Userland/Libraries" ]
+  deps = [ "//AK" ]
+  sources = [
+    "AnonymousBuffer.cpp",
+    "AnonymousBuffer.h",
+    "Command.cpp",
+    "Command.h",
+    "DateTime.cpp",
+    "DateTime.h",
+    "Debounce.h",
+    "DeferredInvocationContext.h",
     "ElapsedTimer.cpp",
     "ElapsedTimer.h",
     "Environment.cpp",
@@ -34,9 +57,6 @@ source_set("sources") {
     "EventLoopImplementationUnix.h",
     "EventReceiver.cpp",
     "EventReceiver.h",
-    "File.cpp",
-    "File.h",
-    "Forward.h",
     "LockFile.cpp",
     "LockFile.h",
     "MappedFile.cpp",
@@ -67,10 +87,6 @@ source_set("sources") {
     "Socket.cpp",
     "Socket.h",
     "SocketAddress.h",
-    "StandardPaths.cpp",
-    "StandardPaths.h",
-    "System.cpp",
-    "System.h",
     "SystemServerTakeover.cpp",
     "SystemServerTakeover.h",
     "TCPServer.cpp",
@@ -83,8 +99,6 @@ source_set("sources") {
     "UDPServer.cpp",
     "UDPServer.h",
     "UmaskScope.h",
-    "Version.cpp",
-    "Version.h",
   ]
   if (current_os != "android") {
     sources += [
@@ -137,6 +151,7 @@ shared_library("LibCore") {
 
   deps = [
     ":filewatcher",
+    ":minimal",
     ":sources",
     "//Meta/gn/build/libs/crypt",
     "//Meta/gn/build/libs/pthread",

+ 16 - 8
Userland/Libraries/LibCore/CMakeLists.txt

@@ -1,12 +1,24 @@
+# These are the minimal set of sources needed to build the code generators. We separate them to allow
+# LibCore to depend on generated sources.
 set(SOURCES
-    AnonymousBuffer.cpp
     ArgsParser.cpp
-    Command.cpp
     ConfigFile.cpp
-    DateTime.cpp
     Directory.cpp
     DirectoryEntry.cpp
     DirIterator.cpp
+    File.cpp
+    StandardPaths.cpp
+    System.cpp
+    Version.cpp
+)
+
+serenity_lib(LibCoreMinimal coreminimal TYPE OBJECT)
+target_link_libraries(LibCoreMinimal PRIVATE LibSystem)
+
+set(SOURCES
+    AnonymousBuffer.cpp
+    Command.cpp
+    DateTime.cpp
     ElapsedTimer.cpp
     Environment.cpp
     Event.cpp
@@ -14,7 +26,6 @@ set(SOURCES
     EventLoopImplementation.cpp
     EventLoopImplementationUnix.cpp
     EventReceiver.cpp
-    File.cpp
     LockFile.cpp
     MappedFile.cpp
     MimeData.cpp
@@ -29,14 +40,11 @@ set(SOURCES
     SessionManagement.cpp
     Socket.cpp
     SOCKSProxyClient.cpp
-    StandardPaths.cpp
-    System.cpp
     SystemServerTakeover.cpp
     TCPServer.cpp
     ThreadEventQueue.cpp
     Timer.cpp
     UDPServer.cpp
-    Version.cpp
 )
 if (NOT ANDROID AND NOT WIN32 AND NOT EMSCRIPTEN)
     list(APPEND SOURCES
@@ -62,7 +70,7 @@ else()
 endif()
 
 serenity_lib(LibCore core)
-target_link_libraries(LibCore PRIVATE LibCrypt LibSystem LibURL)
+target_link_libraries(LibCore PRIVATE LibCoreMinimal LibCrypt LibSystem LibURL)
 
 if (APPLE)
     target_link_libraries(LibCore PUBLIC "-framework CoreFoundation")