Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing diagnostic about missing dependency #6607

Open
dabrahams opened this issue May 23, 2023 · 3 comments
Open

Missing diagnostic about missing dependency #6607

dabrahams opened this issue May 23, 2023 · 3 comments
Labels

Comments

@dabrahams
Copy link
Contributor

Description

Description

Check out the missing-dependency-diagnostic tag from the https://github.com/val-lang/val project, follow the setup instructions if you haven't already, and do swift -vv test. You will get link errors. It turns out that this change is missing, but SPM / the swift compiler doesn't tell me about it:

diff --git a/Package.swift b/Package.swift
index fa1d158f..3203e9c4 100644
--- a/Package.swift
+++ b/Package.swift
@@ -75,6 +75,7 @@ let package = Package(
       dependencies: [
         "Utils",
         .product(name: "LLVM", package: "Swifty-LLVM"),
+        .product(name: "Collections", package: "swift-collections"),
       ],
       swiftSettings: allTargetsSwiftSettings),
 

This is a big problem because often these missing dependencies don't result in link errors (like the state of that project at 5806c04fcb2b9). The project builds/runs/tests but who knows what misbehavior may have resulted from the mis-specification of Package.swift. If my tests fail, is it because of some unspecified dependency? Can't tell.

Expected behavior

No response

Actual behavior

No response

Steps to reproduce

No response

Swift Package Manager version/commit hash

Swift Package Manager - Swift 5.8.0

Swift & OS version (output of swift --version ; uname -a)

swift-driver version: 1.75.2 Apple Swift version 5.8 (swiftlang-5.8.0.124.2 clang-1403.0.22.11.100)
Target: arm64-apple-macosx13.0
Darwin DaveA-MBP14.localdomain 22.4.0 Darwin Kernel Version 22.4.0: Mon Mar 6 20:59:28 PST 2023; root:xnu-8796.101.5~3/RELEASE_ARM64_T6000 arm64

@dabrahams dabrahams added the bug label May 23, 2023
@dabrahams
Copy link
Contributor Author

An even simpler example is the missing-dependency-diagnostic2 tag, which, instead of failing with link errors, fails with the following, which is even more confounding:

/Users/dave/src/val/.build/arm64-apple-macosx/debug/Core.build/module.modulemap:2:12: error: header '/Users/dave/src/val/.build/arm64-apple-macosx/debug/Core.build/Core-Swift.h' not found
    header "/Users/dave/src/val/.build/arm64-apple-macosx/debug/Core.build/Core-Swift.h"
           ^
/Users/dave/src/val/Tests/EndToEndTests/ExecutionTests.swift:1:8: error: could not build Objective-C module 'Core'
import Core
       ^
error: emit-module command failed with exit code 1 (use -v to see invocation)
[401/403] Emitting module EndToEndTests
/Users/dave/src/val/.build/arm64-apple-macosx/debug/Core.build/module.modulemap:2:12: error: header '/Users/dave/src/val/.build/arm64-apple-macosx/debug/Core.build/Core-Swift.h' not found
    header "/Users/dave/src/val/.build/arm64-apple-macosx/debug/Core.build/Core-Swift.h"
           ^
/Users/dave/src/val/Tests/EndToEndTests/ExecutionTests.swift:1:8: error: could not build Objective-C module 'Core'
import Core
       ^
[402/403] Compiling EndToEndTests ExecutionTests.swift
/Users/dave/src/val/.build/arm64-apple-macosx/debug/Core.build/module.modulemap:2:12: error: header '/Users/dave/src/val/.build/arm64-apple-macosx/debug/Core.build/Core-Swift.h' not found
    header "/Users/dave/src/val/.build/arm64-apple-macosx/debug/Core.build/Core-Swift.h"
           ^
/Users/dave/src/val/Tests/EndToEndTests/ExecutionTests.swift:1:8: error: could not build Objective-C module 'Core'
import Core
       ^
error: fatalError

@neonichu
Copy link
Contributor

This is the kind of issue that the opt-in diagnostic added in #3562 aimed to address, but beyond that nothing will check that imports line up with package dependencies currently.

@dabrahams
Copy link
Contributor Author

For anyone stumbling on this bug and wanting to know the workaround without having to dig it out of #3562, if all of your swift build and swift test invocations have the option --explicit-target-dependency-import-check=error, the system will prevent you from making this mistake.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants