swiftlang/swift-package-manager

SwiftPM `-warnings-as-errors` and `-suppress-warnings` to dependency targets

Open

#10,192 opened on Jun 11, 2026

View on GitHub
 (3 comments) (0 reactions) (0 assignees)Swift (1,462 forks)batch import
buggood first issueswiftbuild backend

Repository metrics

Stars
 (10,145 stars)
PR merge metrics
 (Avg merge 9d 4h) (62 merged PRs in 30d)

Description

Invoking a build with -Xswiftc -warnings-as-errors fails under the swiftbuild build system because it passes both -warnings-as-errors and -suppress-warnings to dependency (remote) targets. The Swift driver rejects the pair:

error: conflicting options '-warnings-as-errors' and '-suppress-warnings'

The native build system does not hit this: it strips -warnings-as-errors from dependency targets and compiles them with -suppress-warnings only. Because swiftbuild is the default build system as of Swift 6.4, this is a behavioural regression that breaks any project passing -Xswiftc -warnings-as-errors.

Passing -Xswiftc -warnings-as-errors (e.g. swift test -Xswiftc -warnings-as-errors) in CI to fail the build on warnings in first-party code is a widespread pattern. Dependencies are expected to be built with warnings suppressed, so a warning in a dependency never breaks the build — which is what the native engine does. swift-nio's CI uses this flag and broke when its nightly-next CI moved onto the Swift 6.4 toolchain.

Real failure: https://github.com/apple/swift-nio/actions/runs/27132399521/job/80076358853

Repro

Attached package.zip contains two throwaway packages — upstream and downstream (the root, which consumes upstream as a remote SCM dependency) — plus reproduce.sh, which git-initialises upstream and builds downstream. No network required.

Unzip it, then from inside the package directory run both commands — same toolchain, only the build system differs:

native (works):

% docker run --rm -v "$PWD:/repro" -w /repro swiftlang/swift:nightly-6.4.x-noble bash reproduce.sh native

>>> swift build --build-system native -Xswiftc -warnings-as-errors
Building for debugging...
...
Build complete! (2.30s)

swiftbuild (fails):

% docker run --rm -v "$PWD:/repro" -w /repro swiftlang/swift:nightly-6.4.x-noble bash reproduce.sh swiftbuild

>>> swift build --build-system swiftbuild -Xswiftc -warnings-as-errors
Building for debugging...
...
error: conflicting options '-warnings-as-errors' and '-suppress-warnings'
error: SwiftDriver Upstream normal aarch64 com.apple.xcode.tools.swift.compiler failed with a nonzero exit code
error: Build failed

upstream has no warnings, yet the swiftbuild build still fails — confirming the error is purely the flag combination applied to the dependency target, independent of any actual diagnostic.

Expected behaviour

Dependency (remote) targets must not receive -warnings-as-errors; they should be compiled with warnings suppressed, as the native engine does and as SE-0480 "Remote targets behavior" specifies (warning-control flags are stripped for remote targets and replaced with -suppress-warnings / -w):

https://github.com/swiftlang/swift-evolution/blob/main/proposals/0480-swiftpm-warning-control.md#remote-targets-behavior

Actual behaviour

swiftbuild adds -suppress-warnings to the dependency target but leaves the inherited -Xswiftc -warnings-as-errors in place, so both reach the driver and it errors.

Suggested fix

In the swiftbuild build-graph construction, strip -warnings-as-errors (and the other SE-0480 warning-control flags) from remote/dependency target compilation before substituting -suppress-warnings, matching the native build system.

Contributor guide