Skip to content

Create compile-commands.json with Make#10269

Merged
thufschmitt merged 2 commits intoNixOS:masterfrom
andreabedini:make-compile-commands
Mar 21, 2024
Merged

Create compile-commands.json with Make#10269
thufschmitt merged 2 commits intoNixOS:masterfrom
andreabedini:make-compile-commands

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.

@andreabedini andreabedini requested a review from edolstra as a code owner March 19, 2024 07:56
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

@andreabedini andreabedini force-pushed the make-compile-commands branch from 543b343 to 83fc988 Compare March 21, 2024 07:56
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 enabled auto-merge March 21, 2024 15:55
@thufschmitt thufschmitt merged commit 57d9d0d into NixOS:master Mar 21, 2024
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.

3 participants