From 0578dda8e1c7159f65a33d9b88e020ecfebff1b4 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Fri, 18 Aug 2017 17:48:30 -0400 Subject: doc: Describe CC Wrapper in more detail The main motivation for this is to have something to google for LD=$CC. Eventually, this should probably be moved to another section, but we can deal with that later. --- doc/stdenv.xml | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) (limited to 'doc/stdenv.xml') diff --git a/doc/stdenv.xml b/doc/stdenv.xml index e637962fbb7d0..dac53bc2b8009 100644 --- a/doc/stdenv.xml +++ b/doc/stdenv.xml @@ -1,3 +1,4 @@ + @@ -1153,7 +1154,7 @@ makeWrapper $out/bin/foo $wrapperfile --prefix PATH : ${lib.makeBinPath [ hello - + substitute @@ -1312,7 +1313,7 @@ someVar=$(stripHash $name) - + wrapProgram @@ -1342,12 +1343,34 @@ someVar=$(stripHash $name) - GCC wrapper - Adds the include subdirectory - of each build input to the NIX_CFLAGS_COMPILE - environment variable, and the lib and - lib64 subdirectories to - NIX_LDFLAGS. + CC Wrapper + + + CC Wrapper wraps a C toolchain for a bunch of miscellaneous purposes. + Specifically, a C compiler (GCC or Clang), Binutils (or the CCTools + binutils mashup when targetting Darwin), and a C standard library (glibc or Darwin's libSystem) are all fed in, and dependency finding, hardening (see below), and purity checks for each are handled by CC Wrapper. + Packages typically depend on only CC Wrapper, instead of those 3 inputs directly. + + + Dependency finding is undoubtedly the main task of CC wrapper. + It is currently accomplished by collecting directories of host-platform dependencies (i.e. buildInputs and nativeBuildInputs) in environment variables. + CC wrapper's setup hook causes any include subdirectory of such a dependency to be added to NIX_CFLAGS_COMPILE, and any lib and lib64 subdirectories to NIX_LDFLAGS. + The setup hook itself contains some lengthy comments describing the exact convoluted mechanism by which this is accomplished. + + + A final task of the setup hook is defining a number of standard environment variables to tell build systems which executables full-fill which purpose. + They are defined to just be the base name of the tools, under the assumption that CC Wrapper's binaries will be on the path. + Firstly, this helps poorly-written packages, e.g. ones that look for just gcc when CC isn't defined yet clang is to be used. + Secondly, this helps packages not get confused when cross-compiling, in which case multiple CC wrappers may be simultaneous in use (targeting different platforms). + BUILD_- and TARGET_-prefixed versions of the normal environment variable are defined for the additional CC Wrappers, properly disambiguating them. + + + A problem with this final task is that CC Wrapper is honest and defines LD as ld. + Most packages, however, firstly use the C compiler for linking, secondly use LD anyways, defining it as the C compiler, and thirdly, only so define LD when it is undefined as a fallback. + This triple-threat means CC Wrapper will break those packages, as LD is already defined as the actually linker which the package won't override yet doesn't want to use. + The workaround is to define, just for the problematic package, LD as the C compiler. + A good way to do this would be preConfigure = "LD=$CC". + + -- cgit 1.4.1