cc-wrapper: Fix gnatmake wrapper

Switches that gnatmake needs to pass to gcc must be given as
"-cargs <gcc_switches>" after at least the files to compile (see the
gnatmake docs for all the subtleties).  This commit makes that happen,
in a way that triggers rebuilds only for things that actually depend on
GNAT, and not the other compilers contained in GCC.
This commit is contained in:
Boey Maun Suang 2023-01-06 13:29:46 +11:00
parent f061f3ead5
commit c1308ac58c
3 changed files with 31 additions and 1 deletions

View File

@ -0,0 +1,23 @@
# See add-flags.sh in cc-wrapper for comments.
var_templates_list=(
NIX_GNATMAKE_CARGS
)
accumulateRoles
for var in "${var_templates_list[@]}"; do
mangleVarList "$var" ${role_suffixes[@]+"${role_suffixes[@]}"}
done
# `-B@out@/bin' forces cc to use wrapped as instead of the system one.
NIX_GNATMAKE_CARGS_@suffixSalt@="$NIX_GNATMAKE_CARGS_@suffixSalt@ -B@out@/bin/"
# Only add darwin min version flag if a default darwin min version is set,
# which is a signal that we're targetting darwin.
if [ "@darwinMinVersion@" ]; then
mangleVarSingle @darwinMinVersionVariable@ ${role_suffixes[@]+"${role_suffixes[@]}"}
NIX_GNATMAKE_CARGS_@suffixSalt@="-m@darwinPlatformForCC@-version-min=${@darwinMinVersionVariable@_@suffixSalt@:-@darwinMinVersion@} $NIX_GNATMAKE_CARGS_@suffixSalt@"
fi
export NIX_GNAT_WRAPPER_EXTRA_FLAGS_SET_@suffixSalt@=1

View File

@ -519,6 +519,10 @@ stdenv.mkDerivation {
substituteAll ${../wrapper-common/utils.bash} $out/nix-support/utils.bash substituteAll ${../wrapper-common/utils.bash} $out/nix-support/utils.bash
'' ''
+ optionalString cc.langAda or false ''
substituteAll ${./add-gnat-extra-flags.sh} $out/nix-support/add-gnat-extra-flags.sh
''
## ##
## General Clang support ## General Clang support
## Needs to go after ^ because the for loop eats \n and makes this file an invalid script ## Needs to go after ^ because the for loop eats \n and makes this file an invalid script

View File

@ -29,6 +29,9 @@ if [ -z "${NIX_CC_WRAPPER_FLAGS_SET_@suffixSalt@:-}" ]; then
source @out@/nix-support/add-flags.sh source @out@/nix-support/add-flags.sh
fi fi
if [ -z "${NIX_GNAT_WRAPPER_EXTRA_FLAGS_SET_@suffixSalt@:-}" ]; then
source @out@/nix-support/add-gnat-extra-flags.sh
fi
# Parse command line options and set several variables. # Parse command line options and set several variables.
# For instance, figure out if linker flags should be passed. # For instance, figure out if linker flags should be passed.
@ -126,7 +129,7 @@ fi
if [ "$(basename $0)x" = "gnatmakex" ]; then if [ "$(basename $0)x" = "gnatmakex" ]; then
extraBefore=("--GNATBIND=@out@/bin/gnatbind" "--GNATLINK=@out@/bin/gnatlink") extraBefore=("--GNATBIND=@out@/bin/gnatbind" "--GNATLINK=@out@/bin/gnatlink")
extraAfter=($NIX_GNATFLAGS_COMPILE_@suffixSalt@) extraAfter=($NIX_GNATFLAGS_COMPILE_@suffixSalt@ -cargs $NIX_GNATMAKE_CARGS_@suffixSalt@)
fi fi
if [ "$(basename $0)x" = "gnatbindx" ]; then if [ "$(basename $0)x" = "gnatbindx" ]; then