From 16b83cd8fb0249bcac4c9a11d9b5c5f1817f1212 Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Fri, 5 May 2023 13:05:58 -0600 Subject: [PATCH] Meta: Add gn build rules for Ladybird --- Meta/gn/secondary/BUILD.gn | 2 + Meta/gn/secondary/Ladybird/BUILD.gn | 123 ++++++++++++++++++ Meta/gn/secondary/Ladybird/SQLServer/BUILD.gn | 33 +++++ .../gn/secondary/Ladybird/WebContent/BUILD.gn | 70 ++++++++++ Meta/gn/secondary/Ladybird/WebDriver/BUILD.gn | 41 ++++++ .../Ladybird/compile_qt_resource_file.gni | 24 ++++ .../Ladybird/invoke_process_with_args.py | 6 + Meta/gn/secondary/Ladybird/link_qt.gni | 25 ++++ Meta/gn/secondary/Ladybird/moc_qt_objects.gni | 18 +++ .../secondary/Ladybird/qt_install_prefix.gni | 26 ++++ .../Userland/Libraries/LibDiff/BUILD.gn | 13 ++ 11 files changed, 381 insertions(+) create mode 100644 Meta/gn/secondary/Ladybird/BUILD.gn create mode 100644 Meta/gn/secondary/Ladybird/SQLServer/BUILD.gn create mode 100644 Meta/gn/secondary/Ladybird/WebContent/BUILD.gn create mode 100644 Meta/gn/secondary/Ladybird/WebDriver/BUILD.gn create mode 100644 Meta/gn/secondary/Ladybird/compile_qt_resource_file.gni create mode 100644 Meta/gn/secondary/Ladybird/invoke_process_with_args.py create mode 100644 Meta/gn/secondary/Ladybird/link_qt.gni create mode 100644 Meta/gn/secondary/Ladybird/moc_qt_objects.gni create mode 100644 Meta/gn/secondary/Ladybird/qt_install_prefix.gni create mode 100644 Meta/gn/secondary/Userland/Libraries/LibDiff/BUILD.gn diff --git a/Meta/gn/secondary/BUILD.gn b/Meta/gn/secondary/BUILD.gn index 94b27c570d..d98c13a6a8 100644 --- a/Meta/gn/secondary/BUILD.gn +++ b/Meta/gn/secondary/BUILD.gn @@ -2,8 +2,10 @@ import("//Meta/gn/build/toolchain/compiler.gni") group("default") { deps = [ + "//Ladybird:ladybird", "//Meta/Lagom/Tools/CodeGenerators/IPCCompiler", "//Tests", + "//Userland/Libraries/LibWeb", "//Userland/Utilities:js", ] testonly = true diff --git a/Meta/gn/secondary/Ladybird/BUILD.gn b/Meta/gn/secondary/Ladybird/BUILD.gn new file mode 100644 index 0000000000..de1ad54073 --- /dev/null +++ b/Meta/gn/secondary/Ladybird/BUILD.gn @@ -0,0 +1,123 @@ +import("//Ladybird/compile_qt_resource_file.gni") +import("//Ladybird/link_qt.gni") +import("//Ladybird/moc_qt_objects.gni") + +moc_qt_objects("generate_moc") { + sources = [ + "BrowserWindow.h", + "ConsoleWidget.h", + "InspectorWidget.h", + "LocationEdit.h", + "ModelTranslator.h", + "SettingsDialog.h", + "Tab.h", + "WebContentView.h", + ] +} + +compile_qt_resource_file("compile_resource_file") { + sources = [ "ladybird.qrc" ] +} + +link_qt("ladybird_qt_components") { + qt_components = [ + "Core", + "Gui", + "Widgets", + "Network", + "Svg", + ] +} + +config("ladybird_config") { + include_dirs = [ + "//Userland/Applications", + "//Userland", + ] + defines = [ "AK_DONT_REPLACE_STD" ] +} + +executable("ladybird") { + configs += [ + ":ladybird_config", + ":ladybird_qt_components", + ] + data_deps = [ + ":headless-browser", + "SQLServer", + "WebContent", + "WebDriver", + ] + deps = [ + ":compile_resource_file", + ":generate_moc", + "//AK", + "//Userland/Libraries/LibCore", + "//Userland/Libraries/LibFileSystem", + "//Userland/Libraries/LibGUI", + "//Userland/Libraries/LibGfx", + "//Userland/Libraries/LibIPC", + "//Userland/Libraries/LibJS", + "//Userland/Libraries/LibMain", + "//Userland/Libraries/LibSQL", + "//Userland/Libraries/LibWeb", + "//Userland/Libraries/LibWebView", + ] + sources = [ + "//Userland/Applications/Browser/CookieJar.cpp", + "//Userland/Applications/Browser/Database.cpp", + "//Userland/Applications/Browser/History.cpp", + "BrowserWindow.cpp", + "ConsoleWidget.cpp", + "EventLoopImplementationQt.cpp", + "HelperProcess.cpp", + "InspectorWidget.cpp", + "LocationEdit.cpp", + "ModelTranslator.cpp", + "Settings.cpp", + "SettingsDialog.cpp", + "Tab.cpp", + "Utilities.cpp", + "WebContentView.cpp", + "main.cpp", + ] + sources += get_target_outputs(":generate_moc") + + get_target_outputs(":compile_resource_file") + if (current_os == "android") { + sources += [ "AndroidPlatform.cpp" ] + } +} + +link_qt("headless_browser_qt") { + qt_components = [ "Core" ] +} + +executable("headless-browser") { + include_dirs = [ "//Userland/Services" ] + configs += [ + ":ladybird_config", + ":headless_browser_qt", + ] + deps = [ + "//Userland/Libraries/LibCore", + "//Userland/Libraries/LibCrypto", + "//Userland/Libraries/LibDiff", + "//Userland/Libraries/LibFileSystem", + "//Userland/Libraries/LibGemini", + "//Userland/Libraries/LibGfx", + "//Userland/Libraries/LibHTTP", + "//Userland/Libraries/LibIPC", + "//Userland/Libraries/LibJS", + "//Userland/Libraries/LibMain", + "//Userland/Libraries/LibTLS", + "//Userland/Libraries/LibWeb", + "//Userland/Libraries/LibWebSocket", + "//Userland/Libraries/LibWebView", + ] + sources = [ + "//Userland/Services/WebContent/WebDriverConnection.cpp", + "//Userland/Utilities/headless-browser.cpp", + "HelperProcess.cpp", + "Utilities.cpp", + ] +} diff --git a/Meta/gn/secondary/Ladybird/SQLServer/BUILD.gn b/Meta/gn/secondary/Ladybird/SQLServer/BUILD.gn new file mode 100644 index 0000000000..3cb4a957a2 --- /dev/null +++ b/Meta/gn/secondary/Ladybird/SQLServer/BUILD.gn @@ -0,0 +1,33 @@ +import("//Ladybird/link_qt.gni") + +link_qt("SQLServer_qt") { + qt_components = [ + "Core", + "Gui", + "Network", + ] +} + +executable("SQLServer") { + configs += [ + "//Ladybird:ladybird_config", + ":SQLServer_qt", + ] + include_dirs = [ + "//Userland/Libraries", + "//Userland/Services", + ] + deps = [ + "//AK", + "//Userland/Libraries/LibCore", + "//Userland/Libraries/LibIPC", + "//Userland/Libraries/LibMain", + "//Userland/Libraries/LibSQL", + ] + sources = [ + "//Userland/Services/SQLServer/ConnectionFromClient.cpp", + "//Userland/Services/SQLServer/DatabaseConnection.cpp", + "//Userland/Services/SQLServer/SQLStatement.cpp", + "main.cpp", + ] +} diff --git a/Meta/gn/secondary/Ladybird/WebContent/BUILD.gn b/Meta/gn/secondary/Ladybird/WebContent/BUILD.gn new file mode 100644 index 0000000000..1160046c7b --- /dev/null +++ b/Meta/gn/secondary/Ladybird/WebContent/BUILD.gn @@ -0,0 +1,70 @@ +import("//Ladybird/link_qt.gni") +import("//Ladybird/moc_qt_objects.gni") + +moc_qt_objects("generate_moc") { + sources = [ + "//Ladybird/AudioCodecPluginLadybird.h", + "//Ladybird/AudioThread.h", + "//Ladybird/RequestManagerQt.h", + ] +} + +link_qt("WebContent_qt") { + qt_components = [ + "Core", + "Gui", + "Network", + "Multimedia", + ] +} + +executable("WebContent") { + configs += [ + "//Ladybird:ladybird_config", + ":WebContent_qt", + ] + include_dirs = [ + "//Userland/Services", + "//Ladybird", + ] + deps = [ + ":generate_moc", + "//AK", + "//Userland/Libraries/LibCore", + "//Userland/Libraries/LibFileSystem", + "//Userland/Libraries/LibGfx", + "//Userland/Libraries/LibIPC", + "//Userland/Libraries/LibJS", + "//Userland/Libraries/LibMain", + "//Userland/Libraries/LibWeb", + "//Userland/Libraries/LibWebSocket", + "//Userland/Libraries/LibWebView:WebContentClientEndpoint", + "//Userland/Libraries/LibWebView:WebContentServerEndpoint", + "//Userland/Libraries/LibWebView:WebDriverClientEndpoint", + "//Userland/Libraries/LibWebView:WebDriverServerEndpoint", + ] + sources = [ + "../AudioCodecPluginLadybird.cpp", + "../AudioThread.cpp", + "../EventLoopImplementationQt.cpp", + "../FontPluginQt.cpp", + "../ImageCodecPluginLadybird.cpp", + "../RequestManagerQt.cpp", + "../Utilities.cpp", + "../WebSocketClientManagerLadybird.cpp", + "../WebSocketImplQt.cpp", + "../WebSocketLadybird.cpp", + "//Userland/Services/WebContent/ConnectionFromClient.cpp", + "//Userland/Services/WebContent/ConsoleGlobalEnvironmentExtensions.cpp", + "//Userland/Services/WebContent/PageHost.cpp", + "//Userland/Services/WebContent/WebContentConsoleClient.cpp", + "//Userland/Services/WebContent/WebDriverConnection.cpp", + "main.cpp", + ] + sources += get_target_outputs(":generate_moc") + + if (current_os == "mac") { + sources += [ "MacOSSetup.mm" ] + frameworks = [ "AppKit.framework" ] + } +} diff --git a/Meta/gn/secondary/Ladybird/WebDriver/BUILD.gn b/Meta/gn/secondary/Ladybird/WebDriver/BUILD.gn new file mode 100644 index 0000000000..bb5407c2f8 --- /dev/null +++ b/Meta/gn/secondary/Ladybird/WebDriver/BUILD.gn @@ -0,0 +1,41 @@ +import("//Ladybird/link_qt.gni") + +link_qt("WebDriver_qt") { + qt_components = [ + "Core", + "Network", + ] +} + +executable("WebDriver") { + configs += [ + "//Ladybird:ladybird_config", + ":WebDriver_qt", + ] + include_dirs = [ + "//Userland/Services", + "//Ladybird", + ] + data_deps = [ "//Ladybird:headless-browser" ] + deps = [ + "//AK", + "//Userland/Libraries/LibCore", + "//Userland/Libraries/LibFileSystem", + "//Userland/Libraries/LibGfx", + "//Userland/Libraries/LibIPC", + "//Userland/Libraries/LibJS", + "//Userland/Libraries/LibMain", + "//Userland/Libraries/LibWeb", + "//Userland/Libraries/LibWebSocket", + "//Userland/Libraries/LibWebView:WebDriverClientEndpoint", + "//Userland/Libraries/LibWebView:WebDriverServerEndpoint", + ] + sources = [ + "../HelperProcess.cpp", + "../Utilities.cpp", + "//Userland/Services/WebDriver/Client.cpp", + "//Userland/Services/WebDriver/Session.cpp", + "//Userland/Services/WebDriver/WebContentConnection.cpp", + "main.cpp", + ] +} diff --git a/Meta/gn/secondary/Ladybird/compile_qt_resource_file.gni b/Meta/gn/secondary/Ladybird/compile_qt_resource_file.gni new file mode 100644 index 0000000000..dad6ea1da7 --- /dev/null +++ b/Meta/gn/secondary/Ladybird/compile_qt_resource_file.gni @@ -0,0 +1,24 @@ +import("qt_install_prefix.gni") + +template("compile_qt_resource_file") { + action_foreach(target_name) { + forward_variables_from(invoker, [ "sources" ]) + + script = "//Meta/gn/secondary/Ladybird/invoke_process_with_args.py" + + outputs = [ "$target_gen_dir/rcc_{{source_name_part}}.cpp" ] + depfile = "$target_gen_dir/rcc_{{source_name_part}}.cpp.d" + args = [ + qt_install_libexec + "rcc", + "-g", + "cpp", + "-d", + rebase_path(target_gen_dir, root_build_dir) + + "/rcc_{{source_name_part}}.cpp.d", + "-o", + rebase_path(target_gen_dir, root_build_dir) + + "/rcc_{{source_name_part}}.cpp", + "{{source}}", + ] + } +} diff --git a/Meta/gn/secondary/Ladybird/invoke_process_with_args.py b/Meta/gn/secondary/Ladybird/invoke_process_with_args.py new file mode 100644 index 0000000000..931625242c --- /dev/null +++ b/Meta/gn/secondary/Ladybird/invoke_process_with_args.py @@ -0,0 +1,6 @@ +#!/usr/bin/env python3 + +import subprocess +import sys + +sys.exit(subprocess.call(sys.argv[1:])) diff --git a/Meta/gn/secondary/Ladybird/link_qt.gni b/Meta/gn/secondary/Ladybird/link_qt.gni new file mode 100644 index 0000000000..7985ad98bb --- /dev/null +++ b/Meta/gn/secondary/Ladybird/link_qt.gni @@ -0,0 +1,25 @@ +import("qt_install_prefix.gni") + +template("link_qt") { + assert(defined(invoker.qt_components), + "Must define qt_component on $target_name") + + config(target_name) { + include_dirs = [ qt_install_headers ] + if (current_os == "mac") { + frameworks = [] + framework_dirs = [ qt_install_frameworks ] + foreach(component, invoker.qt_components) { + include_dirs += [ qt_install_headers + "Qt" + component ] + frameworks += [ "Qt" + component + ".framework" ] + } + } else { + libs = [] + lib_dirs = [ qt_install_lib ] + foreach(component, invoker.qt_components) { + include_dirs += [ qt_install_headers + "Qt" + component ] + libs += [ "Qt6" + component ] + } + } + } +} diff --git a/Meta/gn/secondary/Ladybird/moc_qt_objects.gni b/Meta/gn/secondary/Ladybird/moc_qt_objects.gni new file mode 100644 index 0000000000..206a12b5de --- /dev/null +++ b/Meta/gn/secondary/Ladybird/moc_qt_objects.gni @@ -0,0 +1,18 @@ +import("qt_install_prefix.gni") + +template("moc_qt_objects") { + action_foreach(target_name) { + forward_variables_from(invoker, [ "sources" ]) + + script = "//Meta/gn/secondary/Ladybird/invoke_process_with_args.py" + + outputs = [ "$target_gen_dir/moc_{{source_name_part}}.cpp" ] + args = [ + qt_install_libexec + "moc", + "{{source}}", + "-o", + rebase_path(target_gen_dir, root_build_dir) + + "/moc_{{source_name_part}}.cpp", + ] + } +} diff --git a/Meta/gn/secondary/Ladybird/qt_install_prefix.gni b/Meta/gn/secondary/Ladybird/qt_install_prefix.gni new file mode 100644 index 0000000000..3ef168eeaf --- /dev/null +++ b/Meta/gn/secondary/Ladybird/qt_install_prefix.gni @@ -0,0 +1,26 @@ +declare_args() { + # Location of Qt6 binaries/libraries/frameworks. + # Likely /opt/homebrew on macOS and /usr or /usr/local on Linux + # FIXME: We could get these by parsing `qmake -query` or `pkg-config` + if (host_os == "mac") { + qt_install_prefix = "/opt/homebrew/" + } else { + qt_install_prefix = "/usr/" + } +} + +declare_args() { + # Location of Qt6 headers, normally set based on $qt_install_prefix + qt_install_headers = qt_install_prefix + "include/" + if (current_os == "mac") { + # Location of Qt6 frameworks, normally set based on $qt_install_prefix + qt_install_frameworks = qt_install_prefix + "Frameworks/" + } else { + # Location of Qt6 libraries, normally set based on $qt_install_prefix + qt_install_lib = qt_install_prefix + "lib" + } + + # Location of Qt6 helper programs, normally set based on $qt_install_prefix + # Programs such as moc and rcc are expected to be in this location. + qt_install_libexec = qt_install_prefix + "share/qt/libexec/" +} diff --git a/Meta/gn/secondary/Userland/Libraries/LibDiff/BUILD.gn b/Meta/gn/secondary/Userland/Libraries/LibDiff/BUILD.gn new file mode 100644 index 0000000000..d7643bdf00 --- /dev/null +++ b/Meta/gn/secondary/Userland/Libraries/LibDiff/BUILD.gn @@ -0,0 +1,13 @@ +shared_library("LibDiff") { + include_dirs = [ "//Userland/Libraries" ] + sources = [ + "Format.cpp", + "Generator.cpp", + "Hunks.cpp", + ] + deps = [ + "//AK", + "//Userland/Libraries/LibCore", + ] + output_name = "diff" +}