From ea61be413c2505319aa5ed0073cd7412c08115aa Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Tue, 9 May 2023 22:59:09 -0700 Subject: [PATCH] gcc: set GFORTRAN_FOR_TARGET on cross-built native compilers For a cross-built native compiler, i.e. build!=(host==target), the bundled libgfortran needs a gfortran which can run on the buildPlatform and emit code for the targetPlatform. The compiler which is built alongside gfortran in this configuration doesn't meet that need: it runs on the hostPlatform. This commit passes the necessary compiler via `GFORTRAN_FOR_TARGET`, using `pkgsBuildTarget.gfortran`. --- .../compilers/gcc/common/pre-configure.nix | 11 +++++++++++ pkgs/development/compilers/gcc/default.nix | 2 ++ 2 files changed, 13 insertions(+) diff --git a/pkgs/development/compilers/gcc/common/pre-configure.nix b/pkgs/development/compilers/gcc/common/pre-configure.nix index 5cb2f186fd1d..32e203ee4912 100644 --- a/pkgs/development/compilers/gcc/common/pre-configure.nix +++ b/pkgs/development/compilers/gcc/common/pre-configure.nix @@ -3,12 +3,14 @@ , version, buildPlatform, hostPlatform, targetPlatform , gnat-bootstrap ? null , langAda ? false +, langFortran , langJava ? false , langJit ? false , langGo , withoutTargetLibc , enableShared , enableMultilib +, pkgsBuildTarget }: assert langJava -> lib.versionOlder version "7"; @@ -27,6 +29,15 @@ in lib.optionalString (hostPlatform.isSunOS && hostPlatform.is64bit) '' export PATH=${gnat-bootstrap}/bin:$PATH '' +# For a cross-built native compiler, i.e. build!=(host==target), the +# bundled libgfortran needs a gfortran which can run on the +# buildPlatform and emit code for the targetPlatform. The compiler +# which is built alongside gfortran in this configuration doesn't +# meet that need: it runs on the hostPlatform. ++ lib.optionalString (langFortran && (with stdenv; buildPlatform != hostPlatform && hostPlatform == targetPlatform)) '' + export GFORTRAN_FOR_TARGET=${pkgsBuildTarget.gfortran}/bin/${stdenv.targetPlatform.config}-gfortran +'' + # On x86_64-darwin, the gnat-bootstrap bootstrap compiler that we need to build a # native GCC with Ada support emits assembly that is accepted by the Clang # integrated assembler, but not by the GNU assembler in cctools-port that Nix diff --git a/pkgs/development/compilers/gcc/default.nix b/pkgs/development/compilers/gcc/default.nix index fdc79b575515..eb77b6f36524 100644 --- a/pkgs/development/compilers/gcc/default.nix +++ b/pkgs/development/compilers/gcc/default.nix @@ -27,6 +27,7 @@ , gnused ? null , cloog # unused; just for compat with gcc4, as we override the parameter on some places , buildPackages +, pkgsBuildTarget , libxcrypt , disableGdbPlugin ? !enablePlugin , nukeReferences @@ -176,6 +177,7 @@ let inherit version; nukeReferences patchelf perl + pkgsBuildTarget profiledCompiler reproducibleBuild staticCompiler