Skip to content

Commit

Permalink
Merge pull request #91293 from Ericson2314/cxx-wrapper-debt-part-2
Browse files Browse the repository at this point in the history
treewide: Get rid of `cc.gcc`
  • Loading branch information
Ericson2314 committed Aug 3, 2020
2 parents c0b06ef + 92f96f4 commit b5f7ed6
Show file tree
Hide file tree
Showing 17 changed files with 78 additions and 86 deletions.
18 changes: 10 additions & 8 deletions pkgs/build-support/cc-wrapper/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
{ name ? ""
, stdenvNoCC
, cc ? null, libc ? null, bintools, coreutils ? null, shell ? stdenvNoCC.shell
, gccForLibs ? null
, zlib ? null
, nativeTools, noLibc ? false, nativeLibc, nativePrefix ? ""
, propagateDoc ? cc != null && cc ? man
Expand Down Expand Up @@ -262,11 +263,11 @@ stdenv.mkDerivation {
##
## GCC libs for non-GCC support
##
+ optionalString (isClang && libcxx == null && cc ? gcc) ''
+ optionalString (isClang && libcxx == null && !(stdenv.targetPlatform.useLLVM or false) && gccForLibs != null) ''
echo "-B${cc.gcc}/lib/gcc/${targetPlatform.config}/${cc.gcc.version}" >> $out/nix-support/cc-cflags
echo "-L${cc.gcc}/lib/gcc/${targetPlatform.config}/${cc.gcc.version}" >> $out/nix-support/cc-ldflags
echo "-L${cc.gcc.lib}/${targetPlatform.config}/lib" >> $out/nix-support/cc-ldflags
echo "-B${gccForLibs}/lib/gcc/${targetPlatform.config}/${gccForLibs.version}" >> $out/nix-support/cc-cflags
echo "-L${gccForLibs}/lib/gcc/${targetPlatform.config}/${gccForLibs.version}" >> $out/nix-support/cc-ldflags
echo "-L${gccForLibs.lib}/${targetPlatform.config}/lib" >> $out/nix-support/cc-ldflags
''

##
Expand Down Expand Up @@ -306,14 +307,15 @@ stdenv.mkDerivation {

# We have a libc++ directly, we have one via "smuggled" GCC, or we have one
# bundled with the C compiler because it is GCC
+ optionalString (libcxx != null || cc.gcc.langCC or false || (isGNU && cc.langCC or false)) ''
+ optionalString (libcxx != null || (isClang && !(stdenv.targetPlatform.useLLVM or false) && gccForLibs.langCC or false) || (isGNU && cc.langCC or false)) ''
touch "$out/nix-support/libcxx-cxxflags"
touch "$out/nix-support/libcxx-ldflags"
'' + optionalString (libcxx == null && cc ? gcc) ''
for dir in ${cc.gcc}/include/c++/*; do
''
+ optionalString (libcxx == null && (isClang && !(stdenv.targetPlatform.useLLVM or false) && gccForLibs.langCC or false)) ''
for dir in ${gccForLibs}/include/c++/*; do
echo "-isystem $dir" >> $out/nix-support/libcxx-cxxflags
done
for dir in ${cc.gcc}/include/c++/*/${targetPlatform.config}; do
for dir in ${gccForLibs}/include/c++/*/${targetPlatform.config}; do
echo "-isystem $dir" >> $out/nix-support/libcxx-cxxflags
done
''
Expand Down
2 changes: 0 additions & 2 deletions pkgs/development/compilers/computecpp/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ stdenv.mkDerivation rec {

passthru = {
isClang = true;
} // stdenv.lib.optionalAttrs (stdenv.targetPlatform.isLinux || (stdenv.cc.isGNU && stdenv.cc.cc ? gcc)) {
gcc = if stdenv.cc.isGNU then stdenv.cc.cc else stdenv.cc.cc.gcc;
};

meta = with stdenv.lib; {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
{ emscriptenVersion, stdenv, fetchFromGitHub, cmake, python, gtest, ... }:
{ emscriptenVersion, stdenv, fetchFromGitHub, cmake, python, gtest, gccForLibs, ... }:

let
rev = emscriptenVersion;
haveGcc = stdenv.cc.isGNU || stdenv.cc.cc ? gcc;
gcc = if stdenv.cc.isGNU then stdenv.cc.cc else stdenv.cc.cc.gcc;
in
stdenv.mkDerivation rec {
name = "emscripten-fastcomp-${rev}";
Expand Down Expand Up @@ -35,16 +33,14 @@ stdenv.mkDerivation rec {
#"-DLLVM_CONFIG=${llvm}/bin/llvm-config"
"-DLLVM_BUILD_TESTS=ON"
"-DCLANG_INCLUDE_TESTS=ON"
] ++ (stdenv.lib.optional (stdenv.isLinux && haveGcc)
] ++ (stdenv.lib.optional stdenv.isLinux
# necessary for clang to find crtend.o
"-DGCC_INSTALL_PREFIX=${gcc}"
"-DGCC_INSTALL_PREFIX=${gccForLibs}"
);
enableParallelBuilding = true;

passthru = {
isClang = true;
} // stdenv.lib.optionalAttrs haveGcc {
inherit gcc;
};

meta = with stdenv.lib; {
Expand Down
2 changes: 0 additions & 2 deletions pkgs/development/compilers/llvm/10/clang/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ let
passthru = {
isClang = true;
inherit llvm;
} // stdenv.lib.optionalAttrs (stdenv.targetPlatform.isLinux || (stdenv.cc.isGNU && stdenv.cc.cc ? gcc)) {
gcc = if stdenv.cc.isGNU then stdenv.cc.cc else stdenv.cc.cc.gcc;
};

meta = {
Expand Down
10 changes: 6 additions & 4 deletions pkgs/development/compilers/llvm/10/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{ lowPrio, newScope, pkgs, stdenv, cmake
{ lowPrio, newScope, pkgs, stdenv, cmake, gccForLibs
, libxml2, python3, isl, fetchurl, overrideCC, wrapCCWith, wrapBintoolsWith
, buildPackages
, buildLlvmTools # tools, but from the previous stage, for cross
, targetLlvmLibraries # libraries, but from the next stage, for cross
}:
Expand All @@ -24,8 +25,8 @@ 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
'' + stdenv.lib.optionalString (stdenv.targetPlatform.isLinux && tools.clang-unwrapped ? gcc && !(stdenv.targetPlatform.useLLVM or false)) ''
echo "--gcc-toolchain=${tools.clang-unwrapped.gcc}" >> $out/nix-support/cc-cflags
'' + stdenv.lib.optionalString (stdenv.targetPlatform.isLinux && !(stdenv.targetPlatform.useLLVM or false)) ''
echo "--gcc-toolchain=${gccForLibs}" >> $out/nix-support/cc-cflags
'';
in {

Expand Down Expand Up @@ -59,7 +60,8 @@ let

libstdcxxClang = wrapCCWith rec {
cc = tools.clang-unwrapped;
libcxx = null; # libstdcxx is smuggled in with clang.gcc
# libstdcxx is taken from gcc in an ad-hoc way in cc-wrapper.
libcxx = null;
extraPackages = [
targetLlvmLibraries.compiler-rt
];
Expand Down
3 changes: 0 additions & 3 deletions pkgs/development/compilers/llvm/5/clang/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
}:

let
gcc = if stdenv.cc.isGNU then stdenv.cc.cc else stdenv.cc.cc.gcc;
self = stdenv.mkDerivation ({
pname = "clang";
inherit version;
Expand Down Expand Up @@ -78,8 +77,6 @@ let
passthru = {
isClang = true;
inherit llvm;
} // stdenv.lib.optionalAttrs stdenv.isLinux {
inherit gcc;
};

meta = {
Expand Down
10 changes: 6 additions & 4 deletions pkgs/development/compilers/llvm/5/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{ lowPrio, newScope, pkgs, stdenv, cmake
{ lowPrio, newScope, pkgs, stdenv, cmake, gccForLibs
, libxml2, python3, isl, fetchurl, overrideCC, wrapCCWith
, buildPackages
, buildLlvmTools # tools, but from the previous stage, for cross
, targetLlvmLibraries # libraries, but from the next stage, for cross
}:
Expand All @@ -24,8 +25,8 @@ 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
'' + stdenv.lib.optionalString (stdenv.targetPlatform.isLinux && tools.clang-unwrapped ? gcc && !(stdenv.targetPlatform.useLLVM or false)) ''
echo "--gcc-toolchain=${tools.clang-unwrapped.gcc}" >> $out/nix-support/cc-cflags
'' + stdenv.lib.optionalString (stdenv.targetPlatform.isLinux && !(stdenv.targetPlatform.useLLVM or false)) ''
echo "--gcc-toolchain=${gccForLibs}" >> $out/nix-support/cc-cflags
'';
in {

Expand All @@ -51,7 +52,8 @@ let

libstdcxxClang = wrapCCWith rec {
cc = tools.clang-unwrapped;
libcxx = null; # libstdcxx is smuggled in with clang.gcc
# libstdcxx is taken from gcc in an ad-hoc way in cc-wrapper.
libcxx = null;
extraPackages = [
targetLlvmLibraries.compiler-rt
];
Expand Down
3 changes: 0 additions & 3 deletions pkgs/development/compilers/llvm/6/clang/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
}:

let
gcc = if stdenv.cc.isGNU then stdenv.cc.cc else stdenv.cc.cc.gcc;
self = stdenv.mkDerivation ({
pname = "clang";
inherit version;
Expand Down Expand Up @@ -78,8 +77,6 @@ let
passthru = {
isClang = true;
inherit llvm;
} // stdenv.lib.optionalAttrs stdenv.targetPlatform.isLinux {
inherit gcc;
};

meta = {
Expand Down
10 changes: 6 additions & 4 deletions pkgs/development/compilers/llvm/6/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{ lowPrio, newScope, pkgs, stdenv, cmake
{ lowPrio, newScope, pkgs, stdenv, cmake, gccForLibs
, libxml2, python3, isl, fetchurl, overrideCC, wrapCCWith
, buildPackages
, buildLlvmTools # tools, but from the previous stage, for cross
, targetLlvmLibraries # libraries, but from the next stage, for cross
}:
Expand All @@ -24,8 +25,8 @@ 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
'' + stdenv.lib.optionalString (stdenv.targetPlatform.isLinux && tools.clang-unwrapped ? gcc && !(stdenv.targetPlatform.useLLVM or false)) ''
echo "--gcc-toolchain=${tools.clang-unwrapped.gcc}" >> $out/nix-support/cc-cflags
'' + stdenv.lib.optionalString (stdenv.targetPlatform.isLinux && !(stdenv.targetPlatform.useLLVM or false)) ''
echo "--gcc-toolchain=${gccForLibs}" >> $out/nix-support/cc-cflags
'';
in {

Expand All @@ -51,7 +52,8 @@ let

libstdcxxClang = wrapCCWith rec {
cc = tools.clang-unwrapped;
libcxx = null; # libstdcxx is smuggled in with clang.gcc
# libstdcxx is taken from gcc in an ad-hoc way in cc-wrapper.
libcxx = null;
extraPackages = [
targetLlvmLibraries.compiler-rt
];
Expand Down
2 changes: 0 additions & 2 deletions pkgs/development/compilers/llvm/7/clang/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ let
passthru = {
isClang = true;
inherit llvm;
} // stdenv.lib.optionalAttrs (stdenv.targetPlatform.isLinux || (stdenv.cc.isGNU && stdenv.cc.cc ? gcc)) {
gcc = if stdenv.cc.isGNU then stdenv.cc.cc else stdenv.cc.cc.gcc;
};

meta = {
Expand Down
10 changes: 6 additions & 4 deletions pkgs/development/compilers/llvm/7/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{ lowPrio, newScope, pkgs, stdenv, cmake
{ lowPrio, newScope, pkgs, stdenv, cmake, gccForLibs
, libxml2, python3, isl, fetchurl, overrideCC, wrapCCWith, wrapBintoolsWith
, buildPackages
, buildLlvmTools # tools, but from the previous stage, for cross
, targetLlvmLibraries # libraries, but from the next stage, for cross
}:
Expand All @@ -24,8 +25,8 @@ 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
'' + stdenv.lib.optionalString (stdenv.targetPlatform.isLinux && tools.clang-unwrapped ? gcc && !(stdenv.targetPlatform.useLLVM or false)) ''
echo "--gcc-toolchain=${tools.clang-unwrapped.gcc}" >> $out/nix-support/cc-cflags
'' + stdenv.lib.optionalString (stdenv.targetPlatform.isLinux && !(stdenv.targetPlatform.useLLVM or false)) ''
echo "--gcc-toolchain=${gccForLibs}" >> $out/nix-support/cc-cflags
'';
in {

Expand Down Expand Up @@ -58,7 +59,8 @@ let

libstdcxxClang = wrapCCWith rec {
cc = tools.clang-unwrapped;
libcxx = null; # libstdcxx is smuggled in with clang.gcc
# libstdcxx is taken from gcc in an ad-hoc way in cc-wrapper.
libcxx = null;
extraPackages = [
targetLlvmLibraries.compiler-rt
];
Expand Down
2 changes: 0 additions & 2 deletions pkgs/development/compilers/llvm/8/clang/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ let
passthru = {
isClang = true;
inherit llvm;
} // stdenv.lib.optionalAttrs (stdenv.targetPlatform.isLinux || (stdenv.cc.isGNU && stdenv.cc.cc ? gcc)) {
gcc = if stdenv.cc.isGNU then stdenv.cc.cc else stdenv.cc.cc.gcc;
};

meta = {
Expand Down
10 changes: 6 additions & 4 deletions pkgs/development/compilers/llvm/8/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{ lowPrio, newScope, pkgs, stdenv, cmake
{ lowPrio, newScope, pkgs, stdenv, cmake, gccForLibs
, libxml2, python3, isl, fetchurl, overrideCC, wrapCCWith, wrapBintoolsWith
, buildPackages
, buildLlvmTools # tools, but from the previous stage, for cross
, targetLlvmLibraries # libraries, but from the next stage, for cross
}:
Expand All @@ -24,8 +25,8 @@ 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
'' + stdenv.lib.optionalString (stdenv.targetPlatform.isLinux && tools.clang-unwrapped ? gcc && !(stdenv.targetPlatform.useLLVM or false)) ''
echo "--gcc-toolchain=${tools.clang-unwrapped.gcc}" >> $out/nix-support/cc-cflags
'' + stdenv.lib.optionalString (stdenv.targetPlatform.isLinux && !(stdenv.targetPlatform.useLLVM or false)) ''
echo "--gcc-toolchain=${gccForLibs}" >> $out/nix-support/cc-cflags
'';
in {

Expand Down Expand Up @@ -59,7 +60,8 @@ let

libstdcxxClang = wrapCCWith rec {
cc = tools.clang-unwrapped;
libcxx = null; # libstdcxx is smuggled in with clang.gcc
# libstdcxx is taken from gcc in an ad-hoc way in cc-wrapper.
libcxx = null;
extraPackages = [
targetLlvmLibraries.compiler-rt
];
Expand Down
2 changes: 0 additions & 2 deletions pkgs/development/compilers/llvm/9/clang/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ let
passthru = {
isClang = true;
inherit llvm;
} // stdenv.lib.optionalAttrs (stdenv.targetPlatform.isLinux || (stdenv.cc.isGNU && stdenv.cc.cc ? gcc)) {
gcc = if stdenv.cc.isGNU then stdenv.cc.cc else stdenv.cc.cc.gcc;
};

meta = {
Expand Down
10 changes: 6 additions & 4 deletions pkgs/development/compilers/llvm/9/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{ lowPrio, newScope, pkgs, stdenv, cmake
{ lowPrio, newScope, pkgs, stdenv, cmake, gccForLibs
, libxml2, python3, isl, fetchurl, overrideCC, wrapCCWith, wrapBintoolsWith
, buildPackages
, buildLlvmTools # tools, but from the previous stage, for cross
, targetLlvmLibraries # libraries, but from the next stage, for cross
}:
Expand All @@ -24,8 +25,8 @@ 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
'' + stdenv.lib.optionalString (stdenv.targetPlatform.isLinux && tools.clang-unwrapped ? gcc && !(stdenv.targetPlatform.useLLVM or false)) ''
echo "--gcc-toolchain=${tools.clang-unwrapped.gcc}" >> $out/nix-support/cc-cflags
'' + stdenv.lib.optionalString (stdenv.targetPlatform.isLinux && !(stdenv.targetPlatform.useLLVM or false)) ''
echo "--gcc-toolchain=${gccForLibs}" >> $out/nix-support/cc-cflags
'';
in {

Expand Down Expand Up @@ -59,7 +60,8 @@ let

libstdcxxClang = wrapCCWith rec {
cc = tools.clang-unwrapped;
libcxx = null; # libstdcxx is smuggled in with clang.gcc
# libstdcxx is taken from gcc in an ad-hoc way in cc-wrapper.
libcxx = null;
extraPackages = [
targetLlvmLibraries.compiler-rt
];
Expand Down
7 changes: 4 additions & 3 deletions pkgs/development/compilers/swift/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
, cmake
, coreutils
, glibc
, gccForLibs
, which
, perl
, libedit
Expand Down Expand Up @@ -121,7 +122,7 @@ let
cmakeFlags = [
"-DGLIBC_INCLUDE_PATH=${stdenv.cc.libc.dev}/include"
"-DC_INCLUDE_DIRS=${stdenv.lib.makeSearchPathOutput "dev" "include" devInputs}:${libxml2.dev}/include/libxml2"
"-DGCC_INSTALL_PREFIX=${clang.cc.gcc}"
"-DGCC_INSTALL_PREFIX=${gccForLibs}"
];

in
Expand Down Expand Up @@ -199,7 +200,7 @@ stdenv.mkDerivation {
substituteInPlace swift/stdlib/public/Platform/CMakeLists.txt \
--replace '/usr/include' "${stdenv.cc.libc.dev}/include"
substituteInPlace swift/utils/build-script-impl \
--replace '/usr/include/c++' "${clang.cc.gcc}/include/c++"
--replace '/usr/include/c++' "${gccForLibs}/include/c++"
patch -p1 -d swift -i ${./patches/glibc-arch-headers.patch}
patch -p1 -d swift -i ${./patches/0001-build-presets-linux-don-t-require-using-Ninja.patch}
patch -p1 -d swift -i ${./patches/0002-build-presets-linux-allow-custom-install-prefix.patch}
Expand Down Expand Up @@ -264,7 +265,7 @@ stdenv.mkDerivation {
export NIX_CFLAGS_COMPILE="$(< $NIX_CC/nix-support/libcxx-cxxflags) $NIX_CFLAGS_COMPILE"
# During the Swift build, a full local LLVM build is performed and the resulting clang is invoked.
# This compiler is not using the Nix wrappers, so it needs some help to find things.
export NIX_LDFLAGS_BEFORE="-rpath ${clang.cc.gcc.lib}/lib -L${clang.cc.gcc.lib}/lib $NIX_LDFLAGS_BEFORE"
export NIX_LDFLAGS_BEFORE="-rpath ${gccForLibs.lib}/lib -L${gccForLibs.lib}/lib $NIX_LDFLAGS_BEFORE"
# However, we want to use the wrapped compiler whenever possible.
export CC="${clang}/bin/clang"
Expand Down
Loading

0 comments on commit b5f7ed6

Please sign in to comment.