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`.
This commit is contained in:
Adam Joseph 2023-05-09 22:59:09 -07:00 committed by Artturin
parent f8056c5007
commit ea61be413c
2 changed files with 13 additions and 0 deletions

View file

@ -3,12 +3,14 @@
, version, buildPlatform, hostPlatform, targetPlatform , version, buildPlatform, hostPlatform, targetPlatform
, gnat-bootstrap ? null , gnat-bootstrap ? null
, langAda ? false , langAda ? false
, langFortran
, langJava ? false , langJava ? false
, langJit ? false , langJit ? false
, langGo , langGo
, withoutTargetLibc , withoutTargetLibc
, enableShared , enableShared
, enableMultilib , enableMultilib
, pkgsBuildTarget
}: }:
assert langJava -> lib.versionOlder version "7"; assert langJava -> lib.versionOlder version "7";
@ -27,6 +29,15 @@ in lib.optionalString (hostPlatform.isSunOS && hostPlatform.is64bit) ''
export PATH=${gnat-bootstrap}/bin:$PATH 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 # 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 # 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 # integrated assembler, but not by the GNU assembler in cctools-port that Nix

View file

@ -27,6 +27,7 @@
, gnused ? null , gnused ? null
, cloog # unused; just for compat with gcc4, as we override the parameter on some places , cloog # unused; just for compat with gcc4, as we override the parameter on some places
, buildPackages , buildPackages
, pkgsBuildTarget
, libxcrypt , libxcrypt
, disableGdbPlugin ? !enablePlugin , disableGdbPlugin ? !enablePlugin
, nukeReferences , nukeReferences
@ -176,6 +177,7 @@ let inherit version;
nukeReferences nukeReferences
patchelf patchelf
perl perl
pkgsBuildTarget
profiledCompiler profiledCompiler
reproducibleBuild reproducibleBuild
staticCompiler staticCompiler