diff --git a/pkgs/build-support/cc-wrapper/add-clang-cc-cflags-before.sh b/pkgs/build-support/cc-wrapper/add-clang-cc-cflags-before.sh index b56bb39c97a9..2b7cd00783a5 100644 --- a/pkgs/build-support/cc-wrapper/add-clang-cc-cflags-before.sh +++ b/pkgs/build-support/cc-wrapper/add-clang-cc-cflags-before.sh @@ -30,4 +30,8 @@ if $targetPassed && [[ "$targetValue" != "@defaultTarget@" ]] && (( "${NIX_CC_WR echo "Warning: supplying the --target $targetValue != @defaultTarget@ argument to a nix-wrapped compiler may not work correctly - cc-wrapper is currently not designed with multi-target compilers in mind. You may want to use an un-wrapped compiler instead." >&2 elif [[ $0 != *cpp ]]; then extraBefore+=(-target @defaultTarget@ @machineFlags@) + + if [[ "@explicitAbiValue@" != "" ]]; then + extraBefore+=(-mabi=@explicitAbiValue@) + fi fi diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index 2a88e3369a99..472c555e42e2 100644 --- a/pkgs/build-support/cc-wrapper/default.nix +++ b/pkgs/build-support/cc-wrapper/default.nix @@ -94,12 +94,14 @@ let getLib getName getVersion + hasPrefix mapAttrsToList optional optionalAttrs optionals optionalString removePrefix + removeSuffix replaceStrings toList versionAtLeast @@ -901,12 +903,24 @@ stdenvNoCC.mkDerivation { ## General Clang support ## Needs to go after ^ because the for loop eats \n and makes this file an invalid script ## - + optionalString isClang '' - # Escape twice: once for this script, once for the one it gets substituted into. - export machineFlags=${escapeShellArg (escapeShellArgs machineFlags)} - export defaultTarget=${targetPlatform.config} - substituteAll ${./add-clang-cc-cflags-before.sh} $out/nix-support/add-local-cc-cflags-before.sh - '' + + optionalString isClang ( + let + hasUnsupportedGnuSuffix = hasPrefix "gnuabielfv" targetPlatform.parsed.abi.name; + clangCompatibleConfig = + if hasUnsupportedGnuSuffix then + removeSuffix (removePrefix "gnu" targetPlatform.parsed.abi.name) targetPlatform.config + else + targetPlatform.config; + explicitAbiValue = if hasUnsupportedGnuSuffix then targetPlatform.parsed.abi.abi else ""; + in + '' + # Escape twice: once for this script, once for the one it gets substituted into. + export machineFlags=${escapeShellArg (escapeShellArgs machineFlags)} + export defaultTarget=${clangCompatibleConfig} + export explicitAbiValue=${explicitAbiValue} + substituteAll ${./add-clang-cc-cflags-before.sh} $out/nix-support/add-local-cc-cflags-before.sh + '' + ) ## ## Extra custom steps