Unverified Commit 5b123afb authored by Sam's avatar Sam
Browse files

swiftPackages.swift: prefix unguarded-availability flag with -Xcc

The Swift wrapper uses a hook directly from cc-wrapper to set the
`-target` flag appropriately. This works because Clang and Swift use the
same syntax for `-target`, but there was never a guarantee that this
compatibility would be true for every option set in the hook. Indeed,
commit 369cc5c6 (PR #445119) made
availability warnings into errors by setting the
`-Werror=unguarded-availability` flag in this hook, which Swift doesn't
accept at the top level. This caused all invocations of Swift to fail
with the error `unknown argument: '-Werror=unguarded-availability'` -
including the bootstrap Swift, which meant that `swiftPackages.swift`
would fail.

This commit adds all `-Werror` flags to the list of flags that need to
be prefixed with `-Xcc`. I could have just dropped the flag, since Swift
already makes this an error, but you can have C/C++ targets in Swift
packages and we'd want to pass this flag on to them. (I'm not sure
whether the clang used for those targets is already wrapped, but if it
is there is no harm done.)
parent 89f7581b
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -248,6 +248,9 @@ fi
# TODO: If we ever need to expand functionality of this hook, it may no longer
# be compatible with Swift. Right now, it is only used on Darwin to force
# -target, which also happens to work with Swift.
# As of 369cc5c66b1efdbca2f136aa0055fedca1117304 (#445119), this hook also sets
# the -Werror=unguarded-availability flag, which Swift can't accept. We prefix
# that flag with -Xcc in the for loop below
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
@@ -262,7 +265,7 @@ for ((i=0; i < ${#extraBefore[@]}; i++));do
        # TODO: Assumes macOS.
        extraBefore[i]="${extraBefore[i]/-apple-darwin/-apple-macosx${MACOSX_DEPLOYMENT_TARGET:-11.0}}"
        ;;
    -march=*|-mcpu=*|-mfloat-abi=*|-mfpu=*|-mmode=*|-mthumb|-marm|-mtune=*)
    -march=*|-mcpu=*|-mfloat-abi=*|-mfpu=*|-mmode=*|-mthumb|-marm|-mtune=*|-Werror=*)
        [[ i -gt 0 && ${extraBefore[i-1]} == -Xcc ]] && continue
        extraBefore=(
            "${extraBefore[@]:0:i}"