Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkgs/applications/networking/browsers/firefox/common.nix
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ stdenv.mkDerivation ({

BINDGEN_CFLAGS="$(< ${stdenv.cc}/nix-support/libc-cflags) \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should just expose all of these flags in the cc-wrapper ? Something like stdenv.cc.cflags_compile and stdenv.cc.ld_flags

Copy link
Member

@matthewbauer matthewbauer Apr 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is the pre-substituted values since we don't know the actual values at evaluation

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to uses more Nix so we did know the values. (e.g. have a nix boolean and then assert at run-time it was correct.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that requires Nix-level setup-hooks to work correctly. I think that might be too ambitious for now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking something like /nix-support/get-cflags.sh which does all of this for you.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well getting all the -I flags for other packaged requires that, but not just the std library stuff I think.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right these should just need the basic c/c++ headers and library paths.

$(< ${stdenv.cc}/nix-support/cc-cflags) \
${stdenv.cc.default_cxx_stdlib_compile} \
$(< ${stdenv.cc}/nix-support/libcxx-cxxflags) \
${lib.optionalString stdenv.cc.isClang "-idirafter ${stdenv.cc.cc}/lib/clang/${lib.getVersion stdenv.cc.cc}/include"} \
${lib.optionalString stdenv.cc.isGNU "-isystem ${stdenv.cc.cc}/include/c++/${lib.getVersion stdenv.cc.cc} -isystem ${stdenv.cc.cc}/include/c++/${lib.getVersion stdenv.cc.cc}/${stdenv.hostPlatform.config}"} \
$NIX_CFLAGS_COMPILE"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ stdenv.mkDerivation rec {

BINDGEN_CFLAGS="$(< ${stdenv.cc}/nix-support/libc-cflags) \
$(< ${stdenv.cc}/nix-support/cc-cflags) \
${stdenv.cc.default_cxx_stdlib_compile} \
$(< ${stdenv.cc}/nix-support/libcxx-cxxflags) \
${
lib.optionalString stdenv.cc.isClang
"-idirafter ${stdenv.cc.cc}/lib/clang/${
Expand Down
8 changes: 8 additions & 0 deletions pkgs/build-support/cc-wrapper/add-flags.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ if [ -e @out@/nix-support/libc-cflags ]; then
NIX_CFLAGS_COMPILE_@suffixSalt@="$(< @out@/nix-support/libc-cflags) $NIX_CFLAGS_COMPILE_@suffixSalt@"
fi

if [ -e @out@/nix-support/libcxx-cxxflags ]; then
NIX_CXXSTDLIB_COMPILE_@suffixSalt@+=" $(< @out@/nix-support/libcxx-cxxflags)"
fi

if [ -e @out@/nix-support/libcxx-ldflags ]; then
NIX_CXXSTDLIB_LINK_@suffixSalt@+=" $(< @out@/nix-support/libcxx-ldflags)"
fi

if [ -e @out@/nix-support/cc-cflags ]; then
NIX_CFLAGS_COMPILE_@suffixSalt@="$(< @out@/nix-support/cc-cflags) $NIX_CFLAGS_COMPILE_@suffixSalt@"
fi
Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/cc-wrapper/cc-wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ fi

if [[ "$isCpp" = 1 ]]; then
if [[ "$cppInclude" = 1 ]]; then
NIX_CFLAGS_COMPILE_@suffixSalt@+=" ${NIX_CXXSTDLIB_COMPILE_@suffixSalt@:-@default_cxx_stdlib_compile@}"
NIX_CFLAGS_COMPILE_@suffixSalt@+=" $NIX_CXXSTDLIB_COMPILE_@suffixSalt@"
fi
NIX_CFLAGS_LINK_@suffixSalt@+=" $NIX_CXXSTDLIB_LINK_@suffixSalt@"
fi
Expand Down
61 changes: 46 additions & 15 deletions pkgs/build-support/cc-wrapper/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@ let
# The wrapper scripts use 'cat' and 'grep', so we may need coreutils.
coreutils_bin = if nativeTools then "" else getBin coreutils;

default_cxx_stdlib_compile = if (targetPlatform.isLinux && !(cc.isGNU or false) && !nativeTools && cc ? gcc) && !(targetPlatform.useLLVM or false) then
"-isystem $(echo -n ${cc.gcc}/include/c++/*) -isystem $(echo -n ${cc.gcc}/include/c++/*)/${targetPlatform.config}"
else if targetPlatform.isDarwin && (libcxx != null) && (cc.isClang or false) && !(targetPlatform.useLLVM or false) then
"-isystem ${libcxx}/include/c++/v1"
else "";

# The "suffix salt" is a arbitrary string added in the end of env vars
# defined by cc-wrapper's hooks so that multiple cc-wrappers can be used
# without interfering. For the moment, it is defined as the target triple,
Expand All @@ -68,15 +62,15 @@ let

# older compilers (for example bootstrap's GCC 5) fail with -march=too-modern-cpu
isGccArchSupported = arch:
if cc.isGNU or false then
if isGNU then
{ skylake = versionAtLeast ccVersion "6.0";
skylake-avx512 = versionAtLeast ccVersion "6.0";
cannonlake = versionAtLeast ccVersion "8.0";
icelake-client = versionAtLeast ccVersion "8.0";
icelake-server = versionAtLeast ccVersion "8.0";
knm = versionAtLeast ccVersion "8.0";
}.${arch} or true
else if cc.isClang or false then
else if isClang then
{ cannonlake = versionAtLeast ccVersion "5.0";
icelake-client = versionAtLeast ccVersion "7.0";
icelake-server = versionAtLeast ccVersion "7.0";
Expand Down Expand Up @@ -116,7 +110,7 @@ stdenv.mkDerivation {
# Binutils, and Apple's "cctools"; "bintools" as an attempt to find an
# unused middle-ground name that evokes both.
inherit bintools;
inherit libc nativeTools nativeLibc nativePrefix isGNU isClang default_cxx_stdlib_compile;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be used outside by wrappers outside of nixpkgs. might be worth keeping, but just as meta-information.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be, but I think that's bad :)

Copy link
Member

@matthewbauer matthewbauer Apr 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no good way to use libraries that want these c flags without some meta-info like this. For instance bindgen in rust or anything that uses libclang. If we're going to be removing it, we should at least have a replacement.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see #26474 for why this was exported

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right I would rather have a more general way to get flags and just this one in particular. The default part (i.e. miy get overriden) is no good too.

inherit libc nativeTools nativeLibc nativePrefix isGNU isClang;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to expose the libc++ of the compiler, similar to libc?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, though null for libstdc++ is rather unfortunate. Oh well, all the more reason to get on splitting up the GCC derivation.

Copy link
Member

@LnL7 LnL7 Apr 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps for now cc.libcxx = gcc would make sense? Maybe that could also solve cc ? gcc.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm on the fence about this---I do want to get rid of cc.gcc but it's a bit disingenous unless we can somehow filter the other libraries out. Maybe we can leave that for a follow-up PR?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#91293 got rid of cc.gcc here.


emacsBufferSetup = pkgs: ''
; We should handle propagation here too
Expand Down Expand Up @@ -173,8 +167,6 @@ stdenv.mkDerivation {
export named_cc=${targetPrefix}cc
export named_cxx=${targetPrefix}c++

export default_cxx_stdlib_compile="${default_cxx_stdlib_compile}"

if [ -e $ccPath/${targetPrefix}gcc ]; then
wrap ${targetPrefix}gcc $wrapper $ccPath/${targetPrefix}gcc
ln -s ${targetPrefix}gcc $out/bin/${targetPrefix}cc
Expand Down Expand Up @@ -226,7 +218,7 @@ stdenv.mkDerivation {

strictDeps = true;
propagatedBuildInputs = [ bintools ] ++ extraTools ++ optionals cc.langD or false [ zlib ];
depsTargetTargetPropagated = extraPackages;
depsTargetTargetPropagated = optional (libcxx != null) libcxx ++ extraPackages;

wrapperName = "CC_WRAPPER";

Expand All @@ -250,6 +242,24 @@ stdenv.mkDerivation {
fi
''

+ optionalString isClang ''
##
## General Clang support
##

echo "-target ${targetPlatform.config}" >> $out/nix-support/cc-cflags
''

+ optionalString (isClang && libcxx == null && cc ? gcc) ''
##
## GCC libs for non-GCC support
##

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
''

+ optionalString (libc != null) (''
##
## General libc support
Expand Down Expand Up @@ -279,6 +289,27 @@ stdenv.mkDerivation {
echo "${libc_dev}" > $out/nix-support/orig-libc-dev
'')

+ ''
##
## General libc++ support
##

''
+ optionalString (libcxx == null && cc ? gcc) ''
for dir in ${cc.gcc}/include/c++/*; do
echo "-isystem $dir" >> $out/nix-support/libcxx-cxxflags
done
for dir in ${cc.gcc}/include/c++/*/${targetPlatform.config}; do
echo "-isystem $dir" >> $out/nix-support/libcxx-cxxflags
done
''
+ optionalString (libcxx.isLLVM or false) (''
echo "-isystem ${libcxx}/include/c++/v1" >> $out/nix-support/libcxx-cxxflags
echo "-stdlib=libc++" >> $out/nix-support/libcxx-ldflags
'' + stdenv.lib.optionalString stdenv.targetPlatform.isLinux ''
echo "-lc++abi" >> $out/nix-support/libcxx-ldflags
'')

+ optionalString (!nativeTools) ''
##
## Initial CFLAGS
Expand Down Expand Up @@ -389,9 +420,9 @@ stdenv.mkDerivation {
# There are a few tools (to name one libstdcxx5) which do not work
# well with multi line flags, so make the flags single line again
+ ''
if [ -e "$out/nix-support/libc-cflags" ]; then
substituteInPlace "$out/nix-support/libc-cflags" --replace $'\n' ' '
fi
for flags in "$out/nix-support"/*flags; do
substituteInPlace "$flags" --replace $'\n' ' '
done

substituteAll ${./add-flags.sh} $out/nix-support/add-flags.sh
substituteAll ${./add-hardening.sh} $out/nix-support/add-hardening.sh
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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 {
Expand Down Expand Up @@ -34,14 +35,15 @@ stdenv.mkDerivation rec {
#"-DLLVM_CONFIG=${llvm}/bin/llvm-config"
"-DLLVM_BUILD_TESTS=ON"
"-DCLANG_INCLUDE_TESTS=ON"
] ++ (stdenv.lib.optional stdenv.isLinux
] ++ (stdenv.lib.optional (stdenv.isLinux && haveGcc)
# necessary for clang to find crtend.o
"-DGCC_INSTALL_PREFIX=${gcc}"
);
enableParallelBuilding = true;

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

Expand Down
4 changes: 0 additions & 4 deletions pkgs/development/compilers/gcc/libstdc++-hook.sh

This file was deleted.

17 changes: 3 additions & 14 deletions pkgs/development/compilers/llvm/10/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ lowPrio, newScope, pkgs, stdenv, cmake, gcc, libstdcxxHook
{ lowPrio, newScope, pkgs, stdenv, cmake
, libxml2, python3, isl, fetchurl, overrideCC, wrapCCWith, wrapBintoolsWith
, buildLlvmTools # tools, but from the previous stage, for cross
, targetLlvmLibraries # libraries, but from the next stage, for cross
Expand Down Expand Up @@ -57,23 +57,17 @@ let

libstdcxxClang = wrapCCWith rec {
cc = tools.clang-unwrapped;
libcxx = null; # libstdcxx is smuggled in with clang.gcc
extraPackages = [
libstdcxxHook
targetLlvmLibraries.compiler-rt
];
extraBuildCommands = ''
echo "-target ${targetConfig}" >> $out/nix-support/cc-cflags
echo "-B${gcc.cc}/lib/gcc/${targetConfig}/${gcc.version}" >> $out/nix-support/cc-cflags
echo "-L${gcc.cc}/lib/gcc/${targetConfig}/${gcc.version}" >> $out/nix-support/cc-ldflags
echo "-L${gcc.cc.lib}/${targetConfig}/lib" >> $out/nix-support/cc-ldflags
'' + mkExtraBuildCommands cc;
extraBuildCommands = mkExtraBuildCommands cc;
};

libcxxClang = wrapCCWith rec {
cc = tools.clang-unwrapped;
libcxx = targetLlvmLibraries.libcxx;
extraPackages = [
targetLlvmLibraries.libcxx
targetLlvmLibraries.libcxxabi
targetLlvmLibraries.compiler-rt
];
Expand All @@ -100,14 +94,12 @@ let
inherit (tools) bintools;
};
extraPackages = [
targetLlvmLibraries.libcxx
targetLlvmLibraries.libcxxabi
targetLlvmLibraries.compiler-rt
] ++ stdenv.lib.optionals (!stdenv.targetPlatform.isWasm) [
targetLlvmLibraries.libunwind
];
extraBuildCommands = ''
echo "-target ${stdenv.targetPlatform.config}" >> $out/nix-support/cc-cflags
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
'' + stdenv.lib.optionalString (!stdenv.targetPlatform.isWasm) ''
Expand All @@ -127,7 +119,6 @@ let
targetLlvmLibraries.compiler-rt
];
extraBuildCommands = ''
echo "-target ${stdenv.targetPlatform.config}" >> $out/nix-support/cc-cflags
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
Expand All @@ -145,7 +136,6 @@ let
targetLlvmLibraries.compiler-rt
];
extraBuildCommands = ''
echo "-target ${stdenv.targetPlatform.config}" >> $out/nix-support/cc-cflags
echo "-rtlib=compiler-rt" >> $out/nix-support/cc-cflags
echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags
'' + mkExtraBuildCommands cc;
Expand All @@ -161,7 +151,6 @@ let
extraPackages = [ ];
extraBuildCommands = ''
echo "-nostartfiles" >> $out/nix-support/cc-cflags
echo "-target ${stdenv.targetPlatform.config}" >> $out/nix-support/cc-cflags
'';
};

Expand Down
9 changes: 3 additions & 6 deletions pkgs/development/compilers/llvm/10/libc++/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,9 @@ stdenv.mkDerivation {

enableParallelBuilding = true;

linkCxxAbi = stdenv.isLinux;

setupHooks = [
../../../../../build-support/setup-hooks/role.bash
./setup-hook.sh
];
passthru = {
isLLVM = true;
};

meta = {
homepage = "https://libcxx.llvm.org/";
Expand Down
6 changes: 0 additions & 6 deletions pkgs/development/compilers/llvm/10/libc++/setup-hook.sh

This file was deleted.

14 changes: 3 additions & 11 deletions pkgs/development/compilers/llvm/5/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ lowPrio, newScope, pkgs, stdenv, cmake, gcc, libstdcxxHook
{ lowPrio, newScope, pkgs, stdenv, cmake
, libxml2, python3, isl, fetchurl, overrideCC, wrapCCWith
, buildLlvmTools # tools, but from the previous stage, for cross
, targetLlvmLibraries # libraries, but from the next stage, for cross
Expand Down Expand Up @@ -51,25 +51,17 @@ let

libstdcxxClang = wrapCCWith rec {
cc = tools.clang-unwrapped;
extraTools = [
libstdcxxHook
];
libcxx = null; # libstdcxx is smuggled in with clang.gcc
extraPackages = [
targetLlvmLibraries.compiler-rt
];
extraBuildCommands = ''
echo "-target ${targetConfig}" >> $out/nix-support/cc-cflags
echo "-B${gcc.cc}/lib/gcc/${targetConfig}/${gcc.version}" >> $out/nix-support/cc-cflags
echo "-L${gcc.cc}/lib/gcc/${targetConfig}/${gcc.version}" >> $out/nix-support/cc-ldflags
echo "-L${gcc.cc.lib}/${targetConfig}/lib" >> $out/nix-support/cc-ldflags
'' + mkExtraBuildCommands cc;
extraBuildCommands = mkExtraBuildCommands cc;
};

libcxxClang = wrapCCWith rec {
cc = tools.clang-unwrapped;
libcxx = targetLlvmLibraries.libcxx;
extraPackages = [
targetLlvmLibraries.libcxx
targetLlvmLibraries.libcxxabi
targetLlvmLibraries.compiler-rt
];
Expand Down
9 changes: 3 additions & 6 deletions pkgs/development/compilers/llvm/5/libc++/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,9 @@ stdenv.mkDerivation {

enableParallelBuilding = true;

linkCxxAbi = stdenv.isLinux;

setupHooks = [
../../../../../build-support/setup-hooks/role.bash
./setup-hook.sh
];
passthru = {
isLLVM = true;
};

meta = {
homepage = "https://libcxx.llvm.org/";
Expand Down
6 changes: 0 additions & 6 deletions pkgs/development/compilers/llvm/5/libc++/setup-hook.sh

This file was deleted.

14 changes: 3 additions & 11 deletions pkgs/development/compilers/llvm/6/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ lowPrio, newScope, pkgs, stdenv, cmake, gcc, libstdcxxHook
{ lowPrio, newScope, pkgs, stdenv, cmake
, libxml2, python3, isl, fetchurl, overrideCC, wrapCCWith
, buildLlvmTools # tools, but from the previous stage, for cross
, targetLlvmLibraries # libraries, but from the next stage, for cross
Expand Down Expand Up @@ -51,25 +51,17 @@ let

libstdcxxClang = wrapCCWith rec {
cc = tools.clang-unwrapped;
extraTools = [
libstdcxxHook
];
libcxx = null; # libstdcxx is smuggled in with clang.gcc
extraPackages = [
targetLlvmLibraries.compiler-rt
];
extraBuildCommands = ''
echo "-target ${targetConfig}" >> $out/nix-support/cc-cflags
echo "-B${gcc.cc}/lib/gcc/${targetConfig}/${gcc.version}" >> $out/nix-support/cc-cflags
echo "-L${gcc.cc}/lib/gcc/${targetConfig}/${gcc.version}" >> $out/nix-support/cc-ldflags
echo "-L${gcc.cc.lib}/${targetConfig}/lib" >> $out/nix-support/cc-ldflags
'' + mkExtraBuildCommands cc;
extraBuildCommands = mkExtraBuildCommands cc;
};

libcxxClang = wrapCCWith rec {
cc = tools.clang-unwrapped;
libcxx = targetLlvmLibraries.libcxx;
extraPackages = [
targetLlvmLibraries.libcxx
targetLlvmLibraries.libcxxabi
targetLlvmLibraries.compiler-rt
];
Expand Down
9 changes: 3 additions & 6 deletions pkgs/development/compilers/llvm/6/libc++/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,9 @@ stdenv.mkDerivation {

enableParallelBuilding = true;

linkCxxAbi = stdenv.isLinux;

setupHooks = [
../../../../../build-support/setup-hooks/role.bash
./setup-hook.sh
];
passthru = {
isLLVM = true;
};

meta = {
homepage = "https://libcxx.llvm.org/";
Expand Down
Loading