Merge pull request #296082 from a-n-n-a-l-e-e/dont-pass-march-swift

swift: don't pass -march to swiftc
This commit is contained in:
a-n-n-a-l-e-e 2024-03-16 19:18:41 -07:00 committed by GitHub
commit 8c421f78b2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 5 deletions

View File

@ -53,6 +53,10 @@
, 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
}:
with lib;
@ -609,7 +613,7 @@ stdenv.mkDerivation {
# TODO: aarch64-darwin has mcpu incompatible with gcc
+ optionalString ((targetPlatform ? gcc.arch) && !isClang && !(stdenv.isDarwin && stdenv.isAarch64) &&
isGccArchSupported targetPlatform.gcc.arch) ''
isGccArchSupported targetPlatform.gcc.arch && !disableMarch) ''
echo "-march=${targetPlatform.gcc.arch}" >> $out/nix-support/cc-cflags-before
''
@ -705,7 +709,7 @@ stdenv.mkDerivation {
+ optionalString isClang ''
# Escape twice: once for this script, once for the one it gets substituted into.
export march=${lib.escapeShellArg
(lib.optionalString (targetPlatform ? gcc.arch)
(lib.optionalString (targetPlatform ? gcc.arch && !disableMarch)
(lib.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

View File

@ -25,9 +25,13 @@ 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 = if pkgs.stdenv.isDarwin
clang = let
# https://github.com/NixOS/nixpkgs/issues/295322
clangNoMarch = swiftLlvmPackages.clang.override { disableMarch = true; };
in
if pkgs.stdenv.isDarwin
then
swiftLlvmPackages.clang.override rec {
clangNoMarch.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
@ -45,7 +49,7 @@ let
];
}
else
swiftLlvmPackages.clang;
clangNoMarch;
# Overrides that create a useful environment for swift packages, allowing
# packaging with `swiftPackages.callPackage`. These are similar to