mesonbuild / mesonbuild/meson

meson seems to ignore custom targets when it generates compile_commands.json

Open
#9,840 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
6.6k
Forks
1.9k
Avg merge
2d 6h
Merged PRs (30d)
33

Description

**Describe the bug**

In https://github.com/systemd/systemd/pull/22135 it was mentioned that the "boot" part of systemd isn't present in `compile_commands.json` and has to be generated manually with `ninja -C ./build/ -t compdb`. Looking at
```
ninja -t compdb -x c_COMPILER_FOR_BUILD c_COMPILER_FOR_BUILD_RSP c_PCH_FOR_BUILD c_PCH_FOR_BUILD_RSP cpp_COMPILER_FOR_BUILD cpp_COMPILER_FOR_BUILD_RSP cpp_PCH_FOR_BUILD cpp_PCH_FOR_BUILD_RSP c_COMPILER c_COMPILER_RSP c_PCH c_PCH_RSP cpp_COMPILER cpp_COMPILER_RSP cpp_PCH cpp_PCH_RSP
```
it seems `CUSTOM_COMMAND` isn't listed among the "x" options.

Turns out the bpf part of systemd isn't included either so all the commands have to be generated as well to get something like
```
{
"directory": "/home/vagrant/systemd/build",
"command": "/usr/bin/clang -Wno-compare-distinct-pointer-types -O2 -target bpf -g -c -D__x86_64__ -I. -isystem /usr/include/x86_64-redhat-linux -idirafter /usr/include ../src/core/bpf/socket_bind/socket-bind.bpf.c -o src/core/bpf/socket_bind/socket-bind.bpf.unstripped.o",
"file": "../src/core/bpf/socket_bind/socket-bind.bpf.c",
"output": "src/core/bpf/socket_bind/socket-bind.bpf.unstripped.o"
},
{
"directory": "/home/vagrant/systemd/build",
"command": "/usr/bin/llvm-strip -g src/core/bpf/socket_bind/socket-bind.bpf.unstripped.o -o src/core/bpf/socket_bind/socket-bind.bpf.o",
"file": "src/core/bpf/socket_bind/socket-bind.bpf.unstripped.o",
"output": "src/core/bpf/socket_bind/socket-bind.bpf.o"
},
{
"directory": "/home/vagrant/systemd/build",
"command": "/home/vagrant/.local/bin/meson --internal exe --capture src/core/bpf/socket_bind/socket-bind.skel.h -- /usr/sbin/bpftool g s src/core/bpf/socket_bind/socket-bind.bpf.o",
"file": "src/core/bpf/socket_bind/socket-bind.bpf.o",
"output": "src/core/bpf/socket_bind/socket-bind.skel.h"
```

It seems the only way to get it around is to run `ninja -C ./build/ -t compdb` every time to get various tools like static analyzers relying on `compile_commands.json` to work properly.

Contributor guide

Open the contributing guide

Research direction

Reproduce the missing entries in compile_commands.json using the systemd examples, then compare Meson's generated database with ninja -C ./build/ -t compdb and inspect how CUSTOM_COMMAND entries are handled. Done means custom-target commands, including the BPF compile, strip, and bpftool steps shown, are represented without requiring a separate Ninja command.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.