nkoturovic / mini_compile_commands

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Mini Compile Commands

Mini compile commands instruments the compiler wrappers in nixpkgs to generate compile_commands.json files. Using a version of nixpkgs after this PR, it can be used in a shell.nix as follows:

with import <nixpkgs> {};
let mcc-env = (callPackage <this_repo> {}).wrap stdenv;
in (mkShell.override {stdenv = mcc-env;}) {
   buildInputs = [ cmake gtest ];
}

When the compiler is invoked, it will send a message to mini_compile_commands_server.py:

example.mp4

Mini Compile Commands and flakes

If your project is flake based, add mini-compile-commands = { url = github:danielbarter/mini_compile_commands; flake = false;}; to your inputs and mini-compile-commands as an argument to your outputs. Then the above development shell output would be specified as

devShell.x86_64-linux =
  with import nixpkgs { system = "x86_64-linux"; };
  let mcc-env = (callPackage mini-compile-commands {}).wrap stdenv;
  in (mkShell.override {stdenv = mcc-env;}) {
    buildInputs = [ cmake gtest ];
  };

Example

Mini compile commands can be used to generate a compile_commands.json for the linux kernel:

nix-shell -E 'with import <nixpkgs> {}; let mcc-env = (callPackage <this_repo> {}).wrap stdenv; in linux.override { stdenv = mcc-env; }'

As demonstrated in the above video, create two shells. In one, run mini_compile_commands_server.py compile_commands.json and in the other, run your build command.

Testing

There are tests for gcc and clang in tests/gcc and tests/clang respectively. In either of these directories, running nix-shell will generate a compile_commands.json. To test if things are working, open test.cc (make sure your editor can locate clangd) and try and jump into the iostream header.

About

License:GNU General Public License v3.0


Languages

Language:Nix 52.5%Language:Python 44.5%Language:C++ 3.0%