Description
Is it reproducible with SwiftPM command-line tools: swift build
, swift test
, swift package
etc?
- Confirmed reproduction steps with SwiftPM CLI. The description text must include reproduction steps with either of command-line SwiftPM commands,
swift build
,swift test
,swift package
etc.
Description
When an error occurs during the build phase with the swift build
command, swiftbuild
build system uses stderr
as output stream to report the error. xcode
and native
build systems use stdout
.
Here is the PR that discussed about this issue: #8858
Moreover swift run
command uses stderr
as output stream for all build system, leading to more confusion.
Expected behavior
I expect a consistent output stream between build systems when an error occurs with swift build
command.
Actual behavior
When running the swift build
command on a package with syntax error here are the different outputs:
swift build --build-system swiftbuild > stdout-swiftbuild.txt 2> stderr-swiftbuild.txt
Stderr:
/Users/***/Desktop/Sample/Sources/Sample/Sample.swift:5:1: error: expected ')' in expression list
^
/Users/***/Desktop/Sample/Sources/Sample/Sample.swift:4:6: note: to match this opening '('
print("done"
^
error: /Users/***/Desktop/Sample/Sources/Sample/Sample.swift:5:1 expected ')' in expression list
^
error: Build failed
Stdout:
Building for debugging...
19%: 1 / 10
swift build --build-system xcode > stdout-xcode.txt 2> stderr-xcode.txt
Stderr:
Stdout:
0%: Compute target dependency graph
Building targets in dependency order
Target dependency graph (3 targets)
0%: Gather provisioning inputs
0%: Create build description
0%: Build stat cache for /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX26.0.sdk
14%: Planning Swift module Sample (arm64)
14%: Planning Swift module Sample (x86_64)
expected ')' in expression list
^
to match this opening '('
print("done"
^
expected ')' in expression list
^
to match this opening '('
print("done"
^
Build failed
swift build --build-system native > stdout-native.txt 2> stderr-native.txt
Stderr:
Stdout:
[0/1] Planning build
Building for debugging...
[0/1] Write swift-version-39B54973F684ADAB.txt
error: emit-module command failed with exit code 1 (use -v to see invocation)
[2/3] Emitting module Sample
/Users/***/Desktop/Sample/Sources/Sample/Sample.swift:5:1: error: expected ')' in expression list
2 | // https://docs.swift.org/swift-book
3 |
4 | print("done"
| `- note: to match this opening '('
5 |
| `- error: expected ')' in expression list
[3/3] Compiling Sample Sample.swift
/Users/***/Desktop/Sample/Sources/Sample/Sample.swift:5:1: error: expected ')' in expression list
2 | // https://docs.swift.org/swift-book
3 |
4 | print("done"
| `- note: to match this opening '('
5 |
| `- error: expected ')' in expression list
Steps to reproduce
- Create a new Package with
swift package init
- Update source files to contain a syntax error to trigger a build failure
- Run:
swift build --build-system swiftbuild > stdout-swiftbuild.txt 2> stderr-swiftbuild.txt
- Run:
swift build --build-system xcode > stdout-xcode.txt 2> stderr-xcode.txt
- Run:
swift build --build-system native > stdout-native.txt 2> stderr-native.txt
Swift Package Manager version/commit hash
Xcode 26 Beta 1 toolchain
Swift & OS version (output of swift --version ; uname -a
)
swift-driver version: 1.127.4.2 Apple Swift version 6.2 (swiftlang-6.2.0.9.909 clang-1700.3.9.907)
Target: arm64-apple-macosx15.0
Darwin mac.home 24.5.0 Darwin Kernel Version 24.5.0: Tue Apr 22 19:53:27 PDT 2025; root:xnu-11417.121.6~2/RELEASE_ARM64_T6041 arm64