From 2da03072206223ed6ee968bdd654a4d82da33001 Mon Sep 17 00:00:00 2001 From: Sergei Trofimovich Date: Mon, 21 Aug 2023 07:37:01 +0100 Subject: [PATCH] buildFHSEnv: fix `NIX_LDFLAGS` propagation to `ld` wrapper Before the change the following command did not work: $ nix develop -i --impure --expr 'with import { system = "i686-linux"; }; (buildFHSUserEnv { name = "t"; targetPkgs = ps: with ps; [ libmpc stdenv.cc ]; }).env' $ ld -lmpc -o a ld: cannot find -lmpc: No such file or directory It is expected to work as `NIX_LDFLAGS` does contain valid values: $ echo $NIX_LDFLAGS -L/usr/lib -L/usr/lib32 Note that for `gcc` it does work: $ printf "int main(){}" | gcc -x c - -lmpc -o a It happens because `HOST` role is enabled for `cc`: $ echo $NIX_CC_WRAPPER_TARGET_HOST_i686_unknown_linux_gnu 1 But not for `BINTOOLS`: $ echo $NIX_BINTOOLS_WRAPPER_TARGET_HOST_i686_unknown_linux_gnu The change adds BINTOOLS role and fixes linking: $ nix develop -i --impure --expr 'with import ~/nm { system = "i686-linux"; }; (buildFHSUserEnv { name = "t"; targetPkgs = ps: with ps; [ libmpc stdenv.cc ]; }).env' $ printf "int main(){}" | gcc -x c - -lmpc -o a $ ld -lmpc -o a ld: warning: cannot find entry symbol _start; not setting start address --- pkgs/build-support/build-fhsenv-bubblewrap/buildFHSEnv.nix | 1 + pkgs/build-support/build-fhsenv-chroot/env.nix | 1 + 2 files changed, 2 insertions(+) diff --git a/pkgs/build-support/build-fhsenv-bubblewrap/buildFHSEnv.nix b/pkgs/build-support/build-fhsenv-bubblewrap/buildFHSEnv.nix index 3e6fc922906f..2c0c4a3d513a 100644 --- a/pkgs/build-support/build-fhsenv-bubblewrap/buildFHSEnv.nix +++ b/pkgs/build-support/build-fhsenv-bubblewrap/buildFHSEnv.nix @@ -105,6 +105,7 @@ let # Force compilers and other tools to look in default search paths unset NIX_ENFORCE_PURITY + export NIX_BINTOOLS_WRAPPER_TARGET_HOST_${stdenv.cc.suffixSalt}=1 export NIX_CC_WRAPPER_TARGET_HOST_${stdenv.cc.suffixSalt}=1 export NIX_CFLAGS_COMPILE='-idirafter /usr/include' export NIX_CFLAGS_LINK='-L/usr/lib -L/usr/lib32' diff --git a/pkgs/build-support/build-fhsenv-chroot/env.nix b/pkgs/build-support/build-fhsenv-chroot/env.nix index abc9ac4c026f..a1a26472373f 100644 --- a/pkgs/build-support/build-fhsenv-chroot/env.nix +++ b/pkgs/build-support/build-fhsenv-chroot/env.nix @@ -78,6 +78,7 @@ let # Force compilers and other tools to look in default search paths unset NIX_ENFORCE_PURITY + export NIX_BINTOOLS_WRAPPER_TARGET_HOST_${stdenv.cc.suffixSalt}=1 export NIX_CC_WRAPPER_TARGET_HOST_${stdenv.cc.suffixSalt}=1 export NIX_CFLAGS_COMPILE='-idirafter /usr/include' export NIX_CFLAGS_LINK='-L/usr/lib -L/usr/lib32'