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

pull Sjors wants to merge 2 commits into bitcoin-core:master from Sjors:2026/07/export-compile-commands changing 2 files +11 −0
  1. Sjors commented at 11:52 AM on July 21, 2026: member

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

    Before: <img width="1025" height="426" alt="before" src="https://github.com/user-attachments/assets/3b9881fd-7be2-49de-9180-b8517dda0394" />

    After: <img width="911" height="427" alt="after" src="https://github.com/user-attachments/assets/42bac960-3d31-4bf4-9d42-7d92b72c13a9" />

    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
  2. cmake: Export compile_commands.json by default in standalone builds
    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>
    a92b068742
  3. Add .clangd pointing clangd at the build/ compile database
    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>
    fab9081bc3
  4. DrahtBot commented at 11:52 AM on July 21, 2026: none

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

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

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  5. ryanofsky commented at 1:41 PM on July 30, 2026: collaborator

    Code review fab9081bc3a1ef37c521528b466df7d5d1c9df8c.

    I think we should do something to make this less cumbersome, but I'm not sure about this approach, especially since it hardcodes the name of the build directory. The simplest thing to do would be to suggest running cmake -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON && ln -sf build/compile_commands.json . in documentation to set this up.

    But I've also been thinking it would be good to have a clearer separation in the cmake build between essential features that can't be provided externally and convenience features and maybe just enable the convenience features in a dev mode present like Bitcoin core. Sketch of this idea is: https://github.com/bitcoin-core/libmultiprocess/compare/master...ryanofsky:libmultiprocess:pr/extras (branch) which would automatically set up this editor support if dev mode is enabled while avoiding a hardcoded .clangd file, and simplifying the main cmake file instead of complicating it.

  6. Sjors commented at 12:20 PM on July 31, 2026: member

    Closing in favor of your suggested approach. I won't have time in the next two weeks to implement that though.

  7. Sjors closed this on Jul 31, 2026


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin-core/libmultiprocess. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-08-05 20:30 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me