Skip to content

Commit b37c024

Browse files
committed
fix warning as error for 6.5
Signed-off-by: michael_crosby <michael_crosby@apple.com>
1 parent 5427fd2 commit b37c024

6 files changed

Lines changed: 46 additions & 5 deletions

File tree

.github/workflows/linux-build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
run: make containerization
4949

5050
- name: Build vminitd (glibc)
51-
run: make -C vminitd SWIFT_CONFIGURATION="--disable-automatic-resolution -Xswiftc -warnings-as-errors"
51+
run: make -C vminitd SWIFT_CONFIGURATION="--disable-automatic-resolution"
5252

5353
- name: Install Static Linux SDK
5454
run: make -C vminitd linux-sdk
@@ -57,4 +57,4 @@ jobs:
5757
run: make -C vminitd
5858

5959
- name: Run unit tests
60-
run: swift test --disable-automatic-resolution -Xswiftc -warnings-as-errors
60+
run: swift test --disable-automatic-resolution

CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ The project is built via `make`, not directly with `swift build`. Two Swift pack
2424
- `make protos` — regenerates `Sources/Containerization/SandboxContext/SandboxContext.{pb,grpc}.swift` from the `.proto`. Touch this whenever the proto changes; never hand-edit the generated files.
2525
- `make init` / `make init-image``init` compiles the guest and builds `bin/initfs.ext4` (+ a rootfs tar) inside the dev container via `scripts/build-initfs.sh` (mkfs + loop mount, with a `mke2fs -d` fallback), then `init-image` creates the `vminit:latest` OCI image from the tar with the native `cctl` (`cctl rootfs create --rootfs <tar> --image vminit:latest`). CI splits these: a Linux container job builds the initfs artifact, the macOS job runs `init-image`. Building the guest on macOS requires the apple/`container` CLI — there is no host Swiftly / Static Linux SDK setup step anymore.
2626

27-
`WARNINGS_AS_ERRORS=true` is the default for both packages. Don't disable it casually — CI builds with it on.
27+
`WARNINGS_AS_ERRORS=true` is the default for both packages. Don't disable it casually — CI builds with it on. It is enforced *per target* via `.treatAllWarnings(as: .error)` in both `Package.swift` files, not by a global `-Xswiftc -warnings-as-errors`: a global flag also reaches package dependencies, which SwiftPM's swiftbuild build system (the default since Swift 6.5) compiles with `-suppress-warnings`, and `swiftc` rejects that pair — the build then fails inside third-party modules before any of our code compiles. `WARNINGS_AS_ERRORS=false` relaxes it by passing `-Xswiftc -no-warnings-as-errors`.
2828

2929
## Architecture
3030

Makefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,15 @@ WARNINGS_AS_ERRORS ?= true
2222
SCRATCH_ROOT ?=
2323
SCRATCH_PATH ?= $(if $(SCRATCH_ROOT),$(SCRATCH_ROOT)/build-containerization)
2424
SWIFT_SCRATCH_FLAGS := $(if $(SCRATCH_PATH),--scratch-path $(SCRATCH_PATH))
25-
SWIFT_CONFIGURATION := $(if $(filter-out false,$(WARNINGS_AS_ERRORS)),-Xswiftc -warnings-as-errors) --disable-automatic-resolution $(SWIFT_SCRATCH_FLAGS)
25+
# Warnings-as-errors lives in Package.swift (`.treatAllWarnings(as: .error)`,
26+
# applied per target) rather than here. A global `-Xswiftc -warnings-as-errors`
27+
# also reaches package dependencies, which SwiftPM's swiftbuild build system
28+
# (the default since Swift 6.5) compiles with `-suppress-warnings` — swiftc
29+
# rejects that pair and the build dies inside third-party modules. Setting
30+
# WARNINGS_AS_ERRORS=false relaxes the per-target setting with an explicit
31+
# `-no-warnings-as-errors`, which has no such conflict.
32+
SWIFT_CONFIGURATION := $(if $(filter-out false,$(WARNINGS_AS_ERRORS)),,-Xswiftc -no-warnings-as-errors) --disable-automatic-resolution $(SWIFT_SCRATCH_FLAGS)
33+
2634

2735
# Commonly used locations
2836
UNAME_S := $(shell uname -s)

Package.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,3 +339,22 @@ package.targets.append(
339339
path: "Sources/Integration"
340340
)
341341
)
342+
343+
// Warnings are errors in this package's own targets.
344+
//
345+
// This is expressed per target rather than as a global `-Xswiftc
346+
// -warnings-as-errors`, which is what the Makefile used to pass. SwiftPM's
347+
// swiftbuild build system — the default since Swift 6.5 — compiles package
348+
// *dependencies* with `-suppress-warnings`, and swiftc rejects that alongside
349+
// `-warnings-as-errors` ("conflicting options"). A global flag therefore fails
350+
// the build inside third-party modules before any of our code is compiled,
351+
// while a per-target setting leaves dependencies alone.
352+
//
353+
// Applied in a loop so a target added later is covered without anyone
354+
// remembering to opt in. `make ... WARNINGS_AS_ERRORS=false` still relaxes it,
355+
// by passing `-Xswiftc -no-warnings-as-errors` — which does not conflict with
356+
// `-suppress-warnings`.
357+
let cOnlyTargets: Set<String> = ["CShim", "CArchive", "LCShim"]
358+
for target in package.targets where !cOnlyTargets.contains(target.name) {
359+
target.swiftSettings = (target.swiftSettings ?? []) + [.treatAllWarnings(as: .error)]
360+
}

vminitd/Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ WARNINGS_AS_ERRORS ?= true
1717
export GIT_COMMIT := $(shell git rev-parse HEAD)
1818
export GIT_TAG := $(shell git describe --tags --exact-match 2>/dev/null || echo "")
1919
export BUILD_TIME := $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
20-
SWIFT_WARNING_CONFIG := $(if $(filter-out false,$(WARNINGS_AS_ERRORS)),-Xswiftc -warnings-as-errors)
20+
# Warnings-as-errors is set per target in Package.swift; see the comment there.
21+
# Passing it globally would also apply it to package dependencies, which the
22+
# swiftbuild build system compiles with `-suppress-warnings` — a combination
23+
# swiftc rejects outright.
24+
SWIFT_WARNING_CONFIG := $(if $(filter-out false,$(WARNINGS_AS_ERRORS)),,-Xswiftc -no-warnings-as-errors)
25+
2126
# MUSL_ARCH selects which Static Linux SDK triple to build against
2227
# ($(MUSL_ARCH)-swift-linux-musl). Defaults to the host architecture
2328
# so the in-tree aarch64 flow works unchanged, but callers can override

vminitd/Package.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,12 @@ let package = Package(
6969
),
7070
]
7171
)
72+
73+
// Warnings are errors in this package's own targets. Same reasoning as the root
74+
// package: a global `-Xswiftc -warnings-as-errors` also lands on package
75+
// dependencies, which SwiftPM's swiftbuild build system compiles with
76+
// `-suppress-warnings`, and swiftc refuses that combination. `CVersion` is
77+
// C-only, so there is nothing for a Swift setting to apply to.
78+
for target in package.targets where target.name != "CVersion" {
79+
target.swiftSettings = (target.swiftSettings ?? []) + [.treatAllWarnings(as: .error)]
80+
}

0 commit comments

Comments
 (0)