Skip to content

Commit 322a267

Browse files
Don't use package manifest to treat warnings as errors
This reverts the configuration changes from a78e4ae. It turns out that this is causing a compilation error of "error: conflicting options '-warnings-as-errors' and '-suppress-warnings'" when trying to use Xcode to build an app that uses the SDK. Will create a minimal reproduction and raise a bug with Apple (have created #441 for this and restoring a78e4ae once fixed). I'm not sure why our example app wasn't catching this, but I guess there must be a difference in the way that the SDK gets built when it's included in the SDK via a workspace as opposed to via SPM. I've created #442 for for making the example app build more realistic to try and catch this sort of issue in the future; tried doing it as part of this work but didn't find a good solution, and want to get this fix released. Resolves #436.
1 parent c96988e commit 322a267

3 files changed

Lines changed: 45 additions & 4 deletions

File tree

.github/workflows/check.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,10 @@ jobs:
9191
with:
9292
xcode-version: ${{ matrix.tooling.xcodeVersion }}
9393

94-
- run: swift build
94+
# https://forums.swift.org/t/warnings-as-errors-for-libraries-frameworks/58393/2
95+
- run: swift build -Xswiftc -warnings-as-errors
9596
# Disabling testing temporarily due to intermittent hangs on CI (https://github.com/ably/ably-chat-swift/issues/295)
96-
#- run: swift test
97+
#- run: swift test -Xswiftc -warnings-as-errors
9798

9899
build-release-configuration-spm:
99100
name: SPM, `release` configuration (Xcode ${{ matrix.tooling.xcodeVersion }})
@@ -111,7 +112,8 @@ jobs:
111112
with:
112113
xcode-version: ${{ matrix.tooling.xcodeVersion }}
113114

114-
- run: swift build --configuration release
115+
# https://forums.swift.org/t/warnings-as-errors-for-libraries-frameworks/58393/2
116+
- run: swift build -Xswiftc -warnings-as-errors --configuration release
115117

116118
build-and-test-xcode:
117119
name: Xcode, ${{matrix.platform}} (Xcode ${{ matrix.tooling.xcodeVersion }})

Package.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import PackageDescription
44

55
let commonSwiftSettings: [SwiftSetting] = [
6-
.treatAllWarnings(as: .error),
76
.enableUpcomingFeature("MemberImportVisibility"),
87
.enableUpcomingFeature("ExistentialAny"),
98
]

Sources/BuildTool/XcodeRunner.swift

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,46 @@ enum XcodeRunner {
2424
arguments.append(contentsOf: ["-resultBundlePath", resultBundlePath])
2525
}
2626

27+
/*
28+
Note: I was previously passing SWIFT_TREAT_WARNINGS_AS_ERRORS=YES here, but am no longer able to do so, for the following reasons:
29+
30+
1. After adding a new package dependency, Xcode started trying to pass
31+
the Swift compiler the -suppress-warnings flag when compiling one of
32+
the newly-added transitive dependencies. This clashes with the
33+
-warnings-as-errors flag that Xcode adds when you set
34+
SWIFT_TREAT_WARNINGS_AS_ERRORS=YES, leading to a compiler error like
35+
36+
> error: Conflicting options '-warnings-as-errors' and '-suppress-warnings' (in target 'InternalCollectionsUtilities' from project 'swift-collections')
37+
38+
It’s not clear _why_ Xcode is adding this flag (see
39+
https://forums.swift.org/t/warnings-as-errors-in-sub-packages/70810),
40+
but perhaps it’s because of what I mention in point 2 below.
41+
42+
It seems that there is no way to tell Xcode, when building your own
43+
Swift package, “treat warnings as errors, but only for my package, and
44+
not for its dependencies”.
45+
46+
2. So, I thought that I’d try making Xcode remove the
47+
-suppress-warnings flag by additionally passing
48+
SWIFT_SUPPRESS_WARNINGS=NO, but this also doesn’t work because it turns
49+
out that one of our dependencies (swift-async-algorithms) actually does
50+
have some warnings, causing the build to fail.
51+
52+
tl;dr: There doesn’t seem to be a way to treat warnings as errors when
53+
compiling the package from Package.swift using Xcode.
54+
55+
It’s probably OK, though, because we also compile the package with SPM,
56+
and hopefully that will flag any warnings in CI (unless there’s some
57+
class of warnings I’m not aware of that only appear when compiling
58+
against the tvOS or iOS SDK).
59+
60+
(I imagine that using .unsafeFlags(["-warnings-as-errors"]) in the
61+
manifest might work, but then that’d stop other people from being able
62+
to use us as a dependency. I suppose we could, in CI at least, do
63+
something like modifying the manifest as part of the build process, but
64+
that seems like a nuisance.)
65+
*/
66+
2767
try await ProcessRunner.run(executableName: "xcodebuild", arguments: arguments)
2868
}
2969
}

0 commit comments

Comments
 (0)