cc-wrapper: Salt environment variables with LLVM triples

We now (on cross) require per-target flag interposition by putting the
triple in the names of the relevant environment variables, e.g:

export NIX_arm_unknown_linux_gnu_CFLAGS_COMPILE=...

The wrapper also has a `infixSalt` attribute (and "_" prefixed and
suffixed variants) to assist downstream packages.

Note how that the dashes are replaced to keep the identifier valid.
Using names like this allows us to keep the settings for different
compilers seperate.

I think it might be even better to use names like `NIX_{BUILD,HOST}...`
using the platform's role rather than the platform itself, but this
would be more work as the previous stages' tools would have to be re-
wrapped to take on their new role. I therefore didn't do this for now,
but that route should be thoroughly explored in the future.
This commit is contained in:
John Ericson 2017-05-22 20:59:39 -04:00 committed by John Ericson
parent 04a3cad968
commit 0f0383394d

View File

@ -45,6 +45,12 @@ let
default_cxx_stdlib_compile=optionalString (targetPlatform.isLinux && !(cc.isGNU or false))
"-isystem $(echo -n ${cc.gcc}/include/c++/*) -isystem $(echo -n ${cc.gcc}/include/c++/*)/$(${cc.gcc}/bin/gcc -dumpmachine)";
dashlessTarget = stdenv.lib.replaceStrings ["-"] ["_"] targetPlatform.config;
# TODO(@Ericson2314) Make unconditional
infixSalt = stdenv.lib.optionalString (targetPlatform != hostPlatform) dashlessTarget;
infixSalt_ = stdenv.lib.optionalString (targetPlatform != hostPlatform) (dashlessTarget + "_");
_infixSalt = stdenv.lib.optionalString (targetPlatform != hostPlatform) ("_" + dashlessTarget);
in
stdenv.mkDerivation {
@ -60,17 +66,17 @@ stdenv.mkDerivation {
passthru = {
inherit libc nativeTools nativeLibc nativePrefix isGNU isClang default_cxx_stdlib_compile
prefix;
prefix infixSalt infixSalt_ _infixSalt;
emacsBufferSetup = pkgs: ''
; We should handle propagation here too
(mapc (lambda (arg)
(when (file-directory-p (concat arg "/include"))
(setenv "NIX_CFLAGS_COMPILE" (concat (getenv "NIX_CFLAGS_COMPILE") " -isystem " arg "/include")))
(setenv "NIX_${infixSalt_}CFLAGS_COMPILE" (concat (getenv "NIX_${infixSalt_}CFLAGS_COMPILE") " -isystem " arg "/include")))
(when (file-directory-p (concat arg "/lib"))
(setenv "NIX_LDFLAGS" (concat (getenv "NIX_LDFLAGS") " -L" arg "/lib")))
(setenv "NIX_${infixSalt_}LDFLAGS" (concat (getenv "NIX_${infixSalt_}LDFLAGS") " -L" arg "/lib")))
(when (file-directory-p (concat arg "/lib64"))
(setenv "NIX_LDFLAGS" (concat (getenv "NIX_LDFLAGS") " -L" arg "/lib64")))) '(${concatStringsSep " " (map (pkg: "\"${pkg}\"") pkgs)}))
(setenv "NIX_${infixSalt_}LDFLAGS" (concat (getenv "NIX_${infixSalt_}LDFLAGS") " -L" arg "/lib64")))) '(${concatStringsSep " " (map (pkg: "\"${pkg}\"") pkgs)}))
'';
};