swift: don't pass -march to swiftc

swiftc uses cc-wrapper which sets the -march flag on some systems which
breaks the build. This change adds a flag, disableMarch, to cc-wrapper
which disables using the -march flag.
https://github.com/NixOS/nixpkgs/issues/295322
This commit is contained in:
annalee 2024-03-15 06:06:13 +00:00
parent e6aefe20a1
commit 8a7841ceef
No known key found for this signature in database
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
''
@ -699,7 +703,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