From 4763533cca53e31eeb94778875b84b9440deac9e Mon Sep 17 00:00:00 2001 From: Sergei Trofimovich Date: Fri, 27 Jan 2023 21:30:14 +0000 Subject: [PATCH] build-support/cc-wrapper: add libstdc++fs into default library path for clang After https://github.com/NixOS/nixpkgs/pull/210004 `usbmuxd2` started failing to build as: usbmuxd2-unstable> .../ld: cannot find -lstdc++fs: No such file or directory usbmuxd2-unstable> clang-11: error: linker command failed with exit code 1 (use -v to see invocation) This started happening because #210004 exposed a long-standing bug in `gcc` derivation: `cc.lib` is missing `libstdc++fs` library: $ find $(nix-build --no-link -A stdenv.cc.cc.lib) | fgrep libstdc | unnix /<>/gcc-11.3.0-lib/lib/libstdc++fs.la /<>/gcc-11.3.0-lib/lib/libstdc++.la /<>/gcc-11.3.0-lib/lib/libstdc++.so.6.0.29 /<>/gcc-11.3.0-lib/lib/libstdc++.so /<>/gcc-11.3.0-lib/lib/libstdc++.so.6 It was not moved from `cc.out` output: $ find $(nix-build --no-link -A stdenv.cc.cc) | fgrep libstdc | unnix /<>/gcc-11.3.0/lib/libstdc++.a /<>/gcc-11.3.0/lib/libstdc++fs.a This change adds `cc` library lookup path back to `staging-next` until `gcc` is fixed.` --- pkgs/build-support/cc-wrapper/default.nix | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index 4efed4063198..33df804d5efe 100644 --- a/pkgs/build-support/cc-wrapper/default.nix +++ b/pkgs/build-support/cc-wrapper/default.nix @@ -321,6 +321,11 @@ stdenv.mkDerivation { && !(stdenv.targetPlatform.useLLVM or false) && gccForLibs != null) '' echo "--gcc-toolchain=${gccForLibs}" >> $out/nix-support/cc-cflags + + # Pull in 'cc.out' target to get 'libstdc++fs.a'. It should be in + # 'cc.lib'. But it's a gcc package bug. + # TODO(trofi): remove once gcc is fixed to move libraries to .lib output. + echo "-L${gccForLibs}/${optionalString (targetPlatform != hostPlatform) "/${targetPlatform.config}"}/lib" >> $out/nix-support/cc-ldflags '' ##