Meta+Documentation: Switch default build dir to Build/Ladybird

Also prefer using the new top-level CMakeLists.txt
This commit is contained in:
Andrew Kaster 2024-06-03 15:46:00 -06:00
parent e8b6de51fe
commit c6e9f0e7b5
Notes: sideshowbarker 2024-07-17 02:56:25 +09:00
11 changed files with 39 additions and 122 deletions

6
.gitignore vendored
View file

@ -9,8 +9,8 @@
*.cflags *.cflags
*.cxxflags *.cxxflags
*.autosave *.autosave
Meta/Lagom/build build*
Build Build*
Toolchain/Tarballs Toolchain/Tarballs
Toolchain/Build Toolchain/Build
Toolchain/Local Toolchain/Local
@ -23,8 +23,6 @@ compile_commands.json
.idea/ .idea/
cmake-build-debug/ cmake-build-debug/
output/ output/
run-local.sh
sync-local.sh
.vim/ .vim/
.exrc .exrc
.helix/ .helix/

View file

@ -32,42 +32,12 @@
# For more information, please refer to <http://unlicense.org/> # For more information, please refer to <http://unlicense.org/>
import os import os
import subprocess
import ycm_core import ycm_core
DIR_OF_THIS_SCRIPT = os.path.abspath(os.path.dirname(__file__)) DIR_OF_THIS_SCRIPT = os.path.abspath(os.path.dirname(__file__))
SOURCE_EXTENSIONS = ['.cpp', '.c'] SOURCE_EXTENSIONS = ['.cpp', '.c']
gcc_path = None database = ycm_core.CompilationDatabase(os.path.join(DIR_OF_THIS_SCRIPT, 'Build/ladybird'))
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}'))
def is_header_file(filename): def is_header_file(filename):
@ -85,14 +55,7 @@ def find_corresponding_source_file(filename):
return filename return filename
def startswith_any(string, prefixes): def Settings(**kwargs): # noqa: N802
for prefix in prefixes:
if string.startswith(prefix):
return True
return False
def Settings(**kwargs):
if kwargs['language'] != 'cfamily': if kwargs['language'] != 'cfamily':
return {} return {}
# If the file is a header, try to find the corresponding source file and # 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_: if not compilation_info.compiler_flags_:
return {} 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 { return {
'flags': final_flags, 'flags': compilation_info.compiler_flags_,
'include_paths_relative_to_dir': DIR_OF_THIS_SCRIPT, 'include_paths_relative_to_dir': DIR_OF_THIS_SCRIPT,
'override_filename': filename 'override_filename': filename
} }

View file

@ -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 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 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 <target>`: directory to `Build/ladybird` and then running `ninja <target>`:
- `ninja check-style`: Runs the same linters the CI does to verify project style on changed files - `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 - `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_<setting>` or `<component_name>_DEB
```console ```console
# Reconfigure an existing binary directory with process debug enabled # 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 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

View file

@ -109,15 +109,11 @@ Qt chrome, install the Qt dependencies for your platform, and enable the Qt chro
```bash ```bash
# From /path/to/ladybird # 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`. 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 ### Resource files
Ladybird requires resource files from the ladybird/Base/res directory in order to properly load 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_C_COMPILER cmake options.
``` ```
cmake -GNinja -S Ladybird -B Build/ladybird cmake -GNinja -B Build/ladybird
# optionally, add -DCMAKE_CXX_COMPILER=<suitable compiler> -DCMAKE_C_COMPILER=<matching c compiler> # optionally, add -DCMAKE_CXX_COMPILER=<suitable compiler> -DCMAKE_C_COMPILER=<matching c compiler>
cmake --build Build/ladybird cmake --build Build/ladybird
ninja -C Build/ladybird run ninja -C Build/ladybird run
@ -186,16 +182,9 @@ Now breakpoints, stepping and variable inspection will work.
### Debugging with Xcode on macOS ### 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. 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 cmake -GXcode -B Build/ladybird
```
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
``` ```
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. 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. 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 cmake --build Build/ladybird
XDG_RUNTIME_DIR=/var/tmp ninja -C Build/ladybird run 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. additional environment variables are required.
``` ```
cmake -GNinja -S Ladybird -B Build/ladybird cmake -GNinja -B Build/ladybird
cmake --build Build/ladybird cmake --build Build/ladybird
ninja -C Build/ladybird run ninja -C Build/ladybird run
``` ```

View file

@ -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: 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`: `CMake Options`:
``` ```
@ -12,7 +12,7 @@ After opening the `ladybird` repository in CLion as a new project, the "`Open Pr
-GNinja -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. If you already have the project open, you can go to `File -> Settings -> Build, Execution, Deployment -> CMake` to find these options.

View file

@ -9,18 +9,15 @@ can use the following `.clangd` file placed in the project root:
```yaml ```yaml
CompileFlags: CompileFlags:
CompilationDatabase: Build/lagom CompilationDatabase: Build/ladybird
Diagnostics: Diagnostics:
UnusedIncludes: None UnusedIncludes: None
MissingIncludes: 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 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`. that is needed by `clangd`.
### lsp-mode ### lsp-mode

View file

@ -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: The following `.clangd` should be placed in the project root:
```yaml ```yaml
CompileFlags: CompileFlags:
CompilationDatabase: Build/lagom CompilationDatabase: Build/ladybird
Diagnostics: Diagnostics:
UnusedIncludes: None UnusedIncludes: None
@ -21,5 +21,3 @@ args = ["--header-insertion=never"]
name = "cpp" name = "cpp"
language-servers = ["ladybird"] language-servers = ["ladybird"]
``` ```
> Make sure to replace `/path/to/ladybird` with the actual path in the snippet above!

View file

@ -180,7 +180,7 @@ nmap <silent>gs :CocCommand clangd.switchSourceHeader vsplit<CR>
> **Note**: Every time a new source is added or the compilation commands get adjusted > **Note**: Every time a new source is added or the compilation commands get adjusted
(through CMake) you need to rerun `./Meta/ladybird.sh rebuild`. (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` Create `/path/to/ladybird/.clangd` (replace `/path/to/ladybird`
with your ladybird directory) with content of the clangd section in the with your ladybird directory) with content of the clangd section in the

View file

