From caf22a33eb1119004a7f5b9b9faafab6dad7f976 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Wed, 14 Jun 2023 19:12:28 -0700 Subject: [PATCH 1/9] gcc: copy gcc/builder.sh to gcc/common/builder.nix This commit is left unsquashed to make review of the subsequent commits easier. --- .../compilers/gcc/common/builder.nix | 289 ++++++++++++++++++ 1 file changed, 289 insertions(+) create mode 100644 pkgs/development/compilers/gcc/common/builder.nix diff --git a/pkgs/development/compilers/gcc/common/builder.nix b/pkgs/development/compilers/gcc/common/builder.nix new file mode 100644 index 0000000000000..5147df1e4cc0d --- /dev/null +++ b/pkgs/development/compilers/gcc/common/builder.nix @@ -0,0 +1,289 @@ +if [ -e .attrs.sh ]; then source .attrs.sh; fi +source $stdenv/setup + + +oldOpts="$(shopt -po nounset)" || true +set -euo pipefail + + +export NIX_FIXINC_DUMMY="$NIX_BUILD_TOP/dummy" +mkdir "$NIX_FIXINC_DUMMY" + + +if test "$staticCompiler" = "1"; then + EXTRA_LDFLAGS="-static" +else + EXTRA_LDFLAGS="-Wl,-rpath,${!outputLib}/lib" +fi + + +# GCC interprets empty paths as ".", which we don't want. +if test -z "${CPATH-}"; then unset CPATH; fi +if test -z "${LIBRARY_PATH-}"; then unset LIBRARY_PATH; fi +echo "\$CPATH is \`${CPATH-}'" +echo "\$LIBRARY_PATH is \`${LIBRARY_PATH-}'" + +if test "$noSysDirs" = "1"; then + + declare \ + EXTRA_FLAGS_FOR_BUILD EXTRA_FLAGS EXTRA_FLAGS_FOR_TARGET \ + EXTRA_LDFLAGS_FOR_BUILD EXTRA_LDFLAGS_FOR_TARGET + + # Extract flags from Bintools Wrappers + for post in '_FOR_BUILD' ''; do + curBintools="NIX_BINTOOLS${post}" + + declare -a extraLDFlags=() + if [[ -e "${!curBintools}/nix-support/orig-libc" ]]; then + # Figure out what extra flags when linking to pass to the gcc + # compilers being generated to make sure that they use our libc. + extraLDFlags=($(< "${!curBintools}/nix-support/libc-ldflags") $(< "${!curBintools}/nix-support/libc-ldflags-before" || true)) + if [ -e ${!curBintools}/nix-support/ld-set-dynamic-linker ]; then + extraLDFlags=-dynamic-linker=$(< ${!curBintools}/nix-support/dynamic-linker) + fi + + # The path to the Libc binaries such as `crti.o'. + libc_libdir="$(< "${!curBintools}/nix-support/orig-libc")/lib" + else + # Hack: support impure environments. + extraLDFlags=("-L/usr/lib64" "-L/usr/lib") + libc_libdir="/usr/lib" + fi + extraLDFlags=("-L$libc_libdir" "-rpath" "$libc_libdir" + "${extraLDFlags[@]}") + for i in "${extraLDFlags[@]}"; do + declare EXTRA_LDFLAGS${post}+=" -Wl,$i" + done + done + + # Extract flags from CC Wrappers + for post in '_FOR_BUILD' ''; do + curCC="NIX_CC${post}" + curFIXINC="NIX_FIXINC_DUMMY${post}" + + declare -a extraFlags=() + if [[ -e "${!curCC}/nix-support/orig-libc" ]]; then + # Figure out what extra compiling flags to pass to the gcc compilers + # being generated to make sure that they use our libc. + extraFlags=($(< "${!curCC}/nix-support/libc-crt1-cflags") $(< "${!curCC}/nix-support/libc-cflags")) + + # The path to the Libc headers + libc_devdir="$(< "${!curCC}/nix-support/orig-libc-dev")" + + # Use *real* header files, otherwise a limits.h is generated that + # does not include Libc's limits.h (notably missing SSIZE_MAX, + # which breaks the build). + declare NIX_FIXINC_DUMMY${post}="$libc_devdir/include" + else + # Hack: support impure environments. + extraFlags=("-isystem" "/usr/include") + declare NIX_FIXINC_DUMMY${post}=/usr/include + fi + + extraFlags=("-I${!curFIXINC}" "${extraFlags[@]}") + + # BOOT_CFLAGS defaults to `-g -O2'; since we override it below, make + # sure to explictly add them so that files compiled with the bootstrap + # compiler are optimized and (optionally) contain debugging information + # (info "(gccinstall) Building"). + if test -n "${dontStrip-}"; then + extraFlags=("-O2" "-g" "${extraFlags[@]}") + else + # Don't pass `-g' at all; this saves space while building. + extraFlags=("-O2" "${extraFlags[@]}") + fi + + declare EXTRA_FLAGS${post}="${extraFlags[*]}" + done + + if test -z "${targetConfig-}"; then + # host = target, so the flags are the same + EXTRA_FLAGS_FOR_TARGET="$EXTRA_FLAGS" + EXTRA_LDFLAGS_FOR_TARGET="$EXTRA_LDFLAGS" + fi + + # CFLAGS_FOR_TARGET are needed for the libstdc++ configure script to find + # the startfiles. + # FLAGS_FOR_TARGET are needed for the target libraries to receive the -Bxxx + # for the startfiles. + makeFlagsArray+=( + "BUILD_SYSTEM_HEADER_DIR=$NIX_FIXINC_DUMMY_FOR_BUILD" + "SYSTEM_HEADER_DIR=$NIX_FIXINC_DUMMY_FOR_BUILD" + "NATIVE_SYSTEM_HEADER_DIR=$NIX_FIXINC_DUMMY" + + "LDFLAGS_FOR_BUILD=$EXTRA_LDFLAGS_FOR_BUILD" + #"LDFLAGS=$EXTRA_LDFLAGS" + "LDFLAGS_FOR_TARGET=$EXTRA_LDFLAGS_FOR_TARGET" + + "CFLAGS_FOR_BUILD=$EXTRA_FLAGS_FOR_BUILD $EXTRA_LDFLAGS_FOR_BUILD" + "CXXFLAGS_FOR_BUILD=$EXTRA_FLAGS_FOR_BUILD $EXTRA_LDFLAGS_FOR_BUILD" + "FLAGS_FOR_BUILD=$EXTRA_FLAGS_FOR_BUILD $EXTRA_LDFLAGS_FOR_BUILD" + + # It seems there is a bug in GCC 5 + #"CFLAGS=$EXTRA_FLAGS $EXTRA_LDFLAGS" + #"CXXFLAGS=$EXTRA_FLAGS $EXTRA_LDFLAGS" + + "CFLAGS_FOR_TARGET=$EXTRA_FLAGS_FOR_TARGET $EXTRA_LDFLAGS_FOR_TARGET" + "CXXFLAGS_FOR_TARGET=$EXTRA_FLAGS_FOR_TARGET $EXTRA_LDFLAGS_FOR_TARGET" + "FLAGS_FOR_TARGET=$EXTRA_FLAGS_FOR_TARGET $EXTRA_LDFLAGS_FOR_TARGET" + ) + + if test -z "${targetConfig-}"; then + makeFlagsArray+=( + "BOOT_CFLAGS=$EXTRA_FLAGS $EXTRA_LDFLAGS" + "BOOT_LDFLAGS=$EXTRA_FLAGS_FOR_TARGET $EXTRA_LDFLAGS_FOR_TARGET" + ) + fi + + if test "$crossStageStatic" == 1; then + # We don't want the gcc build to assume there will be a libc providing + # limits.h in this stage + makeFlagsArray+=( + 'LIMITS_H_TEST=false' + ) + else + makeFlagsArray+=( + 'LIMITS_H_TEST=true' + ) + fi +fi + +eval "$oldOpts" + +providedPreConfigure="$preConfigure"; +preConfigure() { + if test -n "$newlibSrc"; then + tar xvf "$newlibSrc" -C .. + ln -s ../newlib-*/newlib newlib + # Patch to get armvt5el working: + sed -i -e 's/ arm)/ arm*)/' newlib/configure.host + fi + + # Bug - they packaged zlib + if test -d "zlib"; then + # This breaks the build without-headers, which should build only + # the target libgcc as target libraries. + # See 'configure:5370' + rm -Rf zlib + fi + + if test -n "$crossMingw" -a -n "$crossStageStatic"; then + mkdir -p ../mingw + # --with-build-sysroot expects that: + cp -R $libcCross/include ../mingw + configureFlags="$configureFlags --with-build-sysroot=`pwd`/.." + fi + + # Eval the preConfigure script from nix expression. + eval "$providedPreConfigure" + + # Perform the build in a different directory. + mkdir ../build + cd ../build + configureScript=../$sourceRoot/configure +} + + +postConfigure() { + # Don't store the configure flags in the resulting executables. + sed -e '/TOPLEVEL_CONFIGURE_ARGUMENTS=/d' -i Makefile +} + + +preInstall() { + mkdir -p "$out/${targetConfig}/lib" + mkdir -p "${!outputLib}/${targetConfig}/lib" + # Make ‘lib64’ symlinks to ‘lib’. + if [ -n "$linkLib64toLib" ]; then + ln -s lib "$out/${targetConfig}/lib64" + ln -s lib "${!outputLib}/${targetConfig}/lib64" + fi + # Make ‘lib32’ symlinks to ‘lib’. + if [ -n "$linkLib32toLib" ]; then + ln -s lib "$out/${targetConfig}/lib32" + ln -s lib "${!outputLib}/${targetConfig}/lib32" + fi +} + + +postInstall() { + # Move runtime libraries to lib output. + moveToOutput "${targetConfig+$targetConfig/}lib/lib*.so*" "${!outputLib}" + moveToOutput "${targetConfig+$targetConfig/}lib/lib*.la" "${!outputLib}" + moveToOutput "${targetConfig+$targetConfig/}lib/lib*.dylib" "${!outputLib}" + moveToOutput "${targetConfig+$targetConfig/}lib/lib*.dll.a" "${!outputLib}" + moveToOutput "share/gcc-*/python" "${!outputLib}" + + if [ -z "$enableShared" ]; then + moveToOutput "${targetConfig+$targetConfig/}lib/lib*.a" "${!outputLib}" + fi + + for i in "${!outputLib}/${targetConfig}"/lib/*.{la,py}; do + substituteInPlace "$i" --replace "$out" "${!outputLib}" + done + + if [ -n "$enableMultilib" ]; then + moveToOutput "${targetConfig+$targetConfig/}lib64/lib*.so*" "${!outputLib}" + moveToOutput "${targetConfig+$targetConfig/}lib64/lib*.la" "${!outputLib}" + moveToOutput "${targetConfig+$targetConfig/}lib64/lib*.dylib" "${!outputLib}" + + for i in "${!outputLib}/${targetConfig}"/lib64/*.{la,py}; do + substituteInPlace "$i" --replace "$out" "${!outputLib}" + done + fi + + # Remove `fixincl' to prevent a retained dependency on the + # previous gcc. + rm -rf $out/libexec/gcc/*/*/install-tools + rm -rf $out/lib/gcc/*/*/install-tools + + # More dependencies with the previous gcc or some libs (gccbug stores the build command line) + rm -rf $out/bin/gccbug + + if type "install_name_tool"; then + for i in "${!outputLib}"/lib/*.*.dylib "${!outputLib}"/lib/*.so.[0-9]; do + install_name_tool -id "$i" "$i" || true + for old_path in $(otool -L "$i" | grep "$out" | awk '{print $1}'); do + new_path=`echo "$old_path" | sed "s,$out,${!outputLib},"` + install_name_tool -change "$old_path" "$new_path" "$i" || true + done + done + fi + + # Cross-compiler specific: + # --with-headers=$dir option triggers gcc to make a private copy + # of $dir headers and use it later as `-isysroot`. This prevents + # cc-wrapper from overriding libc headers with `-idirafter`. + # It should be safe to drop it and rely solely on the cc-wrapper. + local sysinc_dir=$out/${targetConfig+$targetConfig/}sys-include + if [ -d "$sysinc_dir" ]; then + chmod -R u+w "$out/${targetConfig+$targetConfig/}sys-include" + rm -rfv "$out/${targetConfig+$targetConfig/}sys-include" + fi + + # Get rid of some "fixed" header files + rm -rfv $out/lib/gcc/*/*/include-fixed/{root,linux,sys/mount.h,bits/statx.h} + + # Replace hard links for i686-pc-linux-gnu-gcc etc. with symlinks. + for i in $out/bin/*-gcc*; do + if cmp -s $out/bin/gcc $i; then + ln -sfn gcc $i + fi + done + + for i in $out/bin/c++ $out/bin/*-c++* $out/bin/*-g++*; do + if cmp -s $out/bin/g++ $i; then + ln -sfn g++ $i + fi + done + + # Two identical man pages are shipped (moving and compressing is done later) + for i in "$out"/share/man/man1/*g++.1; do + if test -e "$i"; then + man_prefix=`echo "$i" | sed "s,.*/\(.*\)g++.1,\1,"` + ln -sf "$man_prefix"gcc.1 "$i" + fi + done +} + +genericBuild From 72284b0d404d1b1c30f2013a88e8a44df65bb405 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Wed, 14 Jun 2023 19:15:34 -0700 Subject: [PATCH 2/9] gcc: make common/builder.nix into valid Nix syntax This commit performs two search-and-replace operations: - replace all `${` with `''${` - replace `''` with `""` in shell scripts This commit is left unsquashed to make review of the subsequent commits easier. --- .../compilers/gcc/common/builder.nix | 108 +++++++++--------- 1 file changed, 54 insertions(+), 54 deletions(-) diff --git a/pkgs/development/compilers/gcc/common/builder.nix b/pkgs/development/compilers/gcc/common/builder.nix index 5147df1e4cc0d..16f319485befd 100644 --- a/pkgs/development/compilers/gcc/common/builder.nix +++ b/pkgs/development/compilers/gcc/common/builder.nix @@ -13,15 +13,15 @@ mkdir "$NIX_FIXINC_DUMMY" if test "$staticCompiler" = "1"; then EXTRA_LDFLAGS="-static" else - EXTRA_LDFLAGS="-Wl,-rpath,${!outputLib}/lib" + EXTRA_LDFLAGS="-Wl,-rpath,''${!outputLib}/lib" fi # GCC interprets empty paths as ".", which we don't want. -if test -z "${CPATH-}"; then unset CPATH; fi -if test -z "${LIBRARY_PATH-}"; then unset LIBRARY_PATH; fi -echo "\$CPATH is \`${CPATH-}'" -echo "\$LIBRARY_PATH is \`${LIBRARY_PATH-}'" +if test -z "''${CPATH-}"; then unset CPATH; fi +if test -z "''${LIBRARY_PATH-}"; then unset LIBRARY_PATH; fi +echo "\$CPATH is \`''${CPATH-}'" +echo "\$LIBRARY_PATH is \`''${LIBRARY_PATH-}'" if test "$noSysDirs" = "1"; then @@ -30,73 +30,73 @@ if test "$noSysDirs" = "1"; then EXTRA_LDFLAGS_FOR_BUILD EXTRA_LDFLAGS_FOR_TARGET # Extract flags from Bintools Wrappers - for post in '_FOR_BUILD' ''; do - curBintools="NIX_BINTOOLS${post}" + for post in '_FOR_BUILD' ""; do + curBintools="NIX_BINTOOLS''${post}" declare -a extraLDFlags=() - if [[ -e "${!curBintools}/nix-support/orig-libc" ]]; then + if [[ -e "''${!curBintools}/nix-support/orig-libc" ]]; then # Figure out what extra flags when linking to pass to the gcc # compilers being generated to make sure that they use our libc. - extraLDFlags=($(< "${!curBintools}/nix-support/libc-ldflags") $(< "${!curBintools}/nix-support/libc-ldflags-before" || true)) - if [ -e ${!curBintools}/nix-support/ld-set-dynamic-linker ]; then - extraLDFlags=-dynamic-linker=$(< ${!curBintools}/nix-support/dynamic-linker) + extraLDFlags=($(< "''${!curBintools}/nix-support/libc-ldflags") $(< "''${!curBintools}/nix-support/libc-ldflags-before" || true)) + if [ -e ''${!curBintools}/nix-support/ld-set-dynamic-linker ]; then + extraLDFlags=-dynamic-linker=$(< ''${!curBintools}/nix-support/dynamic-linker) fi # The path to the Libc binaries such as `crti.o'. - libc_libdir="$(< "${!curBintools}/nix-support/orig-libc")/lib" + libc_libdir="$(< "''${!curBintools}/nix-support/orig-libc")/lib" else # Hack: support impure environments. extraLDFlags=("-L/usr/lib64" "-L/usr/lib") libc_libdir="/usr/lib" fi extraLDFlags=("-L$libc_libdir" "-rpath" "$libc_libdir" - "${extraLDFlags[@]}") - for i in "${extraLDFlags[@]}"; do - declare EXTRA_LDFLAGS${post}+=" -Wl,$i" + "''${extraLDFlags[@]}") + for i in "''${extraLDFlags[@]}"; do + declare EXTRA_LDFLAGS''${post}+=" -Wl,$i" done done # Extract flags from CC Wrappers - for post in '_FOR_BUILD' ''; do - curCC="NIX_CC${post}" - curFIXINC="NIX_FIXINC_DUMMY${post}" + for post in '_FOR_BUILD' ""; do + curCC="NIX_CC''${post}" + curFIXINC="NIX_FIXINC_DUMMY''${post}" declare -a extraFlags=() - if [[ -e "${!curCC}/nix-support/orig-libc" ]]; then + if [[ -e "''${!curCC}/nix-support/orig-libc" ]]; then # Figure out what extra compiling flags to pass to the gcc compilers # being generated to make sure that they use our libc. - extraFlags=($(< "${!curCC}/nix-support/libc-crt1-cflags") $(< "${!curCC}/nix-support/libc-cflags")) + extraFlags=($(< "''${!curCC}/nix-support/libc-crt1-cflags") $(< "''${!curCC}/nix-support/libc-cflags")) # The path to the Libc headers - libc_devdir="$(< "${!curCC}/nix-support/orig-libc-dev")" + libc_devdir="$(< "''${!curCC}/nix-support/orig-libc-dev")" # Use *real* header files, otherwise a limits.h is generated that # does not include Libc's limits.h (notably missing SSIZE_MAX, # which breaks the build). - declare NIX_FIXINC_DUMMY${post}="$libc_devdir/include" + declare NIX_FIXINC_DUMMY''${post}="$libc_devdir/include" else # Hack: support impure environments. extraFlags=("-isystem" "/usr/include") - declare NIX_FIXINC_DUMMY${post}=/usr/include + declare NIX_FIXINC_DUMMY''${post}=/usr/include fi - extraFlags=("-I${!curFIXINC}" "${extraFlags[@]}") + extraFlags=("-I''${!curFIXINC}" "''${extraFlags[@]}") # BOOT_CFLAGS defaults to `-g -O2'; since we override it below, make # sure to explictly add them so that files compiled with the bootstrap # compiler are optimized and (optionally) contain debugging information # (info "(gccinstall) Building"). - if test -n "${dontStrip-}"; then - extraFlags=("-O2" "-g" "${extraFlags[@]}") + if test -n "''${dontStrip-}"; then + extraFlags=("-O2" "-g" "''${extraFlags[@]}") else # Don't pass `-g' at all; this saves space while building. - extraFlags=("-O2" "${extraFlags[@]}") + extraFlags=("-O2" "''${extraFlags[@]}") fi - declare EXTRA_FLAGS${post}="${extraFlags[*]}" + declare EXTRA_FLAGS''${post}="''${extraFlags[*]}" done - if test -z "${targetConfig-}"; then + if test -z "''${targetConfig-}"; then # host = target, so the flags are the same EXTRA_FLAGS_FOR_TARGET="$EXTRA_FLAGS" EXTRA_LDFLAGS_FOR_TARGET="$EXTRA_LDFLAGS" @@ -128,7 +128,7 @@ if test "$noSysDirs" = "1"; then "FLAGS_FOR_TARGET=$EXTRA_FLAGS_FOR_TARGET $EXTRA_LDFLAGS_FOR_TARGET" ) - if test -z "${targetConfig-}"; then + if test -z "''${targetConfig-}"; then makeFlagsArray+=( "BOOT_CFLAGS=$EXTRA_FLAGS $EXTRA_LDFLAGS" "BOOT_LDFLAGS=$EXTRA_FLAGS_FOR_TARGET $EXTRA_LDFLAGS_FOR_TARGET" @@ -191,44 +191,44 @@ postConfigure() { preInstall() { - mkdir -p "$out/${targetConfig}/lib" - mkdir -p "${!outputLib}/${targetConfig}/lib" + mkdir -p "$out/''${targetConfig}/lib" + mkdir -p "''${!outputLib}/''${targetConfig}/lib" # Make ‘lib64’ symlinks to ‘lib’. if [ -n "$linkLib64toLib" ]; then - ln -s lib "$out/${targetConfig}/lib64" - ln -s lib "${!outputLib}/${targetConfig}/lib64" + ln -s lib "$out/''${targetConfig}/lib64" + ln -s lib "''${!outputLib}/''${targetConfig}/lib64" fi # Make ‘lib32’ symlinks to ‘lib’. if [ -n "$linkLib32toLib" ]; then - ln -s lib "$out/${targetConfig}/lib32" - ln -s lib "${!outputLib}/${targetConfig}/lib32" + ln -s lib "$out/''${targetConfig}/lib32" + ln -s lib "''${!outputLib}/''${targetConfig}/lib32" fi } postInstall() { # Move runtime libraries to lib output. - moveToOutput "${targetConfig+$targetConfig/}lib/lib*.so*" "${!outputLib}" - moveToOutput "${targetConfig+$targetConfig/}lib/lib*.la" "${!outputLib}" - moveToOutput "${targetConfig+$targetConfig/}lib/lib*.dylib" "${!outputLib}" - moveToOutput "${targetConfig+$targetConfig/}lib/lib*.dll.a" "${!outputLib}" - moveToOutput "share/gcc-*/python" "${!outputLib}" + moveToOutput "''${targetConfig+$targetConfig/}lib/lib*.so*" "''${!outputLib}" + moveToOutput "''${targetConfig+$targetConfig/}lib/lib*.la" "''${!outputLib}" + moveToOutput "''${targetConfig+$targetConfig/}lib/lib*.dylib" "''${!outputLib}" + moveToOutput "''${targetConfig+$targetConfig/}lib/lib*.dll.a" "''${!outputLib}" + moveToOutput "share/gcc-*/python" "''${!outputLib}" if [ -z "$enableShared" ]; then - moveToOutput "${targetConfig+$targetConfig/}lib/lib*.a" "${!outputLib}" + moveToOutput "''${targetConfig+$targetConfig/}lib/lib*.a" "''${!outputLib}" fi - for i in "${!outputLib}/${targetConfig}"/lib/*.{la,py}; do - substituteInPlace "$i" --replace "$out" "${!outputLib}" + for i in "''${!outputLib}/''${targetConfig}"/lib/*.{la,py}; do + substituteInPlace "$i" --replace "$out" "''${!outputLib}" done if [ -n "$enableMultilib" ]; then - moveToOutput "${targetConfig+$targetConfig/}lib64/lib*.so*" "${!outputLib}" - moveToOutput "${targetConfig+$targetConfig/}lib64/lib*.la" "${!outputLib}" - moveToOutput "${targetConfig+$targetConfig/}lib64/lib*.dylib" "${!outputLib}" + moveToOutput "''${targetConfig+$targetConfig/}lib64/lib*.so*" "''${!outputLib}" + moveToOutput "''${targetConfig+$targetConfig/}lib64/lib*.la" "''${!outputLib}" + moveToOutput "''${targetConfig+$targetConfig/}lib64/lib*.dylib" "''${!outputLib}" - for i in "${!outputLib}/${targetConfig}"/lib64/*.{la,py}; do - substituteInPlace "$i" --replace "$out" "${!outputLib}" + for i in "''${!outputLib}/''${targetConfig}"/lib64/*.{la,py}; do + substituteInPlace "$i" --replace "$out" "''${!outputLib}" done fi @@ -241,10 +241,10 @@ postInstall() { rm -rf $out/bin/gccbug if type "install_name_tool"; then - for i in "${!outputLib}"/lib/*.*.dylib "${!outputLib}"/lib/*.so.[0-9]; do + for i in "''${!outputLib}"/lib/*.*.dylib "''${!outputLib}"/lib/*.so.[0-9]; do install_name_tool -id "$i" "$i" || true for old_path in $(otool -L "$i" | grep "$out" | awk '{print $1}'); do - new_path=`echo "$old_path" | sed "s,$out,${!outputLib},"` + new_path=`echo "$old_path" | sed "s,$out,''${!outputLib},"` install_name_tool -change "$old_path" "$new_path" "$i" || true done done @@ -255,10 +255,10 @@ postInstall() { # of $dir headers and use it later as `-isysroot`. This prevents # cc-wrapper from overriding libc headers with `-idirafter`. # It should be safe to drop it and rely solely on the cc-wrapper. - local sysinc_dir=$out/${targetConfig+$targetConfig/}sys-include + local sysinc_dir=$out/''${targetConfig+$targetConfig/}sys-include if [ -d "$sysinc_dir" ]; then - chmod -R u+w "$out/${targetConfig+$targetConfig/}sys-include" - rm -rfv "$out/${targetConfig+$targetConfig/}sys-include" + chmod -R u+w "$out/''${targetConfig+$targetConfig/}sys-include" + rm -rfv "$out/''${targetConfig+$targetConfig/}sys-include" fi # Get rid of some "fixed" header files From 1157e1d85625dc1ff035f1781079971ed25dbf59 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Wed, 14 Jun 2023 19:22:35 -0700 Subject: [PATCH 3/9] gcc: add args to common/builder.nix, split up script into phases This commit adds arguments to `builder.nix`, making it a callable function, and splits up the single massive shell script into separate attributes for each phase. It also drops the first two lines and the last line because these are part of the default builder. All script lines which were not part of a phase function have been moved into `preUnpack` since this is the first phase that runs. Subsequent commits will move parts of this to more sensible locations. --- .../compilers/gcc/common/builder.nix | 293 +++++++++--------- 1 file changed, 143 insertions(+), 150 deletions(-) diff --git a/pkgs/development/compilers/gcc/common/builder.nix b/pkgs/development/compilers/gcc/common/builder.nix index 16f319485befd..d8ee1dbfa196d 100644 --- a/pkgs/development/compilers/gcc/common/builder.nix +++ b/pkgs/development/compilers/gcc/common/builder.nix @@ -1,157 +1,156 @@ -if [ -e .attrs.sh ]; then source .attrs.sh; fi -source $stdenv/setup +{ lib +, stdenv +}: +originalAttrs: (stdenv.mkDerivation (finalAttrs: originalAttrs // { + preUnpack = '' + oldOpts="$(shopt -po nounset)" || true + set -euo pipefail -oldOpts="$(shopt -po nounset)" || true -set -euo pipefail + export NIX_FIXINC_DUMMY="$NIX_BUILD_TOP/dummy" + mkdir "$NIX_FIXINC_DUMMY" + if test "$staticCompiler" = "1"; then + EXTRA_LDFLAGS="-static" + else + EXTRA_LDFLAGS="-Wl,-rpath,''${!outputLib}/lib" + fi -export NIX_FIXINC_DUMMY="$NIX_BUILD_TOP/dummy" -mkdir "$NIX_FIXINC_DUMMY" - - -if test "$staticCompiler" = "1"; then - EXTRA_LDFLAGS="-static" -else - EXTRA_LDFLAGS="-Wl,-rpath,''${!outputLib}/lib" -fi - - -# GCC interprets empty paths as ".", which we don't want. -if test -z "''${CPATH-}"; then unset CPATH; fi -if test -z "''${LIBRARY_PATH-}"; then unset LIBRARY_PATH; fi -echo "\$CPATH is \`''${CPATH-}'" -echo "\$LIBRARY_PATH is \`''${LIBRARY_PATH-}'" - -if test "$noSysDirs" = "1"; then - - declare \ - EXTRA_FLAGS_FOR_BUILD EXTRA_FLAGS EXTRA_FLAGS_FOR_TARGET \ - EXTRA_LDFLAGS_FOR_BUILD EXTRA_LDFLAGS_FOR_TARGET - - # Extract flags from Bintools Wrappers - for post in '_FOR_BUILD' ""; do - curBintools="NIX_BINTOOLS''${post}" - - declare -a extraLDFlags=() - if [[ -e "''${!curBintools}/nix-support/orig-libc" ]]; then - # Figure out what extra flags when linking to pass to the gcc - # compilers being generated to make sure that they use our libc. - extraLDFlags=($(< "''${!curBintools}/nix-support/libc-ldflags") $(< "''${!curBintools}/nix-support/libc-ldflags-before" || true)) - if [ -e ''${!curBintools}/nix-support/ld-set-dynamic-linker ]; then - extraLDFlags=-dynamic-linker=$(< ''${!curBintools}/nix-support/dynamic-linker) + # GCC interprets empty paths as ".", which we don't want. + if test -z "''${CPATH-}"; then unset CPATH; fi + if test -z "''${LIBRARY_PATH-}"; then unset LIBRARY_PATH; fi + echo "\$CPATH is \`''${CPATH-}'" + echo "\$LIBRARY_PATH is \`''${LIBRARY_PATH-}'" + + if test "$noSysDirs" = "1"; then + + declare \ + EXTRA_FLAGS_FOR_BUILD EXTRA_FLAGS EXTRA_FLAGS_FOR_TARGET \ + EXTRA_LDFLAGS_FOR_BUILD EXTRA_LDFLAGS_FOR_TARGET + + # Extract flags from Bintools Wrappers + for post in '_FOR_BUILD' ""; do + curBintools="NIX_BINTOOLS''${post}" + + declare -a extraLDFlags=() + if [[ -e "''${!curBintools}/nix-support/orig-libc" ]]; then + # Figure out what extra flags when linking to pass to the gcc + # compilers being generated to make sure that they use our libc. + extraLDFlags=($(< "''${!curBintools}/nix-support/libc-ldflags") $(< "''${!curBintools}/nix-support/libc-ldflags-before" || true)) + if [ -e ''${!curBintools}/nix-support/ld-set-dynamic-linker ]; then + extraLDFlags=-dynamic-linker=$(< ''${!curBintools}/nix-support/dynamic-linker) + fi + + # The path to the Libc binaries such as `crti.o'. + libc_libdir="$(< "''${!curBintools}/nix-support/orig-libc")/lib" + else + # Hack: support impure environments. + extraLDFlags=("-L/usr/lib64" "-L/usr/lib") + libc_libdir="/usr/lib" fi - - # The path to the Libc binaries such as `crti.o'. - libc_libdir="$(< "''${!curBintools}/nix-support/orig-libc")/lib" - else - # Hack: support impure environments. - extraLDFlags=("-L/usr/lib64" "-L/usr/lib") - libc_libdir="/usr/lib" - fi - extraLDFlags=("-L$libc_libdir" "-rpath" "$libc_libdir" - "''${extraLDFlags[@]}") - for i in "''${extraLDFlags[@]}"; do - declare EXTRA_LDFLAGS''${post}+=" -Wl,$i" + extraLDFlags=("-L$libc_libdir" "-rpath" "$libc_libdir" + "''${extraLDFlags[@]}") + for i in "''${extraLDFlags[@]}"; do + declare EXTRA_LDFLAGS''${post}+=" -Wl,$i" + done done - done - # Extract flags from CC Wrappers - for post in '_FOR_BUILD' ""; do - curCC="NIX_CC''${post}" - curFIXINC="NIX_FIXINC_DUMMY''${post}" + # Extract flags from CC Wrappers + for post in '_FOR_BUILD' ""; do + curCC="NIX_CC''${post}" + curFIXINC="NIX_FIXINC_DUMMY''${post}" + + declare -a extraFlags=() + if [[ -e "''${!curCC}/nix-support/orig-libc" ]]; then + # Figure out what extra compiling flags to pass to the gcc compilers + # being generated to make sure that they use our libc. + extraFlags=($(< "''${!curCC}/nix-support/libc-crt1-cflags") $(< "''${!curCC}/nix-support/libc-cflags")) + + # The path to the Libc headers + libc_devdir="$(< "''${!curCC}/nix-support/orig-libc-dev")" + + # Use *real* header files, otherwise a limits.h is generated that + # does not include Libc's limits.h (notably missing SSIZE_MAX, + # which breaks the build). + declare NIX_FIXINC_DUMMY''${post}="$libc_devdir/include" + else + # Hack: support impure environments. + extraFlags=("-isystem" "/usr/include") + declare NIX_FIXINC_DUMMY''${post}=/usr/include + fi - declare -a extraFlags=() - if [[ -e "''${!curCC}/nix-support/orig-libc" ]]; then - # Figure out what extra compiling flags to pass to the gcc compilers - # being generated to make sure that they use our libc. - extraFlags=($(< "''${!curCC}/nix-support/libc-crt1-cflags") $(< "''${!curCC}/nix-support/libc-cflags")) + extraFlags=("-I''${!curFIXINC}" "''${extraFlags[@]}") + + # BOOT_CFLAGS defaults to `-g -O2'; since we override it below, make + # sure to explictly add them so that files compiled with the bootstrap + # compiler are optimized and (optionally) contain debugging information + # (info "(gccinstall) Building"). + if test -n "''${dontStrip-}"; then + extraFlags=("-O2" "-g" "''${extraFlags[@]}") + else + # Don't pass `-g' at all; this saves space while building. + extraFlags=("-O2" "''${extraFlags[@]}") + fi - # The path to the Libc headers - libc_devdir="$(< "''${!curCC}/nix-support/orig-libc-dev")" + declare EXTRA_FLAGS''${post}="''${extraFlags[*]}" + done - # Use *real* header files, otherwise a limits.h is generated that - # does not include Libc's limits.h (notably missing SSIZE_MAX, - # which breaks the build). - declare NIX_FIXINC_DUMMY''${post}="$libc_devdir/include" - else - # Hack: support impure environments. - extraFlags=("-isystem" "/usr/include") - declare NIX_FIXINC_DUMMY''${post}=/usr/include + if test -z "''${targetConfig-}"; then + # host = target, so the flags are the same + EXTRA_FLAGS_FOR_TARGET="$EXTRA_FLAGS" + EXTRA_LDFLAGS_FOR_TARGET="$EXTRA_LDFLAGS" fi - extraFlags=("-I''${!curFIXINC}" "''${extraFlags[@]}") + # CFLAGS_FOR_TARGET are needed for the libstdc++ configure script to find + # the startfiles. + # FLAGS_FOR_TARGET are needed for the target libraries to receive the -Bxxx + # for the startfiles. + makeFlagsArray+=( + "BUILD_SYSTEM_HEADER_DIR=$NIX_FIXINC_DUMMY_FOR_BUILD" + "SYSTEM_HEADER_DIR=$NIX_FIXINC_DUMMY_FOR_BUILD" + "NATIVE_SYSTEM_HEADER_DIR=$NIX_FIXINC_DUMMY" - # BOOT_CFLAGS defaults to `-g -O2'; since we override it below, make - # sure to explictly add them so that files compiled with the bootstrap - # compiler are optimized and (optionally) contain debugging information - # (info "(gccinstall) Building"). - if test -n "''${dontStrip-}"; then - extraFlags=("-O2" "-g" "''${extraFlags[@]}") - else - # Don't pass `-g' at all; this saves space while building. - extraFlags=("-O2" "''${extraFlags[@]}") - fi + "LDFLAGS_FOR_BUILD=$EXTRA_LDFLAGS_FOR_BUILD" + #"LDFLAGS=$EXTRA_LDFLAGS" + "LDFLAGS_FOR_TARGET=$EXTRA_LDFLAGS_FOR_TARGET" - declare EXTRA_FLAGS''${post}="''${extraFlags[*]}" - done + "CFLAGS_FOR_BUILD=$EXTRA_FLAGS_FOR_BUILD $EXTRA_LDFLAGS_FOR_BUILD" + "CXXFLAGS_FOR_BUILD=$EXTRA_FLAGS_FOR_BUILD $EXTRA_LDFLAGS_FOR_BUILD" + "FLAGS_FOR_BUILD=$EXTRA_FLAGS_FOR_BUILD $EXTRA_LDFLAGS_FOR_BUILD" - if test -z "''${targetConfig-}"; then - # host = target, so the flags are the same - EXTRA_FLAGS_FOR_TARGET="$EXTRA_FLAGS" - EXTRA_LDFLAGS_FOR_TARGET="$EXTRA_LDFLAGS" - fi + # It seems there is a bug in GCC 5 + #"CFLAGS=$EXTRA_FLAGS $EXTRA_LDFLAGS" + #"CXXFLAGS=$EXTRA_FLAGS $EXTRA_LDFLAGS" - # CFLAGS_FOR_TARGET are needed for the libstdc++ configure script to find - # the startfiles. - # FLAGS_FOR_TARGET are needed for the target libraries to receive the -Bxxx - # for the startfiles. - makeFlagsArray+=( - "BUILD_SYSTEM_HEADER_DIR=$NIX_FIXINC_DUMMY_FOR_BUILD" - "SYSTEM_HEADER_DIR=$NIX_FIXINC_DUMMY_FOR_BUILD" - "NATIVE_SYSTEM_HEADER_DIR=$NIX_FIXINC_DUMMY" - - "LDFLAGS_FOR_BUILD=$EXTRA_LDFLAGS_FOR_BUILD" - #"LDFLAGS=$EXTRA_LDFLAGS" - "LDFLAGS_FOR_TARGET=$EXTRA_LDFLAGS_FOR_TARGET" - - "CFLAGS_FOR_BUILD=$EXTRA_FLAGS_FOR_BUILD $EXTRA_LDFLAGS_FOR_BUILD" - "CXXFLAGS_FOR_BUILD=$EXTRA_FLAGS_FOR_BUILD $EXTRA_LDFLAGS_FOR_BUILD" - "FLAGS_FOR_BUILD=$EXTRA_FLAGS_FOR_BUILD $EXTRA_LDFLAGS_FOR_BUILD" - - # It seems there is a bug in GCC 5 - #"CFLAGS=$EXTRA_FLAGS $EXTRA_LDFLAGS" - #"CXXFLAGS=$EXTRA_FLAGS $EXTRA_LDFLAGS" - - "CFLAGS_FOR_TARGET=$EXTRA_FLAGS_FOR_TARGET $EXTRA_LDFLAGS_FOR_TARGET" - "CXXFLAGS_FOR_TARGET=$EXTRA_FLAGS_FOR_TARGET $EXTRA_LDFLAGS_FOR_TARGET" - "FLAGS_FOR_TARGET=$EXTRA_FLAGS_FOR_TARGET $EXTRA_LDFLAGS_FOR_TARGET" - ) - - if test -z "''${targetConfig-}"; then - makeFlagsArray+=( - "BOOT_CFLAGS=$EXTRA_FLAGS $EXTRA_LDFLAGS" - "BOOT_LDFLAGS=$EXTRA_FLAGS_FOR_TARGET $EXTRA_LDFLAGS_FOR_TARGET" + "CFLAGS_FOR_TARGET=$EXTRA_FLAGS_FOR_TARGET $EXTRA_LDFLAGS_FOR_TARGET" + "CXXFLAGS_FOR_TARGET=$EXTRA_FLAGS_FOR_TARGET $EXTRA_LDFLAGS_FOR_TARGET" + "FLAGS_FOR_TARGET=$EXTRA_FLAGS_FOR_TARGET $EXTRA_LDFLAGS_FOR_TARGET" ) - fi - if test "$crossStageStatic" == 1; then - # We don't want the gcc build to assume there will be a libc providing - # limits.h in this stage - makeFlagsArray+=( - 'LIMITS_H_TEST=false' - ) - else - makeFlagsArray+=( - 'LIMITS_H_TEST=true' - ) + if test -z "''${targetConfig-}"; then + makeFlagsArray+=( + "BOOT_CFLAGS=$EXTRA_FLAGS $EXTRA_LDFLAGS" + "BOOT_LDFLAGS=$EXTRA_FLAGS_FOR_TARGET $EXTRA_LDFLAGS_FOR_TARGET" + ) + fi + + if test "$crossStageStatic" == 1; then + # We don't want the gcc build to assume there will be a libc providing + # limits.h in this stage + makeFlagsArray+=( + 'LIMITS_H_TEST=false' + ) + else + makeFlagsArray+=( + 'LIMITS_H_TEST=true' + ) + fi fi -fi -eval "$oldOpts" + eval "$oldOpts" + ''; -providedPreConfigure="$preConfigure"; -preConfigure() { + preConfigure = (originalAttrs.preConfigure or "") + '' if test -n "$newlibSrc"; then tar xvf "$newlibSrc" -C .. ln -s ../newlib-*/newlib newlib @@ -174,23 +173,19 @@ preConfigure() { configureFlags="$configureFlags --with-build-sysroot=`pwd`/.." fi - # Eval the preConfigure script from nix expression. - eval "$providedPreConfigure" - # Perform the build in a different directory. mkdir ../build cd ../build configureScript=../$sourceRoot/configure -} - - -postConfigure() { - # Don't store the configure flags in the resulting executables. - sed -e '/TOPLEVEL_CONFIGURE_ARGUMENTS=/d' -i Makefile -} + ''; + postConfigure = '' + # Avoid store paths when embedding ./configure flags into gcc. + # Mangled arguments are still useful when reporting bugs upstream. + sed -e "/TOPLEVEL_CONFIGURE_ARGUMENTS=/ s|$NIX_STORE/[a-z0-9]\{32\}-|$NIX_STORE/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-|g" -i Makefile + ''; -preInstall() { + preInstall = '' mkdir -p "$out/''${targetConfig}/lib" mkdir -p "''${!outputLib}/''${targetConfig}/lib" # Make ‘lib64’ symlinks to ‘lib’. @@ -203,10 +198,9 @@ preInstall() { ln -s lib "$out/''${targetConfig}/lib32" ln -s lib "''${!outputLib}/''${targetConfig}/lib32" fi -} + ''; - -postInstall() { + postInstall = '' # Move runtime libraries to lib output. moveToOutput "''${targetConfig+$targetConfig/}lib/lib*.so*" "''${!outputLib}" moveToOutput "''${targetConfig+$targetConfig/}lib/lib*.la" "''${!outputLib}" @@ -284,6 +278,5 @@ postInstall() { ln -sf "$man_prefix"gcc.1 "$i" fi done -} - -genericBuild + ''; +})) From c413f5a6c104ab62c41fb1abba919858a8fac56a Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Wed, 14 Jun 2023 19:26:28 -0700 Subject: [PATCH 4/9] gcc: remove `builder = ../builder.sh` from gcc/${version}/default.nix This commit deletes the custom builder attribute from all gcc versions. --- pkgs/development/compilers/gcc/10/default.nix | 2 -- pkgs/development/compilers/gcc/11/default.nix | 2 -- pkgs/development/compilers/gcc/12/default.nix | 2 -- pkgs/development/compilers/gcc/13/default.nix | 2 -- pkgs/development/compilers/gcc/4.8/default.nix | 2 -- pkgs/development/compilers/gcc/4.9/default.nix | 2 -- pkgs/development/compilers/gcc/6/default.nix | 2 -- pkgs/development/compilers/gcc/7/default.nix | 2 -- pkgs/development/compilers/gcc/8/default.nix | 2 -- pkgs/development/compilers/gcc/9/default.nix | 2 -- 10 files changed, 20 deletions(-) diff --git a/pkgs/development/compilers/gcc/10/default.nix b/pkgs/development/compilers/gcc/10/default.nix index c61093c67c03a..1069ab96b1317 100644 --- a/pkgs/development/compilers/gcc/10/default.nix +++ b/pkgs/development/compilers/gcc/10/default.nix @@ -148,8 +148,6 @@ lib.pipe (stdenv.mkDerivation ({ pname = "${crossNameAddon}${name}"; inherit version; - builder = ../builder.sh; - src = fetchurl { url = "mirror://gcc/releases/gcc-${version}/gcc-${version}.tar.xz"; sha256 = "1wg4xdizkksmwi66mvv2v4pk3ja8x64m7v9gzhykzd3wrmdpsaf9"; diff --git a/pkgs/development/compilers/gcc/11/default.nix b/pkgs/development/compilers/gcc/11/default.nix index 92abdebe49b3c..533da464ad46d 100644 --- a/pkgs/development/compilers/gcc/11/default.nix +++ b/pkgs/development/compilers/gcc/11/default.nix @@ -161,8 +161,6 @@ lib.pipe (stdenv.mkDerivation ({ pname = "${crossNameAddon}${name}"; inherit version; - builder = ../builder.sh; - src = fetchurl { url = "mirror://gcc/releases/gcc-${version}/gcc-${version}.tar.xz"; hash = "sha256-Py2yIrAH6KSiPNW6VnJu8I6LHx6yBV7nLBQCzqc6jdk="; diff --git a/pkgs/development/compilers/gcc/12/default.nix b/pkgs/development/compilers/gcc/12/default.nix index 9665c2a9fe85b..02a594be2b57b 100644 --- a/pkgs/development/compilers/gcc/12/default.nix +++ b/pkgs/development/compilers/gcc/12/default.nix @@ -205,8 +205,6 @@ lib.pipe (stdenv.mkDerivation ({ pname = "${crossNameAddon}${name}"; inherit version; - builder = ../builder.sh; - src = fetchurl { url = "mirror://gcc/releases/gcc-${version}/gcc-${version}.tar.xz"; sha256 = "sha256-lJpdT5nnhkIak7Uysi/6tVeN5zITaZdbka7Jet/ajDs="; diff --git a/pkgs/development/compilers/gcc/13/default.nix b/pkgs/development/compilers/gcc/13/default.nix index 1b73c251ce6f8..60200bc1e6eaf 100644 --- a/pkgs/development/compilers/gcc/13/default.nix +++ b/pkgs/development/compilers/gcc/13/default.nix @@ -199,8 +199,6 @@ lib.pipe (stdenv.mkDerivation ({ pname = "${crossNameAddon}${name}"; inherit version; - builder = ../builder.sh; - src = fetchurl { url = "mirror://gcc/releases/gcc-${version}/gcc-${version}.tar.xz"; sha256 = "sha256-YdaE8Kpedqxlha2ImKJCeq3ol57V5/hUkihsTfwT7oY="; diff --git a/pkgs/development/compilers/gcc/4.8/default.nix b/pkgs/development/compilers/gcc/4.8/default.nix index fa856eff96e5f..10a5d7e6a89a1 100644 --- a/pkgs/development/compilers/gcc/4.8/default.nix +++ b/pkgs/development/compilers/gcc/4.8/default.nix @@ -197,8 +197,6 @@ lib.pipe (stdenv.mkDerivation ({ pname = "${crossNameAddon}${name}"; inherit version; - builder = ../builder.sh; - src = fetchurl { url = "mirror://gnu/gcc/gcc-${version}/gcc-${version}.tar.bz2"; sha256 = "08yggr18v373a1ihj0rg2vd6psnic42b518xcgp3r9k81xz1xyr2"; diff --git a/pkgs/development/compilers/gcc/4.9/default.nix b/pkgs/development/compilers/gcc/4.9/default.nix index bab79f968db38..1e3c284e0b194 100644 --- a/pkgs/development/compilers/gcc/4.9/default.nix +++ b/pkgs/development/compilers/gcc/4.9/default.nix @@ -214,8 +214,6 @@ lib.pipe (stdenv.mkDerivation ({ pname = "${crossNameAddon}${name}"; inherit version; - builder = ../builder.sh; - src = fetchurl { url = "mirror://gnu/gcc/gcc-${version}/gcc-${version}.tar.bz2"; sha256 = "14l06m7nvcvb0igkbip58x59w3nq6315k6jcz3wr9ch1rn9d44bc"; diff --git a/pkgs/development/compilers/gcc/6/default.nix b/pkgs/development/compilers/gcc/6/default.nix index f443babb4b706..e7c18c8bd6960 100644 --- a/pkgs/development/compilers/gcc/6/default.nix +++ b/pkgs/development/compilers/gcc/6/default.nix @@ -203,8 +203,6 @@ lib.pipe (stdenv.mkDerivation ({ pname = "${crossNameAddon}${name}"; inherit version; - builder = ../builder.sh; - src = if stdenv.targetPlatform.isVc4 then fetchFromGitHub { owner = "itszor"; repo = "gcc-vc4"; diff --git a/pkgs/development/compilers/gcc/7/default.nix b/pkgs/development/compilers/gcc/7/default.nix index 5b6ea7ead50a5..d677ab5d58d4d 100644 --- a/pkgs/development/compilers/gcc/7/default.nix +++ b/pkgs/development/compilers/gcc/7/default.nix @@ -153,8 +153,6 @@ lib.pipe (stdenv.mkDerivation ({ pname = "${crossNameAddon}${name}"; inherit version; - builder = ../builder.sh; - src = fetchurl { url = "mirror://gcc/releases/gcc-${version}/gcc-${version}.tar.xz"; sha256 = "0qg6kqc5l72hpnj4vr6l0p69qav0rh4anlkk3y55540zy3klc6dq"; diff --git a/pkgs/development/compilers/gcc/8/default.nix b/pkgs/development/compilers/gcc/8/default.nix index f903e264b0af6..f008f80c61143 100644 --- a/pkgs/development/compilers/gcc/8/default.nix +++ b/pkgs/development/compilers/gcc/8/default.nix @@ -134,8 +134,6 @@ lib.pipe (stdenv.mkDerivation ({ pname = "${crossNameAddon}${name}"; inherit version; - builder = ../builder.sh; - src = fetchurl { url = "mirror://gcc/releases/gcc-${version}/gcc-${version}.tar.xz"; sha256 = "0l7d4m9jx124xsk6xardchgy2k5j5l2b15q322k31f0va4d8826k"; diff --git a/pkgs/development/compilers/gcc/9/default.nix b/pkgs/development/compilers/gcc/9/default.nix index 289212a136356..d0289f6d65beb 100644 --- a/pkgs/development/compilers/gcc/9/default.nix +++ b/pkgs/development/compilers/gcc/9/default.nix @@ -148,8 +148,6 @@ lib.pipe (stdenv.mkDerivation ({ pname = "${crossNameAddon}${name}"; inherit version; - builder = ../builder.sh; - src = fetchurl { url = "mirror://gcc/releases/gcc-${version}/gcc-${version}.tar.xz"; sha256 = "13ygjmd938m0wmy946pxdhz9i1wq7z4w10l6pvidak0xxxj9yxi7"; From e3f05c22aa70784b146d681b68bec8aab86c8e39 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Wed, 14 Jun 2023 19:45:26 -0700 Subject: [PATCH 5/9] gcc: use common/builder.nix This commit replaces `stdenv.mkDerivation` with `(callPackage ../common/builder.nix {})` in all versions of gcc. --- pkgs/development/compilers/gcc/10/default.nix | 2 +- pkgs/development/compilers/gcc/11/default.nix | 2 +- pkgs/development/compilers/gcc/12/default.nix | 2 +- pkgs/development/compilers/gcc/13/default.nix | 2 +- pkgs/development/compilers/gcc/4.8/default.nix | 2 +- pkgs/development/compilers/gcc/4.9/default.nix | 2 +- pkgs/development/compilers/gcc/6/default.nix | 2 +- pkgs/development/compilers/gcc/7/default.nix | 2 +- pkgs/development/compilers/gcc/8/default.nix | 2 +- pkgs/development/compilers/gcc/9/default.nix | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pkgs/development/compilers/gcc/10/default.nix b/pkgs/development/compilers/gcc/10/default.nix index 1069ab96b1317..31b35b49cdf3b 100644 --- a/pkgs/development/compilers/gcc/10/default.nix +++ b/pkgs/development/compilers/gcc/10/default.nix @@ -144,7 +144,7 @@ let majorVersion = "10"; in -lib.pipe (stdenv.mkDerivation ({ +lib.pipe ((callPackage ../common/builder.nix {}) ({ pname = "${crossNameAddon}${name}"; inherit version; diff --git a/pkgs/development/compilers/gcc/11/default.nix b/pkgs/development/compilers/gcc/11/default.nix index 533da464ad46d..ec283828e4c85 100644 --- a/pkgs/development/compilers/gcc/11/default.nix +++ b/pkgs/development/compilers/gcc/11/default.nix @@ -157,7 +157,7 @@ let majorVersion = "11"; in -lib.pipe (stdenv.mkDerivation ({ +lib.pipe ((callPackage ../common/builder.nix {}) ({ pname = "${crossNameAddon}${name}"; inherit version; diff --git a/pkgs/development/compilers/gcc/12/default.nix b/pkgs/development/compilers/gcc/12/default.nix index 02a594be2b57b..b0a298ec08ef6 100644 --- a/pkgs/development/compilers/gcc/12/default.nix +++ b/pkgs/development/compilers/gcc/12/default.nix @@ -201,7 +201,7 @@ let majorVersion = "12"; in -lib.pipe (stdenv.mkDerivation ({ +lib.pipe ((callPackage ../common/builder.nix {}) ({ pname = "${crossNameAddon}${name}"; inherit version; diff --git a/pkgs/development/compilers/gcc/13/default.nix b/pkgs/development/compilers/gcc/13/default.nix index 60200bc1e6eaf..4cf0919c56160 100644 --- a/pkgs/development/compilers/gcc/13/default.nix +++ b/pkgs/development/compilers/gcc/13/default.nix @@ -195,7 +195,7 @@ let majorVersion = "13"; in -lib.pipe (stdenv.mkDerivation ({ +lib.pipe ((callPackage ../common/builder.nix {}) ({ pname = "${crossNameAddon}${name}"; inherit version; diff --git a/pkgs/development/compilers/gcc/4.8/default.nix b/pkgs/development/compilers/gcc/4.8/default.nix index 10a5d7e6a89a1..c047f58845b68 100644 --- a/pkgs/development/compilers/gcc/4.8/default.nix +++ b/pkgs/development/compilers/gcc/4.8/default.nix @@ -193,7 +193,7 @@ in # We need all these X libraries when building AWT with GTK. assert x11Support -> (filter (x: x == null) ([ gtk2 libart_lgpl ] ++ xlibs)) == []; -lib.pipe (stdenv.mkDerivation ({ +lib.pipe ((callPackage ../common/builder.nix {}) ({ pname = "${crossNameAddon}${name}"; inherit version; diff --git a/pkgs/development/compilers/gcc/4.9/default.nix b/pkgs/development/compilers/gcc/4.9/default.nix index 1e3c284e0b194..fe12933750654 100644 --- a/pkgs/development/compilers/gcc/4.9/default.nix +++ b/pkgs/development/compilers/gcc/4.9/default.nix @@ -210,7 +210,7 @@ in # We need all these X libraries when building AWT with GTK. assert x11Support -> (filter (x: x == null) ([ gtk2 libart_lgpl ] ++ xlibs)) == []; -lib.pipe (stdenv.mkDerivation ({ +lib.pipe ((callPackage ../common/builder.nix {}) ({ pname = "${crossNameAddon}${name}"; inherit version; diff --git a/pkgs/development/compilers/gcc/6/default.nix b/pkgs/development/compilers/gcc/6/default.nix index e7c18c8bd6960..2ad2a79cad6a1 100644 --- a/pkgs/development/compilers/gcc/6/default.nix +++ b/pkgs/development/compilers/gcc/6/default.nix @@ -199,7 +199,7 @@ in # We need all these X libraries when building AWT with GTK. assert x11Support -> (filter (x: x == null) ([ gtk2 libart_lgpl ] ++ xlibs)) == []; -lib.pipe (stdenv.mkDerivation ({ +lib.pipe ((callPackage ../common/builder.nix {}) ({ pname = "${crossNameAddon}${name}"; inherit version; diff --git a/pkgs/development/compilers/gcc/7/default.nix b/pkgs/development/compilers/gcc/7/default.nix index d677ab5d58d4d..e341c57ec7dd6 100644 --- a/pkgs/development/compilers/gcc/7/default.nix +++ b/pkgs/development/compilers/gcc/7/default.nix @@ -149,7 +149,7 @@ let majorVersion = "7"; in -lib.pipe (stdenv.mkDerivation ({ +lib.pipe ((callPackage ../common/builder.nix {}) ({ pname = "${crossNameAddon}${name}"; inherit version; diff --git a/pkgs/development/compilers/gcc/8/default.nix b/pkgs/development/compilers/gcc/8/default.nix index f008f80c61143..59be3ecc8a8b7 100644 --- a/pkgs/development/compilers/gcc/8/default.nix +++ b/pkgs/development/compilers/gcc/8/default.nix @@ -130,7 +130,7 @@ let majorVersion = "8"; in -lib.pipe (stdenv.mkDerivation ({ +lib.pipe ((callPackage ../common/builder.nix {}) ({ pname = "${crossNameAddon}${name}"; inherit version; diff --git a/pkgs/development/compilers/gcc/9/default.nix b/pkgs/development/compilers/gcc/9/default.nix index d0289f6d65beb..512047d4c4f66 100644 --- a/pkgs/development/compilers/gcc/9/default.nix +++ b/pkgs/development/compilers/gcc/9/default.nix @@ -144,7 +144,7 @@ let majorVersion = "9"; in -lib.pipe (stdenv.mkDerivation ({ +lib.pipe ((callPackage ../common/builder.nix {}) ({ pname = "${crossNameAddon}${name}"; inherit version; From 67da7b9a1f5d7320e05c7cfa3da2458f15806a14 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Wed, 14 Jun 2023 23:05:37 -0700 Subject: [PATCH 6/9] gcc: remove builder.sh --- pkgs/development/compilers/gcc/builder.sh | 290 ------------------ .../compilers/gcc/common/builder.nix | 4 +- 2 files changed, 2 insertions(+), 292 deletions(-) delete mode 100644 pkgs/development/compilers/gcc/builder.sh diff --git a/pkgs/development/compilers/gcc/builder.sh b/pkgs/development/compilers/gcc/builder.sh deleted file mode 100644 index d9016c45e5794..0000000000000 --- a/pkgs/development/compilers/gcc/builder.sh +++ /dev/null @@ -1,290 +0,0 @@ -if [ -e .attrs.sh ]; then source .attrs.sh; fi -source $stdenv/setup - - -oldOpts="$(shopt -po nounset)" || true -set -euo pipefail - - -export NIX_FIXINC_DUMMY="$NIX_BUILD_TOP/dummy" -mkdir "$NIX_FIXINC_DUMMY" - - -if test "$staticCompiler" = "1"; then - EXTRA_LDFLAGS="-static" -else - EXTRA_LDFLAGS="-Wl,-rpath,${!outputLib}/lib" -fi - - -# GCC interprets empty paths as ".", which we don't want. -if test -z "${CPATH-}"; then unset CPATH; fi -if test -z "${LIBRARY_PATH-}"; then unset LIBRARY_PATH; fi -echo "\$CPATH is \`${CPATH-}'" -echo "\$LIBRARY_PATH is \`${LIBRARY_PATH-}'" - -if test "$noSysDirs" = "1"; then - - declare \ - EXTRA_FLAGS_FOR_BUILD EXTRA_FLAGS EXTRA_FLAGS_FOR_TARGET \ - EXTRA_LDFLAGS_FOR_BUILD EXTRA_LDFLAGS_FOR_TARGET - - # Extract flags from Bintools Wrappers - for post in '_FOR_BUILD' ''; do - curBintools="NIX_BINTOOLS${post}" - - declare -a extraLDFlags=() - if [[ -e "${!curBintools}/nix-support/orig-libc" ]]; then - # Figure out what extra flags when linking to pass to the gcc - # compilers being generated to make sure that they use our libc. - extraLDFlags=($(< "${!curBintools}/nix-support/libc-ldflags") $(< "${!curBintools}/nix-support/libc-ldflags-before" || true)) - if [ -e ${!curBintools}/nix-support/ld-set-dynamic-linker ]; then - extraLDFlags=-dynamic-linker=$(< ${!curBintools}/nix-support/dynamic-linker) - fi - - # The path to the Libc binaries such as `crti.o'. - libc_libdir="$(< "${!curBintools}/nix-support/orig-libc")/lib" - else - # Hack: support impure environments. - extraLDFlags=("-L/usr/lib64" "-L/usr/lib") - libc_libdir="/usr/lib" - fi - extraLDFlags=("-L$libc_libdir" "-rpath" "$libc_libdir" - "${extraLDFlags[@]}") - for i in "${extraLDFlags[@]}"; do - declare EXTRA_LDFLAGS${post}+=" -Wl,$i" - done - done - - # Extract flags from CC Wrappers - for post in '_FOR_BUILD' ''; do - curCC="NIX_CC${post}" - curFIXINC="NIX_FIXINC_DUMMY${post}" - - declare -a extraFlags=() - if [[ -e "${!curCC}/nix-support/orig-libc" ]]; then - # Figure out what extra compiling flags to pass to the gcc compilers - # being generated to make sure that they use our libc. - extraFlags=($(< "${!curCC}/nix-support/libc-crt1-cflags") $(< "${!curCC}/nix-support/libc-cflags")) - - # The path to the Libc headers - libc_devdir="$(< "${!curCC}/nix-support/orig-libc-dev")" - - # Use *real* header files, otherwise a limits.h is generated that - # does not include Libc's limits.h (notably missing SSIZE_MAX, - # which breaks the build). - declare NIX_FIXINC_DUMMY${post}="$libc_devdir/include" - else - # Hack: support impure environments. - extraFlags=("-isystem" "/usr/include") - declare NIX_FIXINC_DUMMY${post}=/usr/include - fi - - extraFlags=("-I${!curFIXINC}" "${extraFlags[@]}") - - # BOOT_CFLAGS defaults to `-g -O2'; since we override it below, make - # sure to explictly add them so that files compiled with the bootstrap - # compiler are optimized and (optionally) contain debugging information - # (info "(gccinstall) Building"). - if test -n "${dontStrip-}"; then - extraFlags=("-O2" "-g" "${extraFlags[@]}") - else - # Don't pass `-g' at all; this saves space while building. - extraFlags=("-O2" "${extraFlags[@]}") - fi - - declare EXTRA_FLAGS${post}="${extraFlags[*]}" - done - - if test -z "${targetConfig-}"; then - # host = target, so the flags are the same - EXTRA_FLAGS_FOR_TARGET="$EXTRA_FLAGS" - EXTRA_LDFLAGS_FOR_TARGET="$EXTRA_LDFLAGS" - fi - - # CFLAGS_FOR_TARGET are needed for the libstdc++ configure script to find - # the startfiles. - # FLAGS_FOR_TARGET are needed for the target libraries to receive the -Bxxx - # for the startfiles. - makeFlagsArray+=( - "BUILD_SYSTEM_HEADER_DIR=$NIX_FIXINC_DUMMY_FOR_BUILD" - "SYSTEM_HEADER_DIR=$NIX_FIXINC_DUMMY_FOR_BUILD" - "NATIVE_SYSTEM_HEADER_DIR=$NIX_FIXINC_DUMMY" - - "LDFLAGS_FOR_BUILD=$EXTRA_LDFLAGS_FOR_BUILD" - #"LDFLAGS=$EXTRA_LDFLAGS" - "LDFLAGS_FOR_TARGET=$EXTRA_LDFLAGS_FOR_TARGET" - - "CFLAGS_FOR_BUILD=$EXTRA_FLAGS_FOR_BUILD $EXTRA_LDFLAGS_FOR_BUILD" - "CXXFLAGS_FOR_BUILD=$EXTRA_FLAGS_FOR_BUILD $EXTRA_LDFLAGS_FOR_BUILD" - "FLAGS_FOR_BUILD=$EXTRA_FLAGS_FOR_BUILD $EXTRA_LDFLAGS_FOR_BUILD" - - # It seems there is a bug in GCC 5 - #"CFLAGS=$EXTRA_FLAGS $EXTRA_LDFLAGS" - #"CXXFLAGS=$EXTRA_FLAGS $EXTRA_LDFLAGS" - - "CFLAGS_FOR_TARGET=$EXTRA_FLAGS_FOR_TARGET $EXTRA_LDFLAGS_FOR_TARGET" - "CXXFLAGS_FOR_TARGET=$EXTRA_FLAGS_FOR_TARGET $EXTRA_LDFLAGS_FOR_TARGET" - "FLAGS_FOR_TARGET=$EXTRA_FLAGS_FOR_TARGET $EXTRA_LDFLAGS_FOR_TARGET" - ) - - if test -z "${targetConfig-}"; then - makeFlagsArray+=( - "BOOT_CFLAGS=$EXTRA_FLAGS $EXTRA_LDFLAGS" - "BOOT_LDFLAGS=$EXTRA_FLAGS_FOR_TARGET $EXTRA_LDFLAGS_FOR_TARGET" - ) - fi - - if test "$withoutTargetLibc" == 1; then - # We don't want the gcc build to assume there will be a libc providing - # limits.h in this stage - makeFlagsArray+=( - 'LIMITS_H_TEST=false' - ) - else - makeFlagsArray+=( - 'LIMITS_H_TEST=true' - ) - fi -fi - -eval "$oldOpts" - -providedPreConfigure="$preConfigure"; -preConfigure() { - if test -n "$newlibSrc"; then - tar xvf "$newlibSrc" -C .. - ln -s ../newlib-*/newlib newlib - # Patch to get armvt5el working: - sed -i -e 's/ arm)/ arm*)/' newlib/configure.host - fi - - # Bug - they packaged zlib - if test -d "zlib"; then - # This breaks the build without-headers, which should build only - # the target libgcc as target libraries. - # See 'configure:5370' - rm -Rf zlib - fi - - if test -n "$crossMingw" -a -n "$withoutTargetLibc"; then - mkdir -p ../mingw - # --with-build-sysroot expects that: - cp -R $libcCross/include ../mingw - configureFlags="$configureFlags --with-build-sysroot=`pwd`/.." - fi - - # Eval the preConfigure script from nix expression. - eval "$providedPreConfigure" - - # Perform the build in a different directory. - mkdir ../build - cd ../build - configureScript=../$sourceRoot/configure -} - - -postConfigure() { - # Avoid store paths when embedding ./configure flags into gcc. - # Mangled arguments are still useful when reporting bugs upstream. - sed -e "/TOPLEVEL_CONFIGURE_ARGUMENTS=/ s|$NIX_STORE/[a-z0-9]\{32\}-|$NIX_STORE/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-|g" -i Makefile -} - - -preInstall() { - mkdir -p "$out/${targetConfig}/lib" - mkdir -p "${!outputLib}/${targetConfig}/lib" - # Make ‘lib64’ symlinks to ‘lib’. - if [ -n "$linkLib64toLib" ]; then - ln -s lib "$out/${targetConfig}/lib64" - ln -s lib "${!outputLib}/${targetConfig}/lib64" - fi - # Make ‘lib32’ symlinks to ‘lib’. - if [ -n "$linkLib32toLib" ]; then - ln -s lib "$out/${targetConfig}/lib32" - ln -s lib "${!outputLib}/${targetConfig}/lib32" - fi -} - - -postInstall() { - # Move runtime libraries to lib output. - moveToOutput "${targetConfig+$targetConfig/}lib/lib*.so*" "${!outputLib}" - moveToOutput "${targetConfig+$targetConfig/}lib/lib*.la" "${!outputLib}" - moveToOutput "${targetConfig+$targetConfig/}lib/lib*.dylib" "${!outputLib}" - moveToOutput "${targetConfig+$targetConfig/}lib/lib*.dll.a" "${!outputLib}" - moveToOutput "share/gcc-*/python" "${!outputLib}" - - if [ -z "$enableShared" ]; then - moveToOutput "${targetConfig+$targetConfig/}lib/lib*.a" "${!outputLib}" - fi - - for i in "${!outputLib}/${targetConfig}"/lib/*.{la,py}; do - substituteInPlace "$i" --replace "$out" "${!outputLib}" - done - - if [ -n "$enableMultilib" ]; then - moveToOutput "${targetConfig+$targetConfig/}lib64/lib*.so*" "${!outputLib}" - moveToOutput "${targetConfig+$targetConfig/}lib64/lib*.la" "${!outputLib}" - moveToOutput "${targetConfig+$targetConfig/}lib64/lib*.dylib" "${!outputLib}" - - for i in "${!outputLib}/${targetConfig}"/lib64/*.{la,py}; do - substituteInPlace "$i" --replace "$out" "${!outputLib}" - done - fi - - # Remove `fixincl' to prevent a retained dependency on the - # previous gcc. - rm -rf $out/libexec/gcc/*/*/install-tools - rm -rf $out/lib/gcc/*/*/install-tools - - # More dependencies with the previous gcc or some libs (gccbug stores the build command line) - rm -rf $out/bin/gccbug - - if type "install_name_tool"; then - for i in "${!outputLib}"/lib/*.*.dylib "${!outputLib}"/lib/*.so.[0-9]; do - install_name_tool -id "$i" "$i" || true - for old_path in $(otool -L "$i" | grep "$out" | awk '{print $1}'); do - new_path=`echo "$old_path" | sed "s,$out,${!outputLib},"` - install_name_tool -change "$old_path" "$new_path" "$i" || true - done - done - fi - - # Cross-compiler specific: - # --with-headers=$dir option triggers gcc to make a private copy - # of $dir headers and use it later as `-isysroot`. This prevents - # cc-wrapper from overriding libc headers with `-idirafter`. - # It should be safe to drop it and rely solely on the cc-wrapper. - local sysinc_dir=$out/${targetConfig+$targetConfig/}sys-include - if [ -d "$sysinc_dir" ]; then - chmod -R u+w "$out/${targetConfig+$targetConfig/}sys-include" - rm -rfv "$out/${targetConfig+$targetConfig/}sys-include" - fi - - # Get rid of some "fixed" header files - rm -rfv $out/lib/gcc/*/*/include-fixed/{root,linux,sys/mount.h,bits/statx.h} - - # Replace hard links for i686-pc-linux-gnu-gcc etc. with symlinks. - for i in $out/bin/*-gcc*; do - if cmp -s $out/bin/gcc $i; then - ln -sfn gcc $i - fi - done - - for i in $out/bin/c++ $out/bin/*-c++* $out/bin/*-g++*; do - if cmp -s $out/bin/g++ $i; then - ln -sfn g++ $i - fi - done - - # Two identical man pages are shipped (moving and compressing is done later) - for i in "$out"/share/man/man1/*g++.1; do - if test -e "$i"; then - man_prefix=`echo "$i" | sed "s,.*/\(.*\)g++.1,\1,"` - ln -sf "$man_prefix"gcc.1 "$i" - fi - done -} - -genericBuild diff --git a/pkgs/development/compilers/gcc/common/builder.nix b/pkgs/development/compilers/gcc/common/builder.nix index d8ee1dbfa196d..0e3f0bdad61c1 100644 --- a/pkgs/development/compilers/gcc/common/builder.nix +++ b/pkgs/development/compilers/gcc/common/builder.nix @@ -134,7 +134,7 @@ originalAttrs: (stdenv.mkDerivation (finalAttrs: originalAttrs // { ) fi - if test "$crossStageStatic" == 1; then + if test "$withoutTargetLibc" == 1; then # We don't want the gcc build to assume there will be a libc providing # limits.h in this stage makeFlagsArray+=( @@ -166,7 +166,7 @@ originalAttrs: (stdenv.mkDerivation (finalAttrs: originalAttrs // { rm -Rf zlib fi - if test -n "$crossMingw" -a -n "$crossStageStatic"; then + if test -n "$crossMingw" -a -n "$withoutTargetLibc"; then mkdir -p ../mingw # --with-build-sysroot expects that: cp -R $libcCross/include ../mingw From 5eaf17927e285e207d66fcf497707a8af22ac0b9 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Fri, 16 Jun 2023 00:42:50 -0700 Subject: [PATCH 7/9] gcc: add `-g` to `declare` The bash `declare` builtin works differently when it occurs inside function, as it now does due to breaking up the monolithic `builder.sh` into separate phases. We have to add `-g` in order to get the outside-of-a-bash-function behavior when using `declare` within a bash function. --- pkgs/development/compilers/gcc/common/builder.nix | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pkgs/development/compilers/gcc/common/builder.nix b/pkgs/development/compilers/gcc/common/builder.nix index 0e3f0bdad61c1..72a06383c92b0 100644 --- a/pkgs/development/compilers/gcc/common/builder.nix +++ b/pkgs/development/compilers/gcc/common/builder.nix @@ -24,7 +24,7 @@ originalAttrs: (stdenv.mkDerivation (finalAttrs: originalAttrs // { if test "$noSysDirs" = "1"; then - declare \ + declare -g \ EXTRA_FLAGS_FOR_BUILD EXTRA_FLAGS EXTRA_FLAGS_FOR_TARGET \ EXTRA_LDFLAGS_FOR_BUILD EXTRA_LDFLAGS_FOR_TARGET @@ -51,7 +51,7 @@ originalAttrs: (stdenv.mkDerivation (finalAttrs: originalAttrs // { extraLDFlags=("-L$libc_libdir" "-rpath" "$libc_libdir" "''${extraLDFlags[@]}") for i in "''${extraLDFlags[@]}"; do - declare EXTRA_LDFLAGS''${post}+=" -Wl,$i" + declare -g EXTRA_LDFLAGS''${post}+=" -Wl,$i" done done @@ -72,11 +72,11 @@ originalAttrs: (stdenv.mkDerivation (finalAttrs: originalAttrs // { # Use *real* header files, otherwise a limits.h is generated that # does not include Libc's limits.h (notably missing SSIZE_MAX, # which breaks the build). - declare NIX_FIXINC_DUMMY''${post}="$libc_devdir/include" + declare -g NIX_FIXINC_DUMMY''${post}="$libc_devdir/include" else # Hack: support impure environments. extraFlags=("-isystem" "/usr/include") - declare NIX_FIXINC_DUMMY''${post}=/usr/include + declare -g NIX_FIXINC_DUMMY''${post}=/usr/include fi extraFlags=("-I''${!curFIXINC}" "''${extraFlags[@]}") @@ -92,7 +92,7 @@ originalAttrs: (stdenv.mkDerivation (finalAttrs: originalAttrs // { extraFlags=("-O2" "''${extraFlags[@]}") fi - declare EXTRA_FLAGS''${post}="''${extraFlags[*]}" + declare -g EXTRA_FLAGS''${post}="''${extraFlags[*]}" done if test -z "''${targetConfig-}"; then From e99f6372fab940ca96c399055b2dcb7c6160fc3e Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Thu, 29 Jun 2023 08:48:58 -0700 Subject: [PATCH 8/9] gcc: use callFile instead of callPackage for builder.nix --- pkgs/development/compilers/gcc/10/default.nix | 2 +- pkgs/development/compilers/gcc/11/default.nix | 2 +- pkgs/development/compilers/gcc/12/default.nix | 2 +- pkgs/development/compilers/gcc/13/default.nix | 2 +- pkgs/development/compilers/gcc/4.8/default.nix | 2 +- pkgs/development/compilers/gcc/4.9/default.nix | 2 +- pkgs/development/compilers/gcc/6/default.nix | 2 +- pkgs/development/compilers/gcc/7/default.nix | 2 +- pkgs/development/compilers/gcc/8/default.nix | 2 +- pkgs/development/compilers/gcc/9/default.nix | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pkgs/development/compilers/gcc/10/default.nix b/pkgs/development/compilers/gcc/10/default.nix index 31b35b49cdf3b..ff473019de775 100644 --- a/pkgs/development/compilers/gcc/10/default.nix +++ b/pkgs/development/compilers/gcc/10/default.nix @@ -144,7 +144,7 @@ let majorVersion = "10"; in -lib.pipe ((callPackage ../common/builder.nix {}) ({ +lib.pipe ((callFile ../common/builder.nix {}) ({ pname = "${crossNameAddon}${name}"; inherit version; diff --git a/pkgs/development/compilers/gcc/11/default.nix b/pkgs/development/compilers/gcc/11/default.nix index ec283828e4c85..b009972307740 100644 --- a/pkgs/development/compilers/gcc/11/default.nix +++ b/pkgs/development/compilers/gcc/11/default.nix @@ -157,7 +157,7 @@ let majorVersion = "11"; in -lib.pipe ((callPackage ../common/builder.nix {}) ({ +lib.pipe ((callFile ../common/builder.nix {}) ({ pname = "${crossNameAddon}${name}"; inherit version; diff --git a/pkgs/development/compilers/gcc/12/default.nix b/pkgs/development/compilers/gcc/12/default.nix index b0a298ec08ef6..da9ebb0a63c17 100644 --- a/pkgs/development/compilers/gcc/12/default.nix +++ b/pkgs/development/compilers/gcc/12/default.nix @@ -201,7 +201,7 @@ let majorVersion = "12"; in -lib.pipe ((callPackage ../common/builder.nix {}) ({ +lib.pipe ((callFile ../common/builder.nix {}) ({ pname = "${crossNameAddon}${name}"; inherit version; diff --git a/pkgs/development/compilers/gcc/13/default.nix b/pkgs/development/compilers/gcc/13/default.nix index 4cf0919c56160..82b30a0e5102d 100644 --- a/pkgs/development/compilers/gcc/13/default.nix +++ b/pkgs/development/compilers/gcc/13/default.nix @@ -195,7 +195,7 @@ let majorVersion = "13"; in -lib.pipe ((callPackage ../common/builder.nix {}) ({ +lib.pipe ((callFile ../common/builder.nix {}) ({ pname = "${crossNameAddon}${name}"; inherit version; diff --git a/pkgs/development/compilers/gcc/4.8/default.nix b/pkgs/development/compilers/gcc/4.8/default.nix index c047f58845b68..acc8ba41a00b2 100644 --- a/pkgs/development/compilers/gcc/4.8/default.nix +++ b/pkgs/development/compilers/gcc/4.8/default.nix @@ -193,7 +193,7 @@ in # We need all these X libraries when building AWT with GTK. assert x11Support -> (filter (x: x == null) ([ gtk2 libart_lgpl ] ++ xlibs)) == []; -lib.pipe ((callPackage ../common/builder.nix {}) ({ +lib.pipe ((callFile ../common/builder.nix {}) ({ pname = "${crossNameAddon}${name}"; inherit version; diff --git a/pkgs/development/compilers/gcc/4.9/default.nix b/pkgs/development/compilers/gcc/4.9/default.nix index fe12933750654..fadc9b72c45fc 100644 --- a/pkgs/development/compilers/gcc/4.9/default.nix +++ b/pkgs/development/compilers/gcc/4.9/default.nix @@ -210,7 +210,7 @@ in # We need all these X libraries when building AWT with GTK. assert x11Support -> (filter (x: x == null) ([ gtk2 libart_lgpl ] ++ xlibs)) == []; -lib.pipe ((callPackage ../common/builder.nix {}) ({ +lib.pipe ((callFile ../common/builder.nix {}) ({ pname = "${crossNameAddon}${name}"; inherit version; diff --git a/pkgs/development/compilers/gcc/6/default.nix b/pkgs/development/compilers/gcc/6/default.nix index 2ad2a79cad6a1..f19c2b4f46c8a 100644 --- a/pkgs/development/compilers/gcc/6/default.nix +++ b/pkgs/development/compilers/gcc/6/default.nix @@ -199,7 +199,7 @@ in # We need all these X libraries when building AWT with GTK. assert x11Support -> (filter (x: x == null) ([ gtk2 libart_lgpl ] ++ xlibs)) == []; -lib.pipe ((callPackage ../common/builder.nix {}) ({ +lib.pipe ((callFile ../common/builder.nix {}) ({ pname = "${crossNameAddon}${name}"; inherit version; diff --git a/pkgs/development/compilers/gcc/7/default.nix b/pkgs/development/compilers/gcc/7/default.nix index e341c57ec7dd6..72e241214fe46 100644 --- a/pkgs/development/compilers/gcc/7/default.nix +++ b/pkgs/development/compilers/gcc/7/default.nix @@ -149,7 +149,7 @@ let majorVersion = "7"; in -lib.pipe ((callPackage ../common/builder.nix {}) ({ +lib.pipe ((callFile ../common/builder.nix {}) ({ pname = "${crossNameAddon}${name}"; inherit version; diff --git a/pkgs/development/compilers/gcc/8/default.nix b/pkgs/development/compilers/gcc/8/default.nix index 59be3ecc8a8b7..274373a4fc8f3 100644 --- a/pkgs/development/compilers/gcc/8/default.nix +++ b/pkgs/development/compilers/gcc/8/default.nix @@ -130,7 +130,7 @@ let majorVersion = "8"; in -lib.pipe ((callPackage ../common/builder.nix {}) ({ +lib.pipe ((callFile ../common/builder.nix {}) ({ pname = "${crossNameAddon}${name}"; inherit version; diff --git a/pkgs/development/compilers/gcc/9/default.nix b/pkgs/development/compilers/gcc/9/default.nix index 512047d4c4f66..d08de2a5b79ce 100644 --- a/pkgs/development/compilers/gcc/9/default.nix +++ b/pkgs/development/compilers/gcc/9/default.nix @@ -144,7 +144,7 @@ let majorVersion = "9"; in -lib.pipe ((callPackage ../common/builder.nix {}) ({ +lib.pipe ((callFile ../common/builder.nix {}) ({ pname = "${crossNameAddon}${name}"; inherit version; From 7621636030c887b4d7d000813a7be61869a16cf7 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Thu, 29 Jun 2023 08:48:07 -0700 Subject: [PATCH 9/9] gcc: use Nix instead of bash for conditional Now that we use the standard builder, the commands produced by pre-configure.nix are wrapped in a bash function. Inside of a bash function, `export foo=` will still add `foo` to the environment of any child processes forked after that point, but those variables will *not* be visible to bash code which is outside of the function-scope in which the `export` occurs. Weird crap like this is yet another reason why we need to move away from using bash for logic. Let's switch. --- .../compilers/gcc/common/builder.nix | 27 ++++++++++++------- .../compilers/gcc/common/pre-configure.nix | 13 --------- 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/pkgs/development/compilers/gcc/common/builder.nix b/pkgs/development/compilers/gcc/common/builder.nix index 72a06383c92b0..e73542263df2f 100644 --- a/pkgs/development/compilers/gcc/common/builder.nix +++ b/pkgs/development/compilers/gcc/common/builder.nix @@ -1,5 +1,6 @@ { lib , stdenv +, enableMultilib }: originalAttrs: (stdenv.mkDerivation (finalAttrs: originalAttrs // { @@ -188,16 +189,22 @@ originalAttrs: (stdenv.mkDerivation (finalAttrs: originalAttrs // { preInstall = '' mkdir -p "$out/''${targetConfig}/lib" mkdir -p "''${!outputLib}/''${targetConfig}/lib" - # Make ‘lib64’ symlinks to ‘lib’. - if [ -n "$linkLib64toLib" ]; then - ln -s lib "$out/''${targetConfig}/lib64" - ln -s lib "''${!outputLib}/''${targetConfig}/lib64" - fi - # Make ‘lib32’ symlinks to ‘lib’. - if [ -n "$linkLib32toLib" ]; then - ln -s lib "$out/''${targetConfig}/lib32" - ln -s lib "''${!outputLib}/''${targetConfig}/lib32" - fi + '' + + # Make `lib64` symlinks to `lib`. + lib.optionalString (!enableMultilib && stdenv.hostPlatform.is64bit && !stdenv.hostPlatform.isMips64n32) '' + ln -s lib "$out/''${targetConfig}/lib64" + ln -s lib "''${!outputLib}/''${targetConfig}/lib64" + '' + + # On mips platforms, gcc follows the IRIX naming convention: + # + # $PREFIX/lib = mips32 + # $PREFIX/lib32 = mips64n32 + # $PREFIX/lib64 = mips64 + # + # Make `lib32` symlinks to `lib`. + lib.optionalString (!enableMultilib && stdenv.targetPlatform.isMips64n32) '' + ln -s lib "$out/''${targetConfig}/lib32" + ln -s lib "''${!outputLib}/''${targetConfig}/lib32" ''; postInstall = '' diff --git a/pkgs/development/compilers/gcc/common/pre-configure.nix b/pkgs/development/compilers/gcc/common/pre-configure.nix index e386693b22c7a..933a132ce4d1d 100644 --- a/pkgs/development/compilers/gcc/common/pre-configure.nix +++ b/pkgs/development/compilers/gcc/common/pre-configure.nix @@ -148,16 +148,3 @@ in lib.optionalString (hostPlatform.isSunOS && hostPlatform.is64bit) '' echo 'SHLIB_LC=${SHLIB_LC}' >> libgcc/Makefile.in '') -+ lib.optionalString (!enableMultilib && hostPlatform.is64bit && !hostPlatform.isMips64n32) '' - export linkLib64toLib=1 -'' - -# On mips platforms, gcc follows the IRIX naming convention: -# -# $PREFIX/lib = mips32 -# $PREFIX/lib32 = mips64n32 -# $PREFIX/lib64 = mips64 -# -+ lib.optionalString (!enableMultilib && targetPlatform.isMips64n32) '' - export linkLib32toLib=1 -''