From c1308ac58cb1bccf29e6729b6b0da0254710bf70 Mon Sep 17 00:00:00 2001 From: Boey Maun Suang Date: Fri, 6 Jan 2023 13:29:46 +1100 Subject: [PATCH] cc-wrapper: Fix gnatmake wrapper Switches that gnatmake needs to pass to gcc must be given as "-cargs " 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. --- .../cc-wrapper/add-gnat-extra-flags.sh | 23 +++++++++++++++++++ pkgs/build-support/cc-wrapper/default.nix | 4 ++++ pkgs/build-support/cc-wrapper/gnat-wrapper.sh | 5 +++- 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 pkgs/build-support/cc-wrapper/add-gnat-extra-flags.sh diff --git a/pkgs/build-support/cc-wrapper/add-gnat-extra-flags.sh b/pkgs/build-support/cc-wrapper/add-gnat-extra-flags.sh new file mode 100644 index 000000000000..ceff1e4a4c4a --- /dev/null +++ b/pkgs/build-support/cc-wrapper/add-gnat-extra-flags.sh @@ -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 diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index a59505d08258..7473b866d64f 100644 --- a/pkgs/build-support/cc-wrapper/default.nix +++ b/pkgs/build-support/cc-wrapper/default.nix @@ -519,6 +519,10 @@ stdenv.mkDerivation { 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 ## Needs to go after ^ because the for loop eats \n and makes this file an invalid script diff --git a/pkgs/build-support/cc-wrapper/gnat-wrapper.sh b/pkgs/build-support/cc-wrapper/gnat-wrapper.sh index 5714b228c595..1d0a97c7604c 100644 --- a/pkgs/build-support/cc-wrapper/gnat-wrapper.sh +++ b/pkgs/build-support/cc-wrapper/gnat-wrapper.sh @@ -29,6 +29,9 @@ if [ -z "${NIX_CC_WRAPPER_FLAGS_SET_@suffixSalt@:-}" ]; then source @out@/nix-support/add-flags.sh 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. # For instance, figure out if linker flags should be passed. @@ -126,7 +129,7 @@ fi if [ "$(basename $0)x" = "gnatmakex" ]; then 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 if [ "$(basename $0)x" = "gnatbindx" ]; then