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

[SR-14311] swift-api-extract crashes when a swiftmodule has a native dependency #56670

swift-ci opened this issue Mar 6, 2021 · 3 comments


Copy link

swift-ci commented Mar 6, 2021

Previous ID SR-14311
Radar None
Original Reporter migueldeicaza (JIRA User)
Type Bug
Status Resolved
Resolution Done

Attachment: Download


MacOS 11.2.1

Darwin miguels-mac-pro.lan 20.3.0 Darwin Kernel Version 20.3.0: Thu Jan 21 00:07:06 PST 2021; root:xnu-7195.81.3~1/RELEASE_X86_64 x86_64

Using swift-DEVELOPMENT-SNAPSHOT-2021-03-02-a

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee @cachemeifyoucan
Priority Medium

md5: ae9232800ffe2a585e4686566d492101

Issue Description:

I took the new swift-api-extract for a ride, and found that while it can dump the API for .swiftmodules, if this swiftmodule depends on a native library, the program crashes with the following assertion:

<unknown>:0: error: missing required module 'NativeDep'

Assertion failed: (!Files.empty() && "No files added yet"), function getMainFile, file /Users/buildnode/jenkins/workspace/oss-swift-package-macos/swift/include/swift/AST/FileUnit.h, line 423.

I have provided a self-contained test case that shows the problem.

If you checkout this git repo. or use the attached sample you can see it.

And run "make", this will build, and then attempt to use swift-api-extract, which will crash with the above message. It seems to want a .swiftmodule for the NativeDep library, but since it is a C library, there is no swiftmodule available for it.

Copy link

cachemeifyoucan commented Mar 8, 2021

Thanks for testing driving the new option. I kind of aware of this can happen when I write the current implementation (along with other issues, like you cannot request api-extract on a non swift modules). I will keep improving on the current implementation, and at the same time, don't develop serious dependency on the current JSON output format and expect that will be stable.

Copy link

cachemeifyoucan commented Mar 19, 2021

I took a quick look at this bug. This is not actually what I thought it was. This is likely because of either using the wrong underlying compiler from swift PM (which you need to overwrite with a just built toolchain):

<unknown>:0: error: module compiled with Swift 5.4 cannot be imported by the Swift 5.5 compiler: /@input/ApiDemo.swiftmodule

or (which you need to give clang importer a search path to locate NativeDep, which the option doesn't exist yet):

<unknown>:0: error: missing required module 'NativeDep'

I think I need to turn on module loading remarks and exit early when there are errors when loading module.

Copy link

cachemeifyoucan commented Mar 19, 2021


@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

2 participants