Skip to content

Commit

Permalink
Meta+Documentation: Switch default build dir to Build/Ladybird
Browse files Browse the repository at this point in the history
Also prefer using the new top-level CMakeLists.txt
  • Loading branch information
ADKaster committed Jun 4, 2024
1 parent e8b6de5 commit c6e9f0e
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 122 deletions.
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
*.cflags
*.cxxflags
*.autosave
Meta/Lagom/build
Build
build*
Build*
Toolchain/Tarballs
Toolchain/Build
Toolchain/Local
Expand All @@ -23,8 +23,6 @@ compile_commands.json
.idea/
cmake-build-debug/
output/
run-local.sh
sync-local.sh
.vim/
.exrc
.helix/
Expand Down
51 changes: 3 additions & 48 deletions .ycm_extra_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,42 +32,12 @@
# For more information, please refer to <http://unlicense.org/>

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):
Expand All @@ -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
Expand All @@ -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
}
4 changes: 2 additions & 2 deletions Documentation/AdvancedBuildInstructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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 lint-shell-scripts`: Checks style of shell scripts in the source tree with shellcheck
Expand Down Expand Up @@ -58,7 +58,7 @@ For example, boolean options such as `ENABLE_<setting>` or `<component_name>_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
Expand Down
21 changes: 5 additions & 16 deletions Documentation/BuildInstructionsLadybird.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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=<suitable compiler> -DCMAKE_C_COMPILER=<matching c compiler>
cmake --build Build/ladybird
ninja -C Build/ladybird run
Expand Down Expand Up @@ -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.
Expand All @@ -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
```
Expand All @@ -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
```
4 changes: 2 additions & 2 deletions Documentation/CLionConfiguration.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ 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`:
```
-DSERENITY_CACHE_DIR=$CMakeProjectDir$/Build/caches
-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.

Expand Down
7 changes: 2 additions & 5 deletions Documentation/EmacsConfiguration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions Documentation/HelixConfiguration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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!
2 changes: 1 addition & 1 deletion Documentation/NvimConfiguration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
(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
Expand Down
36 changes: 18 additions & 18 deletions Documentation/VSCodeConfiguration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -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",
Expand All @@ -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/"
}
}
],
Expand Down Expand Up @@ -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"
]
}
],
Expand Down Expand Up @@ -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": [
{
Expand Down Expand Up @@ -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": [
{
Expand All @@ -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"
]
}
]
Expand Down
Loading

0 comments on commit c6e9f0e

Please sign in to comment.