@ -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. 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``): 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 ```yaml
CompileFlags: CompileFlags:
CompilationDatabase: Build/lagom CompilationDatabase: Build/ladybird
Diagnostics: Diagnostics:
UnusedIncludes: None UnusedIncludes: None
@ -60,10 +60,10 @@ following ``c_cpp_properties.json`` to circumvent some errors. Even with the con
"name": "ladybird-gcc", "name": "ladybird-gcc",
"includePath": [ "includePath": [
"${workspaceFolder}", "${workspaceFolder}",
"${workspaceFolder}/Build/lagom/", "${workspaceFolder}/Build/ladybird/",
"${workspaceFolder}/Build/lagom/Userland", "${workspaceFolder}/Build/ladybird/Userland",
"${workspaceFolder}/Build/lagom/Userland/Libraries", "${workspaceFolder}/Build/ladybird/Userland/Libraries",
"${workspaceFolder}/Build/lagom/Userland/Services", "${workspaceFolder}/Build/ladybird/Userland/Services",
"${workspaceFolder}/Userland", "${workspaceFolder}/Userland",
"${workspaceFolder}/Userland/Libraries", "${workspaceFolder}/Userland/Libraries",
"${workspaceFolder}/Userland/Services" "${workspaceFolder}/Userland/Services"
@ -74,7 +74,7 @@ following ``c_cpp_properties.json`` to circumvent some errors. Even with the con
"cStandard": "c17", "cStandard": "c17",
"cppStandard": "c++23", "cppStandard": "c++23",
"intelliSenseMode": "linux-gcc-x86", "intelliSenseMode": "linux-gcc-x86",
"compileCommands": "Build/lagom/compile_commands.json", "compileCommands": "Build/ladybird/compile_commands.json",
"compilerArgs": [ "compilerArgs": [
"-Wall", "-Wall",
"-Wextra", "-Wextra",
@ -83,16 +83,16 @@ following ``c_cpp_properties.json`` to circumvent some errors. Even with the con
"browse": { "browse": {
"path": [ "path": [
"${workspaceFolder}", "${workspaceFolder}",
"${workspaceFolder}/Build/lagom/", "${workspaceFolder}/Build/ladybird/",
"${workspaceFolder}/Build/lagom/Userland", "${workspaceFolder}/Build/ladybird/Userland",
"${workspaceFolder}/Build/lagom/Userland/Libraries", "${workspaceFolder}/Build/ladybird/Userland/Libraries",
"${workspaceFolder}/Build/lagom/Userland/Services", "${workspaceFolder}/Build/ladybird/Userland/Services",
"${workspaceFolder}/Userland", "${workspaceFolder}/Userland",
"${workspaceFolder}/Userland/Libraries", "${workspaceFolder}/Userland/Libraries",
"${workspaceFolder}/Userland/Services" "${workspaceFolder}/Userland/Services"
], ],
"limitSymbolsToIncludedHeaders": true, "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", "base": "$gcc",
"fileLocation": [ "fileLocation": [
"relative", "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", "base": "$gcc",
"fileLocation": [ "fileLocation": [
"relative", "relative",
"${workspaceFolder}/Build/lagom" "${workspaceFolder}/Build/ladybird"
] ]
}, },
{ {
"source": "gcc", "source": "gcc",
"fileLocation": [ "fileLocation": [
"relative", "relative",
"${workspaceFolder}/Build/lagom" "${workspaceFolder}/Build/ladybird"
], ],
"pattern": [ "pattern": [
{ {
@ -241,14 +241,14 @@ The following three example tasks should suffice in most situations, and allow y
"base": "$gcc", "base": "$gcc",
"fileLocation": [ "fileLocation": [
"relative", "relative",
"${workspaceFolder}/Build/lagom" "${workspaceFolder}/Build/ladybird"
] ]
}, },
{ {
"source": "gcc", "source": "gcc",
"fileLocation": [ "fileLocation": [
"relative", "relative",
"${workspaceFolder}/Build/lagom" "${workspaceFolder}/Build/ladybird"
], ],
"pattern": [ "pattern": [
{ {
@ -275,7 +275,7 @@ The following three example tasks should suffice in most situations, and allow y
], ],
"fileLocation": [ "fileLocation": [
"relative", "relative",
"${workspaceFolder}/Build/lagom" "${workspaceFolder}/Build/ladybird"
] ]
} }
] ]

View file

@ -67,21 +67,11 @@ get_top_dir() {
git rev-parse --show-toplevel 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() { 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() { cmd_with_target() {
is_valid_target || ( >&2 echo "Unknown target: $TARGET"; usage )
pick_host_compiler pick_host_compiler
CMAKE_ARGS+=("-DCMAKE_C_COMPILER=${CC}") CMAKE_ARGS+=("-DCMAKE_C_COMPILER=${CC}")
CMAKE_ARGS+=("-DCMAKE_CXX_COMPILER=${CXX}") CMAKE_ARGS+=("-DCMAKE_CXX_COMPILER=${CXX}")
@ -90,7 +80,7 @@ cmd_with_target() {
LADYBIRD_SOURCE_DIR="$(get_top_dir)" LADYBIRD_SOURCE_DIR="$(get_top_dir)"
export LADYBIRD_SOURCE_DIR export LADYBIRD_SOURCE_DIR
fi 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+=("-DCMAKE_INSTALL_PREFIX=$LADYBIRD_SOURCE_DIR/Build/lagom-install")
CMAKE_ARGS+=("-DSERENITY_CACHE_DIR=${LADYBIRD_SOURCE_DIR}/Build/caches") CMAKE_ARGS+=("-DSERENITY_CACHE_DIR=${LADYBIRD_SOURCE_DIR}/Build/caches")
export PATH="$LADYBIRD_SOURCE_DIR/Toolchain/Local/cmake/bin":$PATH export PATH="$LADYBIRD_SOURCE_DIR/Toolchain/Local/cmake/bin":$PATH
@ -113,12 +103,6 @@ run_tests() {
} }
build_target() { 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 # Get either the environment MAKEJOBS or all processors via CMake
[ -z "$MAKEJOBS" ] && MAKEJOBS=$(cmake -P "$LADYBIRD_SOURCE_DIR/Meta/CMake/processor-count.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" die "Lagom executable can't be specified more than once"
fi fi
LAGOM_EXECUTABLE="$arg" 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 fi
done done
if [ "$PASS_ARG_TO_GDB" != "" ]; then if [ "$PASS_ARG_TO_GDB" != "" ]; then

View file

@ -11,7 +11,7 @@ then
fi 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)}" which WebDriver)}"
update_expectations_metadata=false update_expectations_metadata=false
remove_wpt_repository=false remove_wpt_repository=false