Merge pull request #301103 from Samasaur1/fix-swift

swiftc: pass -Xcc before -march
This commit is contained in:
a-n-n-a-l-e-e
2024-04-03 04:56:37 -07:00
committed by GitHub
3 changed files with 19 additions and 18 deletions
+2 -6
View File
@@ -53,10 +53,6 @@
, gccForLibs ? if useCcForLibs then cc else null
, fortify-headers ? null
, includeFortifyHeaders ? null
# https://github.com/NixOS/nixpkgs/issues/295322
# should -march flag be used
, disableMarch ? false
}:
assert nativeTools -> !propagateDoc && nativePrefix != "";
@@ -633,7 +629,7 @@ stdenv.mkDerivation {
# TODO: aarch64-darwin has mcpu incompatible with gcc
+ optionalString ((targetPlatform ? gcc.arch) && !isClang && !(stdenv.isDarwin && stdenv.isAarch64) &&
isGccArchSupported targetPlatform.gcc.arch && !disableMarch) ''
isGccArchSupported targetPlatform.gcc.arch) ''
echo "-march=${targetPlatform.gcc.arch}" >> $out/nix-support/cc-cflags-before
''
@@ -729,7 +725,7 @@ stdenv.mkDerivation {
+ optionalString isClang ''
# Escape twice: once for this script, once for the one it gets substituted into.
export march=${escapeShellArg
(optionalString (targetPlatform ? gcc.arch && !disableMarch)
(optionalString (targetPlatform ? gcc.arch)
(escapeShellArg "-march=${targetPlatform.gcc.arch}"))}
export defaultTarget=${targetPlatform.config}
substituteAll ${./add-clang-cc-cflags-before.sh} $out/nix-support/add-local-cc-cflags-before.sh
+3 -7
View File
@@ -25,13 +25,9 @@ let
#
# The following selects the correct Clang version, matching the version
# used in Swift, and applies the same libc overrides as `apple_sdk.stdenv`.
clang = let
# https://github.com/NixOS/nixpkgs/issues/295322
clangNoMarch = swiftLlvmPackages.clang.override { disableMarch = true; };
in
if pkgs.stdenv.isDarwin
clang = if pkgs.stdenv.isDarwin
then
clangNoMarch.override rec {
swiftLlvmPackages.clang.override rec {
libc = apple_sdk.Libsystem;
bintools = pkgs.bintools.override { inherit libc; };
# Ensure that Swifts internal clang uses the same libc++ and libc++abi as the
@@ -41,7 +37,7 @@ let
inherit (llvmPackages) libcxx;
}
else
clangNoMarch;
swiftLlvmPackages.clang;
# Overrides that create a useful environment for swift packages, allowing
# packaging with `swiftPackages.callPackage`. These are similar to
@@ -242,17 +242,26 @@ if [[ -e $cc_wrapper/nix-support/add-local-cc-cflags-before.sh ]]; then
source $cc_wrapper/nix-support/add-local-cc-cflags-before.sh
fi
# May need to transform the triple injected by the above.
for ((i = 1; i < ${#extraBefore[@]}; i++)); do
if [[ "${extraBefore[i]}" = -target ]]; then
for ((i=0; i < ${#extraBefore[@]}; i++));do
case "${extraBefore[i]}" in
-target)
i=$((i + 1))
# On Darwin only, need to change 'aarch64' to 'arm64'.
extraBefore[i]="${extraBefore[i]/aarch64-apple-/arm64-apple-}"
# On Darwin, Swift requires the triple to be annotated with a version.
# TODO: Assumes macOS.
extraBefore[i]="${extraBefore[i]/-apple-darwin/-apple-macosx${MACOSX_DEPLOYMENT_TARGET:-11.0}}"
break
fi
;;
-march=*)
[[ i -gt 0 && ${extraBefore[i-1]} == -Xcc ]] && continue
extraBefore=(
"${extraBefore[@]:0:i}"
-Xcc
"${extraBefore[@]:i:${#extraBefore[@]}}"
)
i=$((i + 1))
;;
esac
done
# As a very special hack, if the arguments are just `-v', then don't