clang, cc-wrapper: Move --gcc-toolchain logic into CC wrapper

Take 2, after #94582 had to be reverted.

This reverts commit ac03cfa3c5.
This commit is contained in:
John Ericson 2021-01-20 18:45:52 -05:00
parent a7a61998e9
commit 0710308402
11 changed files with 21 additions and 23 deletions

View File

@ -290,6 +290,17 @@ stdenv.mkDerivation {
echo "-L${gccForLibs.lib}/${targetPlatform.config}/lib" >> $out/nix-support/cc-ldflags
''
# TODO We would like to connect this to `useGccForLibs`, but we cannot yet
# because `libcxxStdenv` on linux still needs this. Maybe someday we'll
# always set `useLLVM` on Darwin, and maybe also break down `useLLVM` into
# fine-grained use flags (libgcc vs compiler-rt, ld.lld vs legacy, libc++
# vs libstdc++, etc.) since Darwin isn't `useLLVM` on all counts. (See
# https://clang.llvm.org/docs/Toolchain.html for all the axes one might
# break `useLLVM` into.)
+ optionalString (isClang && gccForLibs != null && targetPlatform.isLinux && !(stdenv.targetPlatform.useLLVM or false)) ''
echo "--gcc-toolchain=${gccForLibs}" >> $out/nix-support/cc-cflags
''
##
## General libc support
##

View File

@ -26,8 +26,6 @@ let
ln -s "${targetLlvmLibraries.compiler-rt.out}/lib" "$rsrc/lib"
ln -s "${targetLlvmLibraries.compiler-rt.out}/share" "$rsrc/share"
echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags
'' + lib.optionalString (stdenv.targetPlatform.isLinux && !(stdenv.targetPlatform.useLLVM or false)) ''
echo "--gcc-toolchain=${gccForLibs}" >> $out/nix-support/cc-cflags
'';
in {

View File

@ -28,8 +28,6 @@ let
ln -s "${targetLlvmLibraries.compiler-rt.out}/lib" "$rsrc/lib"
ln -s "${targetLlvmLibraries.compiler-rt.out}/share" "$rsrc/share"
echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags
'' + lib.optionalString (stdenv.targetPlatform.isLinux && !(stdenv.targetPlatform.useLLVM or false)) ''
echo "--gcc-toolchain=${gccForLibs}" >> $out/nix-support/cc-cflags
'';
in {

View File

@ -25,8 +25,6 @@ let
ln -s "${cc}/lib/clang/${release_version}/include" "$rsrc"
ln -s "${targetLlvmLibraries.compiler-rt.out}/lib" "$rsrc/lib"
echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags
'' + lib.optionalString (stdenv.targetPlatform.isLinux && !(stdenv.targetPlatform.useLLVM or false)) ''
echo "--gcc-toolchain=${gccForLibs}" >> $out/nix-support/cc-cflags
'';
in {

View File

@ -25,8 +25,6 @@ let
ln -s "${cc}/lib/clang/${release_version}/include" "$rsrc"
ln -s "${targetLlvmLibraries.compiler-rt.out}/lib" "$rsrc/lib"
echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags
'' + lib.optionalString (stdenv.targetPlatform.isLinux && !(stdenv.targetPlatform.useLLVM or false)) ''
echo "--gcc-toolchain=${gccForLibs}" >> $out/nix-support/cc-cflags
'';
in {

View File

@ -25,8 +25,6 @@ let
ln -s "${cc}/lib/clang/${release_version}/include" "$rsrc"
ln -s "${targetLlvmLibraries.compiler-rt.out}/lib" "$rsrc/lib"
echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags
'' + lib.optionalString (stdenv.targetPlatform.isLinux && !(stdenv.targetPlatform.useLLVM or false)) ''
echo "--gcc-toolchain=${gccForLibs}" >> $out/nix-support/cc-cflags
'';
in {

View File

@ -25,8 +25,6 @@ let
ln -s "${cc}/lib/clang/${release_version}/include" "$rsrc"
ln -s "${targetLlvmLibraries.compiler-rt.out}/lib" "$rsrc/lib"
echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags
'' + lib.optionalString (stdenv.targetPlatform.isLinux && !(stdenv.targetPlatform.useLLVM or false)) ''
echo "--gcc-toolchain=${gccForLibs}" >> $out/nix-support/cc-cflags
'';
in {

View File

@ -25,8 +25,6 @@ let
ln -s "${cc}/lib/clang/${release_version}/include" "$rsrc"
ln -s "${targetLlvmLibraries.compiler-rt.out}/lib" "$rsrc/lib"
echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags
'' + lib.optionalString (stdenv.targetPlatform.isLinux && !(stdenv.targetPlatform.useLLVM or false)) ''
echo "--gcc-toolchain=${gccForLibs}" >> $out/nix-support/cc-cflags
'';
in {

View File

@ -13,7 +13,12 @@ let
chmod u+rw -R $out/lib
cp -r ${basegcc.libc}/lib/* $(ls -d $out/lib/gcc/*/*)
'';
gcc_multi_sysroot = runCommand "gcc-multi-sysroot" {} ''
gcc_multi_sysroot = runCommand "gcc-multi-sysroot" {
passthru = {
inherit (gcc64) version;
lib = gcc_multi_sysroot;
};
} ''
mkdir -p $out/lib/gcc
ln -s ${combine gcc64}/lib/gcc/* $out/lib/gcc/
@ -32,17 +37,16 @@ let
'';
clangMulti = clang.override {
# Only used for providing expected structure re:dynamic linkers, AFAIK
# Most of the magic is done by setting the --gcc-toolchain option below
# Only used for providing expected structure re:dynamic linkers, AFAIK Most
# of the magic is done by setting the --gcc-toolchain option via
# `gccForLibs`.
libc = gcc_multi_sysroot;
bintools = clang.bintools.override {
libc = gcc_multi_sysroot;
};
extraBuildCommands = ''
sed -e '$a --gcc-toolchain=${gcc_multi_sysroot}' -i $out/nix-support/libc-cflags
'';
gccForLibs = gcc_multi_sysroot;
};
in clangMulti

View File

@ -17,7 +17,6 @@ in rec {
mkdir "$rsrc"
ln -s "${cc}/lib/clang/$clang_version/include" "$rsrc"
echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags
echo "--gcc-toolchain=${stdenv.cc.cc}" >> $out/nix-support/cc-cflags
echo "-Wno-unused-command-line-argument" >> $out/nix-support/cc-cflags
rm $out/nix-support/add-hardening.sh
touch $out/nix-support/add-hardening.sh

View File

@ -9498,8 +9498,6 @@ in
mkdir -p "$rsrc/lib"
ln -s "${cc}/lib" "$rsrc/include"
echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags
'' + lib.optionalString (stdenv.targetPlatform.isLinux && !(stdenv.targetPlatform.useLLVM or false)) ''
echo "--gcc-toolchain=${gccForLibs}" >> $out/nix-support/cc-cflags
'';
};