Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create compile-commands.json with Make #10269

Merged
merged 2 commits into from Mar 21, 2024

Conversation

andreabedini
Copy link
Contributor

Motivation

The language server clangd needs to know the build flags which it reads from a file compile_commands.json ("JSON Compilation Database").

The contributing section of the manual suggests to create this file with

make clean && bear -- make -j$NIX_BUILD_CORES default check install

This works but I find it a little unsatisfactory because of two reasons:

  1. it requires a full build and a full re-build if anything changes (since bear does not do incremental updates, rebuilding a single file will result in a single file in compile_commands.json.
  2. our build system already knows exactly the flags we pass to the compiler so there is no reason to go the roundabout way.

Context

This PR adds to build system a target to create the compile_commands.json file without any unnecessary building. I tried to follow the patterns in the existing makefiles.

Priorities and Process

Add 馃憤 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

Copy link
Member

@thufschmitt thufschmitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooooh that is great!

Tried it locally, and it works like a charm (and generates a compilation database that's semantically equivalent to the one generated by bear).

Left a few minor comments on the form

scripts/mk-compile-commands.sh Outdated Show resolved Hide resolved
mk/patterns.mk Outdated Show resolved Hide resolved
mk/compilation-database.mk Outdated Show resolved Hide resolved
mk/lib.mk Outdated Show resolved Hide resolved
Copy link
Member

@thufschmitt thufschmitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the biggest QOL improvements for contributors (well, for me at least :D).

I've edited the hacking guide to mention it.

Thanks!

@thufschmitt thufschmitt merged commit 57d9d0d into NixOS:master Mar 21, 2024
8 checks passed
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.

None yet

3 participants