Skip to content

Export compile_commands.json in standalone builds (by default) #314

Open
Sjors wants to merge 2 commits into
bitcoin-core:masterfrom
Sjors:2026/07/export-compile-commands
Open

Export compile_commands.json in standalone builds (by default) #314
Sjors wants to merge 2 commits into
bitcoin-core:masterfrom
Sjors:2026/07/export-compile-commands

Conversation

@Sjors

@Sjors Sjors commented Jul 21, 2026

Copy link
Copy Markdown
Member

This makes the default build configuration play nicely with code editors. E.g. with Zed, looking at spawn_argv in #231:

Before:
before

After:
after

One downside of this approach is that it only just works(tm) on the build directory.

There are several alternative approaches:

  1. Update documentation to recommend:
cmake -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
ln -sf build/compile_commands.json .
  1. Have cmake add a symlink to the source dir
  2. Add a (dev) cmake preset

Sjors and others added 2 commits July 21, 2026 13:48
Makes clangd and other tooling work out of the box after configuring.
Only applied when libmultiprocess is the top-level project, so it does
not opt targets into a parent project's compile database when built as
a subtree.

An explicit -DCMAKE_EXPORT_COMPILE_COMMANDS=OFF or environment variable
setting still takes precedence: project() copies the environment value
into the cache, leaving the cache entry empty when neither is set, so
the default only applies to an empty value.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
clangd only searches ancestor directories of a source file for
compile_commands.json, so even with CMAKE_EXPORT_COMPILE_COMMANDS
enabled it would not find the database in the build directory without
a symlink in the source directory. Point it at the build/ directory
suggested by doc/install.md and doc/usage.md.

Developers using a differently named build directory can override this
with clangd's --compile-commands-dir flag or a personal clangd user
config, which takes precedence over this file.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
@DrahtBot

DrahtBot commented Jul 21, 2026

Copy link
Copy Markdown

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline and AI policy for information on the review process.
A summary of reviews will appear here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants