{bintools,cc}-wrapper: Ensure nix-support/*-flags files exist

This will unbreak firefox and a few other packages which try to grab
some of the libcxx flags.
This commit is contained in:
John Ericson 2020-06-30 18:26:37 +00:00
parent 1085403acd
commit 704daf7a6e
2 changed files with 37 additions and 17 deletions

View File

@ -204,7 +204,8 @@ stdenv.mkDerivation {
## General libc support ## General libc support
## ##
optionalString (libc != null) ('' optionalString (libc != null) (''
echo "-L${libc_lib}${libc.libdir or "/lib"}" > $out/nix-support/libc-ldflags touch "$out/nix-support/libc-ldflags"
echo "-L${libc_lib}${libc.libdir or "/lib"}" >> $out/nix-support/libc-ldflags
echo "${libc_lib}" > $out/nix-support/orig-libc echo "${libc_lib}" > $out/nix-support/orig-libc
echo "${libc_dev}" > $out/nix-support/orig-libc-dev echo "${libc_dev}" > $out/nix-support/orig-libc-dev
@ -230,25 +231,23 @@ stdenv.mkDerivation {
*) echo "Multiple dynamic linkers found for platform '${targetPlatform.config}'." >&2;; *) echo "Multiple dynamic linkers found for platform '${targetPlatform.config}'." >&2;;
esac esac
if [ -n "''${dynamicLinker:-}" ]; then if [ -n "''${dynamicLinker-}" ]; then
echo $dynamicLinker > $out/nix-support/dynamic-linker echo $dynamicLinker > $out/nix-support/dynamic-linker
'' + (if targetPlatform.isDarwin then '' '' + (if targetPlatform.isDarwin then ''
printf "export LD_DYLD_PATH=%q\n" "$dynamicLinker" >> $out/nix-support/setup-hook printf "export LD_DYLD_PATH=%q\n" "$dynamicLinker" >> $out/nix-support/setup-hook
'' else '' '' else ''
if [ -e ${libc_lib}/lib/32/ld-linux.so.2 ]; then if [ -e ${libc_lib}/lib/32/ld-linux.so.2 ]; then
echo ${libc_lib}/lib/32/ld-linux.so.2 > $out/nix-support/dynamic-linker-m32 echo ${libc_lib}/lib/32/ld-linux.so.2 > $out/nix-support/dynamic-linker-m32
fi fi
''
local ldflagsBefore=(-dynamic-linker "$dynamicLinker") # The dynamic linker is passed in `ldflagsBefore' to allow
# explicit overrides of the dynamic linker by callers to ld
# (the *last* value counts, so ours should come first).
+ ''
echo -dynamic-linker "$dynamicLinker" >> $out/nix-support/libc-ldflags-before
'') + '' '') + ''
fi fi
''
# The dynamic linker is passed in `ldflagsBefore' to allow
# explicit overrides of the dynamic linker by callers to ld
# (the *last* value counts, so ours should come first).
+ ''
printWords "''${ldflagsBefore[@]}" > $out/nix-support/libc-ldflags-before
'') '')
# Ensure consistent LC_VERSION_MIN_MACOSX and remove LC_UUID. # Ensure consistent LC_VERSION_MIN_MACOSX and remove LC_UUID.
@ -306,6 +305,10 @@ stdenv.mkDerivation {
'' ''
+ '' + ''
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-flags.sh} $out/nix-support/add-flags.sh
substituteAll ${./add-hardening.sh} $out/nix-support/add-hardening.sh substituteAll ${./add-hardening.sh} $out/nix-support/add-hardening.sh
substituteAll ${../wrapper-common/utils.bash} $out/nix-support/utils.bash substituteAll ${../wrapper-common/utils.bash} $out/nix-support/utils.bash

View File

@ -230,12 +230,19 @@ stdenv.mkDerivation {
]; ];
postFixup = postFixup =
# Ensure flags files exists, as some other programs cat them. (That these
# are considered an exposed interface is a bit dubious, but fine for now.)
''
touch "$out/nix-support/cc-cflags"
touch "$out/nix-support/cc-ldflags"
''
# Backwards compatability for packages expecting this file, e.g. with # Backwards compatability for packages expecting this file, e.g. with
# `$NIX_CC/nix-support/dynamic-linker`. # `$NIX_CC/nix-support/dynamic-linker`.
# #
# TODO(@Ericson2314): Remove this after stable release and force # TODO(@Ericson2314): Remove this after stable release and force
# everyone to refer to bintools-wrapper directly. # everyone to refer to bintools-wrapper directly.
'' + ''
if [[ -f "$bintools/nix-support/dynamic-linker" ]]; then if [[ -f "$bintools/nix-support/dynamic-linker" ]]; then
ln -s "$bintools/nix-support/dynamic-linker" "$out/nix-support" ln -s "$bintools/nix-support/dynamic-linker" "$out/nix-support"
fi fi
@ -278,6 +285,8 @@ stdenv.mkDerivation {
# limits.h file in ../includes-fixed. To remedy the problem, # limits.h file in ../includes-fixed. To remedy the problem,
# another -idirafter is necessary to add that directory again. # another -idirafter is necessary to add that directory again.
+ optionalString (libc != null) ('' + optionalString (libc != null) (''
touch "$out/nix-support/libc-cflags"
touch "$out/nix-support/libc-ldflags"
echo "-B${libc_lib}${libc.libdir or "/lib/"}" >> $out/nix-support/libc-cflags echo "-B${libc_lib}${libc.libdir or "/lib/"}" >> $out/nix-support/libc-cflags
'' + optionalString (!(cc.langD or false)) '' '' + optionalString (!(cc.langD or false)) ''
echo "-idirafter ${libc_dev}${libc.incdir or "/include"}" >> $out/nix-support/libc-cflags echo "-idirafter ${libc_dev}${libc.incdir or "/include"}" >> $out/nix-support/libc-cflags
@ -294,7 +303,13 @@ stdenv.mkDerivation {
## ##
## General libc++ support ## General libc++ support
## ##
+ optionalString (libcxx == null && cc ? gcc) ''
# 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)) ''
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 for dir in ${cc.gcc}/include/c++/*; do
echo "-isystem $dir" >> $out/nix-support/libcxx-cxxflags echo "-isystem $dir" >> $out/nix-support/libcxx-cxxflags
done done
@ -326,14 +341,16 @@ stdenv.mkDerivation {
ccCFlags+=" -B${cc_solib}/lib" ccCFlags+=" -B${cc_solib}/lib"
'' + optionalString cc.langAda or false '' '' + optionalString cc.langAda or false ''
touch "$out/nix-support/gnat-cflags"
touch "$out/nix-support/gnat-ldflags"
basePath=$(echo $cc/lib/*/*/*) basePath=$(echo $cc/lib/*/*/*)
ccCFlags+=" -B$basePath -I$basePath/adainclude" ccCFlags+=" -B$basePath -I$basePath/adainclude"
gnatCFlags="-I$basePath/adainclude -I$basePath/adalib" gnatCFlags="-I$basePath/adainclude -I$basePath/adalib"
echo "$gnatCFlags" > $out/nix-support/gnat-cflags echo "$gnatCFlags" >> $out/nix-support/gnat-cflags
'' + '' '' + ''
echo "$ccLDFlags" > $out/nix-support/cc-ldflags echo "$ccLDFlags" >> $out/nix-support/cc-ldflags
echo "$ccCFlags" > $out/nix-support/cc-cflags echo "$ccCFlags" >> $out/nix-support/cc-cflags
'' + optionalString (targetPlatform.isDarwin && (libcxx != null) && (cc.isClang or false)) '' '' + optionalString (targetPlatform.isDarwin && (libcxx != null) && (cc.isClang or false)) ''
echo " -L${libcxx}/lib" >> $out/nix-support/cc-ldflags echo " -L${libcxx}/lib" >> $out/nix-support/cc-ldflags
'' ''
@ -419,7 +436,7 @@ stdenv.mkDerivation {
# There are a few tools (to name one libstdcxx5) which do not work # 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 # well with multi line flags, so make the flags single line again
+ '' + ''
for flags in "$out/nix-support"/*flags; do for flags in "$out/nix-support"/*flags*; do
substituteInPlace "$flags" --replace $'\n' ' ' substituteInPlace "$flags" --replace $'\n' ' '
done done