Giter VIP home page Giter VIP logo

mini_compile_commands's Introduction

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.

mini_compile_commands's People

Contributors

danielbarter avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.