From c6e9f0e7b5b050ddbb5d735ca9c65458add9b4a5 Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Mon, 3 Jun 2024 15:46:00 -0600 Subject: [PATCH] Meta+Documentation: Switch default build dir to Build/Ladybird Also prefer using the new top-level CMakeLists.txt --- .gitignore | 6 +-- .ycm_extra_conf.py | 51 ++-------------------- Documentation/AdvancedBuildInstructions.md | 4 +- Documentation/BuildInstructionsLadybird.md | 21 +++------ Documentation/CLionConfiguration.md | 4 +- Documentation/EmacsConfiguration.md | 7 +-- Documentation/HelixConfiguration.md | 4 +- Documentation/NvimConfiguration.md | 2 +- Documentation/VSCodeConfiguration.md | 36 +++++++-------- Meta/ladybird.sh | 24 +--------- Tests/LibWeb/WPT/run.sh | 2 +- 11 files changed, 39 insertions(+), 122 deletions(-) diff --git a/.gitignore b/.gitignore index 589944f75f5..d072dfc733d 100644 --- a/.gitignore +++ b/.gitignore @@ -9,8 +9,8 @@ *.cflags *.cxxflags *.autosave -Meta/Lagom/build -Build +build* +Build* Toolchain/Tarballs Toolchain/Build Toolchain/Local @@ -23,8 +23,6 @@ compile_commands.json .idea/ cmake-build-debug/ output/ -run-local.sh -sync-local.sh .vim/ .exrc .helix/ diff --git a/.ycm_extra_conf.py b/.ycm_extra_conf.py index 782f1102daa..d12c9923320 100644 --- a/.ycm_extra_conf.py +++ b/.ycm_extra_conf.py @@ -32,42 +32,12 @@ # For more information, please refer to import os -import subprocess import ycm_core DIR_OF_THIS_SCRIPT = os.path.abspath(os.path.dirname(__file__)) SOURCE_EXTENSIONS = ['.cpp', '.c'] -gcc_path = None -for serenity_arch in ['x86_64', 'aarch64']: - candidate_gcc_path = os.path.join( - DIR_OF_THIS_SCRIPT, 'Toolchain', - 'Local', serenity_arch, 'bin', f'{serenity_arch}-pc-serenity-gcc' - ) - if os.path.isfile(candidate_gcc_path): - gcc_path = candidate_gcc_path - break - -serenity_flags = [ - '-D__serenity__', - '-D__unix__' -] - -if gcc_path: - gcc_output = subprocess.check_output( - [gcc_path, '-E', '-Wp,-v', '-'], - stdin=subprocess.DEVNULL, stderr=subprocess.STDOUT - ).rstrip().decode('utf8').split("\n") - - for line in gcc_output: - if not line.startswith(' '): - continue - include_path = line.lstrip() - if '/../Build/' in include_path: - continue - serenity_flags.extend(('-isystem', include_path)) - -database = ycm_core.CompilationDatabase(os.path.join(DIR_OF_THIS_SCRIPT, f'Build/{serenity_arch}')) +database = ycm_core.CompilationDatabase(os.path.join(DIR_OF_THIS_SCRIPT, 'Build/ladybird')) def is_header_file(filename): @@ -85,14 +55,7 @@ def find_corresponding_source_file(filename): return filename -def startswith_any(string, prefixes): - for prefix in prefixes: - if string.startswith(prefix): - return True - return False - - -def Settings(**kwargs): +def Settings(**kwargs): # noqa: N802 if kwargs['language'] != 'cfamily': return {} # If the file is a header, try to find the corresponding source file and @@ -107,16 +70,8 @@ def Settings(**kwargs): if not compilation_info.compiler_flags_: return {} - ignored_flags = [ - '--sysroot', - '-fzero-call-used-regs=used-gpr', - ] - - final_flags = [flag for flag in compilation_info.compiler_flags_ if not startswith_any(flag, ignored_flags)] - final_flags.extend(serenity_flags) - return { - 'flags': final_flags, + 'flags': compilation_info.compiler_flags_, 'include_paths_relative_to_dir': DIR_OF_THIS_SCRIPT, 'override_filename': filename } diff --git a/Documentation/AdvancedBuildInstructions.md b/Documentation/AdvancedBuildInstructions.md index 6696f95b621..e89bdd9f885 100644 --- a/Documentation/AdvancedBuildInstructions.md +++ b/Documentation/AdvancedBuildInstructions.md @@ -6,7 +6,7 @@ This file covers a few advanced scenarios that go beyond what the basic build gu The `Meta/ladybird.sh` script provides an abstraction over the build targets which are made available by CMake. The following build targets cannot be accessed through the script and have to be used directly by changing the current -directory to `Build/x86_64` and then running `ninja `: +directory to `Build/ladybird` and then running `ninja `: - `ninja check-style`: Runs the same linters the CI does to verify project style on changed files - `ninja lint-shell-scripts`: Checks style of shell scripts in the source tree with shellcheck @@ -58,7 +58,7 @@ For example, boolean options such as `ENABLE_` or `_DEB ```console # Reconfigure an existing binary directory with process debug enabled -$ cmake -B Build/x86_64 -DPROCESS_DEBUG=ON +$ cmake -B Build/ladbyird -DPROCESS_DEBUG=ON ``` For more information on how the CMake cache works, see the CMake guide for [Running CMake](https://cmake.org/runningcmake/). Additional context is available in the CMake documentation for diff --git a/Documentation/BuildInstructionsLadybird.md b/Documentation/BuildInstructionsLadybird.md index cc4b800aca2..45805f45f49 100644 --- a/Documentation/BuildInstructionsLadybird.md +++ b/Documentation/BuildInstructionsLadybird.md @@ -109,15 +109,11 @@ Qt chrome, install the Qt dependencies for your platform, and enable the Qt chro ```bash # From /path/to/ladybird -cmake -S Meta/Lagom -B Build/lagom -DENABLE_QT=ON +cmake -B Build/ladybird -DENABLE_QT=ON ``` To re-disable the Qt chrome, run the above command with `-DENABLE_QT=OFF`. -```bash -cmake -S Meta/Lagom -B Build/lagom -DENABLE_LAGOM_LADYBIRD=OFF -DENABLE_LAGOM_LIBWEB=OFF -DBUILD_LAGOM=OFF -``` - ### Resource files Ladybird requires resource files from the ladybird/Base/res directory in order to properly load @@ -142,7 +138,7 @@ a suitable C++ compiler (g++ >= 13, clang >= 14, Apple Clang >= 14.3) via the CM CMAKE_C_COMPILER cmake options. ``` -cmake -GNinja -S Ladybird -B Build/ladybird +cmake -GNinja -B Build/ladybird # optionally, add -DCMAKE_CXX_COMPILER= -DCMAKE_C_COMPILER= cmake --build Build/ladybird ninja -C Build/ladybird run @@ -186,16 +182,9 @@ Now breakpoints, stepping and variable inspection will work. ### Debugging with Xcode on macOS The `ladybird.sh` build script does not know how to generate Xcode projects, so creating the project must be done manually. -To be compatible with the `ladybird.sh` script, a few extra options are required. If there is a previous Lagom build directory, CMake will likely complain that the generator has changed. ``` -cmake -GXcode -S Meta/Lagom -B Build/lagom -DBUILD_LAGOM=ON -DENABLE_LAGOM_LADYBIRD=ON -``` - -Alternatively, if you don't need your ladybird build to be compatible with `ladybird.sh`, you can use Ladybird as the source directory like so: - -``` -cmake -GXcode -S Ladybird -B Build/ladybird +cmake -GXcode -B Build/ladybird ``` After generating an Xcode project into the specified build directory, you can open `ladybird.xcodeproj` in Xcode. The project has a ton of targets, many of which are generated code. @@ -213,7 +202,7 @@ When running Ladybird, make sure that XDG_RUNTIME_DIR is set, or it will immedia doesn't find a writable directory for its sockets. ``` -CMAKE_PREFIX_PATH=/usr/lib/qt/6.2/lib/amd64/cmake cmake -GNinja -S Ladybird -B Build/ladybird -DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang++ +CMAKE_PREFIX_PATH=/usr/lib/qt/6.2/lib/amd64/cmake cmake -GNinja -B Build/ladybird -DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang++ cmake --build Build/ladybird XDG_RUNTIME_DIR=/var/tmp ninja -C Build/ladybird run ``` @@ -224,7 +213,7 @@ Haiku is supported by Ladybird out of the box. The steps are the same as on Open additional environment variables are required. ``` -cmake -GNinja -S Ladybird -B Build/ladybird +cmake -GNinja -B Build/ladybird cmake --build Build/ladybird ninja -C Build/ladybird run ``` diff --git a/Documentation/CLionConfiguration.md b/Documentation/CLionConfiguration.md index dde509ad5f1..54e138aeea4 100644 --- a/Documentation/CLionConfiguration.md +++ b/Documentation/CLionConfiguration.md @@ -4,7 +4,7 @@ CLion can integrate with CMake to provide code comprehension features. After opening the `ladybird` repository in CLion as a new project, the "`Open Project Wizard`" window will open, from here set the following fields: -(Assuming you use `Ninja` as the build system and configured the CMake build directory to `Build/lagom`) +(Assuming you use `Ninja` as the build system and configured the CMake build directory to `Build/ladybird`) `CMake Options`: ``` @@ -12,7 +12,7 @@ After opening the `ladybird` repository in CLion as a new project, the "`Open Pr -GNinja ``` -`Build Directory`: `Build/lagom` +`Build Directory`: `Build/ladybird` If you already have the project open, you can go to `File -> Settings -> Build, Execution, Deployment -> CMake` to find these options. diff --git a/Documentation/EmacsConfiguration.md b/Documentation/EmacsConfiguration.md index 217365f6a3f..03e1fd333fe 100644 --- a/Documentation/EmacsConfiguration.md +++ b/Documentation/EmacsConfiguration.md @@ -9,18 +9,15 @@ can use the following `.clangd` file placed in the project root: ```yaml CompileFlags: - CompilationDatabase: Build/lagom + CompilationDatabase: Build/ladybird Diagnostics: UnusedIncludes: None MissingIncludes: None ``` -You will need to change `/path/to/ladybird` and change `13.1.0` to -whatever your GCC toolchain version at the time is. - Run cmake (`Meta/ladybird.sh run ladybird` or similar) at least once for this -to work, as it will generate the `Build/lagom/compile_commands.json` +to work, as it will generate the `Build/ladybird/compile_commands.json` that is needed by `clangd`. ### lsp-mode diff --git a/Documentation/HelixConfiguration.md b/Documentation/HelixConfiguration.md index 30c345b139f..77d188362e6 100644 --- a/Documentation/HelixConfiguration.md +++ b/Documentation/HelixConfiguration.md @@ -4,7 +4,7 @@ Helix comes with support for `clangd` and `clang-format` out of the box! However The following `.clangd` should be placed in the project root: ```yaml CompileFlags: - CompilationDatabase: Build/lagom + CompilationDatabase: Build/ladybird Diagnostics: UnusedIncludes: None @@ -21,5 +21,3 @@ args = ["--header-insertion=never"] name = "cpp" language-servers = ["ladybird"] ``` - -> Make sure to replace `/path/to/ladybird` with the actual path in the snippet above! diff --git a/Documentation/NvimConfiguration.md b/Documentation/NvimConfiguration.md index e7834a80db2..5eea5148213 100644 --- a/Documentation/NvimConfiguration.md +++ b/Documentation/NvimConfiguration.md @@ -180,7 +180,7 @@ nmap gs :CocCommand clangd.switchSourceHeader vsplit > **Note**: Every time a new source is added or the compilation commands get adjusted (through CMake) you need to rerun `./Meta/ladybird.sh rebuild`. -Link `ln -s /path/to/ladybird/Build/lagom/compile_commands.json /path/to/ladybird/compile_commands.json`. +Link `ln -s /path/to/ladybird/Build/ladybird/compile_commands.json /path/to/ladybird/compile_commands.json`. Create `/path/to/ladybird/.clangd` (replace `/path/to/ladybird` with your ladybird directory) with content of the clangd section in the diff --git a/Documentation/VSCodeConfiguration.md b/Documentation/VSCodeConfiguration.md index dbec30fdf17..240056b7492 100644 --- a/Documentation/VSCodeConfiguration.md +++ b/Documentation/VSCodeConfiguration.md @@ -17,12 +17,12 @@ Clangd has the best support for cross-compiling workflows, especially if configu The official clangd extension can be used for C++ comprehension. It is recommended in general, as it is most likely to work on all platforms. -clangd uses ``compile_commands.json`` files to understand the project. CMake will generate these in Build/lagom. +clangd uses ``compile_commands.json`` files to understand the project. CMake will generate these in Build/ladybird. Depending on which configuration you use most, set the CompilationDatabase configuration item in the below ``.clangd`` file accordingly. It goes at the root of your checkout (``ladybird/.clangd``): ```yaml CompileFlags: - CompilationDatabase: Build/lagom + CompilationDatabase: Build/ladybird Diagnostics: UnusedIncludes: None @@ -60,10 +60,10 @@ following ``c_cpp_properties.json`` to circumvent some errors. Even with the con "name": "ladybird-gcc", "includePath": [ "${workspaceFolder}", - "${workspaceFolder}/Build/lagom/", - "${workspaceFolder}/Build/lagom/Userland", - "${workspaceFolder}/Build/lagom/Userland/Libraries", - "${workspaceFolder}/Build/lagom/Userland/Services", + "${workspaceFolder}/Build/ladybird/", + "${workspaceFolder}/Build/ladybird/Userland", + "${workspaceFolder}/Build/ladybird/Userland/Libraries", + "${workspaceFolder}/Build/ladybird/Userland/Services", "${workspaceFolder}/Userland", "${workspaceFolder}/Userland/Libraries", "${workspaceFolder}/Userland/Services" @@ -74,7 +74,7 @@ following ``c_cpp_properties.json`` to circumvent some errors. Even with the con "cStandard": "c17", "cppStandard": "c++23", "intelliSenseMode": "linux-gcc-x86", - "compileCommands": "Build/lagom/compile_commands.json", + "compileCommands": "Build/ladybird/compile_commands.json", "compilerArgs": [ "-Wall", "-Wextra", @@ -83,16 +83,16 @@ following ``c_cpp_properties.json`` to circumvent some errors. Even with the con "browse": { "path": [ "${workspaceFolder}", - "${workspaceFolder}/Build/lagom/", - "${workspaceFolder}/Build/lagom/Userland", - "${workspaceFolder}/Build/lagom/Userland/Libraries", - "${workspaceFolder}/Build/lagom/Userland/Services", + "${workspaceFolder}/Build/ladybird/", + "${workspaceFolder}/Build/ladybird/Userland", + "${workspaceFolder}/Build/ladybird/Userland/Libraries", + "${workspaceFolder}/Build/ladybird/Userland/Services", "${workspaceFolder}/Userland", "${workspaceFolder}/Userland/Libraries", "${workspaceFolder}/Userland/Services" ], "limitSymbolsToIncludedHeaders": true, - "databaseFilename": "${workspaceFolder}/Build/lagom/" + "databaseFilename": "${workspaceFolder}/Build/ladybird/" } } ], @@ -165,7 +165,7 @@ The following three example tasks should suffice in most situations, and allow y "base": "$gcc", "fileLocation": [ "relative", - "${workspaceFolder}/Build/lagom" + "${workspaceFolder}/Build/ladybird" ] } ], @@ -199,14 +199,14 @@ The following three example tasks should suffice in most situations, and allow y "base": "$gcc", "fileLocation": [ "relative", - "${workspaceFolder}/Build/lagom" + "${workspaceFolder}/Build/ladybird" ] }, { "source": "gcc", "fileLocation": [ "relative", - "${workspaceFolder}/Build/lagom" + "${workspaceFolder}/Build/ladybird" ], "pattern": [ { @@ -241,14 +241,14 @@ The following three example tasks should suffice in most situations, and allow y "base": "$gcc", "fileLocation": [ "relative", - "${workspaceFolder}/Build/lagom" + "${workspaceFolder}/Build/ladybird" ] }, { "source": "gcc", "fileLocation": [ "relative", - "${workspaceFolder}/Build/lagom" + "${workspaceFolder}/Build/ladybird" ], "pattern": [ { @@ -275,7 +275,7 @@ The following three example tasks should suffice in most situations, and allow y ], "fileLocation": [ "relative", - "${workspaceFolder}/Build/lagom" + "${workspaceFolder}/Build/ladybird" ] } ] diff --git a/Meta/ladybird.sh b/Meta/ladybird.sh index 03678df194f..f1007cc7dd9 100755 --- a/Meta/ladybird.sh +++ b/Meta/ladybird.sh @@ -67,21 +67,11 @@ get_top_dir() { git rev-parse --show-toplevel } -is_valid_target() { - CMAKE_ARGS+=("-DBUILD_LAGOM=ON") - if [ "${CMD_ARGS[0]}" = "ladybird" ]; then - CMAKE_ARGS+=("-DENABLE_LAGOM_LADYBIRD=ON") - fi - return 0 -} - create_build_dir() { - cmake -GNinja "${CMAKE_ARGS[@]}" -S "$LADYBIRD_SOURCE_DIR/Meta/Lagom" -B "$BUILD_DIR" + cmake -GNinja "${CMAKE_ARGS[@]}" -S "$LADYBIRD_SOURCE_DIR" -B "$BUILD_DIR" } cmd_with_target() { - is_valid_target || ( >&2 echo "Unknown target: $TARGET"; usage ) - pick_host_compiler CMAKE_ARGS+=("-DCMAKE_C_COMPILER=${CC}") CMAKE_ARGS+=("-DCMAKE_CXX_COMPILER=${CXX}") @@ -90,7 +80,7 @@ cmd_with_target() { LADYBIRD_SOURCE_DIR="$(get_top_dir)" export LADYBIRD_SOURCE_DIR fi - BUILD_DIR="$LADYBIRD_SOURCE_DIR/Build/lagom" + BUILD_DIR="$LADYBIRD_SOURCE_DIR/Build/ladybird" CMAKE_ARGS+=("-DCMAKE_INSTALL_PREFIX=$LADYBIRD_SOURCE_DIR/Build/lagom-install") CMAKE_ARGS+=("-DSERENITY_CACHE_DIR=${LADYBIRD_SOURCE_DIR}/Build/caches") export PATH="$LADYBIRD_SOURCE_DIR/Toolchain/Local/cmake/bin":$PATH @@ -113,12 +103,6 @@ run_tests() { } build_target() { - local EXTRA_CMAKE_ARGS=() - if [ "${CMD_ARGS[0]}" = "ladybird" ]; then - EXTRA_CMAKE_ARGS=("-DENABLE_LAGOM_LADYBIRD=ON") - fi - cmake -S "$LADYBIRD_SOURCE_DIR/Meta/Lagom" -B "$BUILD_DIR" -DBUILD_LAGOM=ON "${EXTRA_CMAKE_ARGS[@]}" - # Get either the environment MAKEJOBS or all processors via CMake [ -z "$MAKEJOBS" ] && MAKEJOBS=$(cmake -P "$LADYBIRD_SOURCE_DIR/Meta/CMake/processor-count.cmake") @@ -163,10 +147,6 @@ run_gdb() { die "Lagom executable can't be specified more than once" fi LAGOM_EXECUTABLE="$arg" - if [ "$LAGOM_EXECUTABLE" = "ladybird" ]; then - # FIXME: Make ladybird less cwd-dependent while in the build directory - cd "$BUILD_DIR/Ladybird" - fi fi done if [ "$PASS_ARG_TO_GDB" != "" ]; then diff --git a/Tests/LibWeb/WPT/run.sh b/Tests/LibWeb/WPT/run.sh index 0ccd8aef6dc..121c985f1dd 100755 --- a/Tests/LibWeb/WPT/run.sh +++ b/Tests/LibWeb/WPT/run.sh @@ -11,7 +11,7 @@ then fi -: "${WEBDRIVER_BINARY:=$(env PATH="${LADYBIRD_SOURCE_DIR}/Build/lagom/bin/Ladybird.app/Contents/MacOS:${LADYBIRD_SOURCE_DIR}/Build/lagom/bin:${LADYBIRD_SOURCE_DIR}/Meta/Lagom/Build/bin:${PATH}" \ +: "${WEBDRIVER_BINARY:=$(env PATH="${LADYBIRD_SOURCE_DIR}/Build/ladybird/bin/Ladybird.app/Contents/MacOS:${LADYBIRD_SOURCE_DIR}/Build/ladybird/bin:${LADYBIRD_SOURCE_DIR}/Build/bin:${PATH}" \ which WebDriver)}" update_expectations_metadata=false remove_wpt_repository=false