C: Difference between revisions

imported>Mic92
language server..
imported>Mic92
document overrideCC and wrapCCWith
Line 230: Line 230:
Tooling that provides autocompletion or refactoring support also needs to be aware of the environments variables
Tooling that provides autocompletion or refactoring support also needs to be aware of the environments variables
to find C/C++ header files. Nixpkgs adds wrapper to both language server [ccls](https://github.com/MaskRay/ccls) and [cquery](https://github.com/cquery-project/cquery) to extend the include path of these tools. [CCLS](https://github.com/MaskRay/ccls/wiki) also provides extensive documentation on how to setup a project/editors to make use of it.
to find C/C++ header files. Nixpkgs adds wrapper to both language server [ccls](https://github.com/MaskRay/ccls) and [cquery](https://github.com/cquery-project/cquery) to extend the include path of these tools. [CCLS](https://github.com/MaskRay/ccls/wiki) also provides extensive documentation on how to setup a project/editors to make use of it.
== Use a different compiler version ==
Adding a different c compiler to `buildInputs` in a nix expression will not change the default compiler
available in `$PATH`. Instead nixpkgs provides a `overrideCC` function:
<syntaxHighlight lang=nix>
(overrideCC stdenv gcc8).mkDerivation {
  name = "env";
}
</syntaxHighlight>
<syntaxHighlight lang=console>
$ nix-shell --command 'gcc --version'
gcc (GCC) 8.3.0
</syntaxHighlight>
== Get a compiler without default libc ==
By default cc wrapper will include the libc headers (i.e. glibc). This can break for example projects that would bring their own libc (i.e. musl). However it is possible to get a cc wrapper that would include all build inputs without adding glibc:
<syntaxHighlight lang=nix>
let
  gcc_nolibc = wrapCCWith {
    cc = gcc.cc;
    bintools = wrapBintoolsWith {
      bintools = binutils-unwrapped;
      libc = null;
    };
  };
in (overrideCC stdenv gcc_nolibc).mkDerivation {
  name = "env";
}
</syntaxHighlight>