about summary refs log tree commit diff
path: root/pkgs/build-support
diff options
context:
space:
mode:
authorJohn Ericson <Ericson2314@Yahoo.com>2017-05-22 20:59:39 -0400
committerJohn Ericson <John.Ericson@Obsidian.Systems>2017-06-22 17:52:28 -0400
commit0f0383394d006ae1c67e2815d5b4a8e4c7788de0 (patch)
tree409abdb7a7d2e70a6492b53f888c67ee4e0c2cf9 /pkgs/build-support
parent04a3cad968fccc11fd07997cd5b496f4c482aae7 (diff)
downloadnixlib-0f0383394d006ae1c67e2815d5b4a8e4c7788de0.tar
nixlib-0f0383394d006ae1c67e2815d5b4a8e4c7788de0.tar.gz
nixlib-0f0383394d006ae1c67e2815d5b4a8e4c7788de0.tar.bz2
nixlib-0f0383394d006ae1c67e2815d5b4a8e4c7788de0.tar.lz
nixlib-0f0383394d006ae1c67e2815d5b4a8e4c7788de0.tar.xz
nixlib-0f0383394d006ae1c67e2815d5b4a8e4c7788de0.tar.zst
nixlib-0f0383394d006ae1c67e2815d5b4a8e4c7788de0.zip
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.
Diffstat (limited to 'pkgs/build-support')
-rw-r--r--pkgs/build-support/cc-wrapper/default.nix14
1 files changed, 10 insertions, 4 deletions
diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix
index 86314c5130fb..ffb1fdc139df 100644
--- a/pkgs/build-support/cc-wrapper/default.nix
+++ b/pkgs/build-support/cc-wrapper/default.nix
@@ -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)}))
     '';
   };