From 89a0dd24143b3f604451ad2f31c27faf3e274b88 Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Fri, 29 Apr 2022 21:54:03 -0500 Subject: [PATCH 1/2] wrapCCWith: structured argument for wrapper flags Take a "nixSupport" argument that is an attrset of lists to append to "$out/nix-support/${name}" where name is the name of the attribute. This attrset is available from the passthru of the wrapped compiler. This is an alternative to imperatively issuing flags with extraBuildCommands and makes it possible to append or filter flags with an override. --- pkgs/build-support/cc-wrapper/default.nix | 9 ++++++++- pkgs/top-level/all-packages.nix | 3 ++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index 3738f628b18..ac6257220fd 100644 --- a/pkgs/build-support/cc-wrapper/default.nix +++ b/pkgs/build-support/cc-wrapper/default.nix @@ -14,6 +14,7 @@ , nativeTools, noLibc ? false, nativeLibc, nativePrefix ? "" , propagateDoc ? cc != null && cc ? man , extraTools ? [], extraPackages ? [], extraBuildCommands ? "" +, nixSupport ? {} , isGNU ? false, isClang ? cc.isClang or false, gnugrep ? null , buildPackages ? {} , libcxx ? null @@ -155,6 +156,8 @@ stdenv.mkDerivation { (setenv "NIX_CFLAGS_COMPILE_${suffixSalt}" (concat (getenv "NIX_CFLAGS_COMPILE_${suffixSalt}") " -isystem " arg "/include")))) '(${concatStringsSep " " (map (pkg: "\"${pkg}\"") pkgs)})) ''; + + inherit nixSupport; }; dontBuild = true; @@ -521,7 +524,11 @@ stdenv.mkDerivation { ## ## Extra custom steps ## - + extraBuildCommands; + + extraBuildCommands + + lib.strings.concatStringsSep "; " + (lib.attrsets.mapAttrsToList + (name: value: "echo ${toString value} >> $out/nix-support/${name}") + nixSupport); inherit expand-response-params; diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index e665d0bdc23..cc3872f7bf8 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -13932,6 +13932,7 @@ with pkgs; # default. libcxx ? null , extraPackages ? lib.optional (cc.isGNU or false && stdenv.targetPlatform.isMinGW) threadsCross + , nixSupport ? {} , ... } @ extraArgs: callPackage ../build-support/cc-wrapper (let self = { @@ -13943,7 +13944,7 @@ with pkgs; isGNU = cc.isGNU or false; isClang = cc.isClang or false; - inherit cc bintools libc libcxx extraPackages zlib; + inherit cc bintools libc libcxx extraPackages nixSupport zlib; } // extraArgs; in self); wrapCC = cc: wrapCCWith { From ff802de61e44ab70363d245c251ec2b427def6b5 Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Sat, 30 Apr 2022 21:17:08 -0500 Subject: [PATCH 2/2] llvm-14: use nixSupport arguments with wrapCCWith --- .../development/compilers/llvm/14/default.nix | 46 ++++++++++--------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/pkgs/development/compilers/llvm/14/default.nix b/pkgs/development/compilers/llvm/14/default.nix index 4e5e85684a2..b18b558d5b8 100644 --- a/pkgs/development/compilers/llvm/14/default.nix +++ b/pkgs/development/compilers/llvm/14/default.nix @@ -158,16 +158,17 @@ let ] ++ lib.optionals (!stdenv.targetPlatform.isWasm) [ targetLlvmLibraries.libunwind ]; - extraBuildCommands = '' - echo "-rtlib=compiler-rt -Wno-unused-command-line-argument" >> $out/nix-support/cc-cflags - echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags - '' + lib.optionalString (!stdenv.targetPlatform.isWasm) '' - echo "--unwindlib=libunwind" >> $out/nix-support/cc-cflags - '' + lib.optionalString (!stdenv.targetPlatform.isWasm && stdenv.targetPlatform.useLLVM or false) '' - echo "-lunwind" >> $out/nix-support/cc-ldflags - '' + lib.optionalString stdenv.targetPlatform.isWasm '' - echo "-fno-exceptions" >> $out/nix-support/cc-cflags - '' + mkExtraBuildCommands cc; + extraBuildCommands = mkExtraBuildCommands cc; + nixSupport.cc-cflags = + [ "-rtlib=compiler-rt" + "-Wno-unused-command-line-argument" + "-B${targetLlvmLibraries.compiler-rt}/lib" + ] + ++ lib.optional (!stdenv.targetPlatform.isWasm) "--unwindlib=libunwind" + ++ lib.optional + (!stdenv.targetPlatform.isWasm && stdenv.targetPlatform.useLLVM or false) + "-lunwind" + ++ lib.optional stdenv.targetPlatform.isWasm "-fno-exceptions"; }; clangNoLibcxx = wrapCCWith rec { @@ -177,11 +178,12 @@ let extraPackages = [ targetLlvmLibraries.compiler-rt ]; - extraBuildCommands = '' - echo "-rtlib=compiler-rt" >> $out/nix-support/cc-cflags - echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags - echo "-nostdlib++" >> $out/nix-support/cc-cflags - '' + mkExtraBuildCommands cc; + extraBuildCommands = mkExtraBuildCommands cc; + nixSupport.cc-cflags = [ + "-rtlib=compiler-rt" + "-B${targetLlvmLibraries.compiler-rt}/lib" + "-nostdlib++" + ]; }; clangNoLibc = wrapCCWith rec { @@ -191,10 +193,11 @@ let extraPackages = [ targetLlvmLibraries.compiler-rt ]; - extraBuildCommands = '' - echo "-rtlib=compiler-rt" >> $out/nix-support/cc-cflags - echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags - '' + mkExtraBuildCommands cc; + extraBuildCommands = mkExtraBuildCommands cc; + nixSupport.cc-cflags = [ + "-rtlib=compiler-rt" + "-B${targetLlvmLibraries.compiler-rt}/lib" + ]; }; clangNoCompilerRt = wrapCCWith rec { @@ -202,9 +205,8 @@ let libcxx = null; bintools = bintoolsNoLibc'; extraPackages = [ ]; - extraBuildCommands = '' - echo "-nostartfiles" >> $out/nix-support/cc-cflags - '' + mkExtraBuildCommands0 cc; + extraBuildCommands = mkExtraBuildCommands0 cc; + nixSupport.cc-cflags = [ "-nostartfiles" ]; }; clangNoCompilerRtWithLibc = wrapCCWith rec {