[SR-14459] swift compiler (swift build) reports erroneous error about missing -Swift.h file when missing a dependency in Package.swift #56815
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
Environment
Apple Swift version 5.3.2 (swiftlang-1200.0.45 clang-1200.0.32.28).
Additional Detail from JIRA
md5: 911215588387a3376ea0fef86affbc0e
Issue Description:
While working through replicating some example code from swift-collections-benchmark, I was creating my own Package.swift and missed including a dependency.
The error that `swift build` reported was:
```
/Users/heckj/src/swift-collections-benchmark/Documentation/.build/x86_64-apple-macosx/debug/Collections.build/module.modulemap:2:12: error: header '/Users/heckj/src/swift-collections-benchmark/Documentation/.build/x86_64-apple-macosx/debug/Collections.build/Collections-Swift.h' not found
header "/Users/heckj/src/swift-collections-benchmark/Documentation/.build/x86_64-apple-macosx/debug/Collections.build/Collections-Swift.h"
^
/Users/heckj/src/swift-collections-benchmark/Documentation/Sources/Kalimba/Kalimba.swift:18:8: error: could not build Objective-C module 'Collections'
import Collections
^
[1/57] Compiling OrderedCollections _HashTable+Bucket.swift
```
When the actual issue was that I neglected to include "Collections" in the dependency for the library.
I wasn't entirely clear why the error message was appearing, but I think if we can report that the dependency couldn't be found as a first step, that would probably be a better error than sending someone down the path of trying to understand what's expecting a header file.
I set up a sample project to make this easier to reproduce:
1. `git clone https://github.com/heckj/swift-collections-benchmark.git -b buildMissingDependency`
2. `cd swift-collections-benchmark/Documentation`
3. `swift build -c release`:
```
Fetching https://github.com/apple/swift-collections-benchmark
Fetching https://github.com/apple/swift-collections
Fetching https://github.com/apple/swift-argument-parser
Fetching https://github.com/apple/swift-system
Cloning https://github.com/apple/swift-system
Resolving https://github.com/apple/swift-system at 0.0.1
Cloning https://github.com/apple/swift-collections
Resolving https://github.com/apple/swift-collections at 0.0.1
Cloning https://github.com/apple/swift-collections-benchmark
Resolving https://github.com/apple/swift-collections-benchmark at 0.0.1
Cloning https://github.com/apple/swift-argument-parser
Resolving https://github.com/apple/swift-argument-parser at 0.4.1
/Users/heckj/src/swift-collections-benchmark/Documentation/.build/x86_64-apple-macosx/release/Collections.build/module.modulemap:2:12: error: header '/Users/heckj/src/swift-collections-benchmark/Documentation/.build/x86_64-apple-macosx/release/Collections.build/Collections-Swift.h' not found
header "/Users/heckj/src/swift-collections-benchmark/Documentation/.build/x86_64-apple-macosx/release/Collections.build/Collections-Swift.h"
^
/Users/heckj/src/swift-collections-benchmark/Documentation/Sources/Kalimba/Kalimba.swift:18:8: error: could not build Objective-C module 'Collections'
import Collections
^
```
Within the Package.swift that's inside the Documentation directory, there's a commented out dependency. Remove the comment and recompile, and it's quite happy.
The text was updated successfully, but these errors were encountered: