Skip to content

Commit eedb8e6

Browse files
committed
ClangImporter: support SDK for APINotes
Honour the SDK for APINotes to augment the system libraries. This allows us to distribute APINotes with the Swift SDK and impact the system without having to map the APINotes into the filesystem.
1 parent d3cfaa3 commit eedb8e6

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -751,10 +751,24 @@ void importer::getNormalInvocationArguments(
751751
invocationArgStrs.push_back("-fapinotes-modules");
752752
invocationArgStrs.push_back("-fapinotes-swift-version=" +
753753
languageVersion.asAPINotesVersionString());
754-
invocationArgStrs.push_back("-iapinotes-modules");
755-
invocationArgStrs.push_back((llvm::Twine(searchPathOpts.RuntimeResourcePath) +
756-
llvm::sys::path::get_separator() +
757-
"apinotes").str());
754+
755+
// Prefer `-sdk` paths.
756+
if (!searchPathOpts.getSDKPath().empty()) {
757+
llvm::SmallString<261> path{searchPathOpts.getSDKPath()};
758+
llvm::sys::path::append(path, "usr", "lib", "swift", "apinotes");
759+
760+
invocationArgStrs.push_back("-iapinotes-modules");
761+
invocationArgStrs.push_back(path.str().str());
762+
}
763+
764+
// Fallback to "legacy" `-resource-dir` paths.
765+
{
766+
llvm::SmallString<261> path{searchPathOpts.RuntimeResourcePath};
767+
llvm::sys::path::append(path, "apinotes");
768+
769+
invocationArgStrs.push_back("-iapinotes-modules");
770+
invocationArgStrs.push_back(path.str().str());
771+
}
758772
}
759773

760774
static void

test/ClangImporter/sdk-apinotes.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck %s -verify
2+
3+
import cfuncs
4+
5+
[nil].withUnsafeBufferPointer(nullability_note)

test/Inputs/clang-importer-sdk/usr/include/cfuncs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,5 @@ void opaque_pointer_param(struct not_importable *);
6060

6161
int unsupported_parameter_type(int param1, _Complex int param2);
6262
_Complex int unsupported_return_type();
63+
64+
void nullability_note(const char * _Nonnull const * _Nonnull parameter);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
Name: cfuncs
3+
Functions:
4+
- nullability_note
5+
Parameters:
6+
- Position: 0
7+
Type: "const char * _Nullable const * _Nonnull"

0 commit comments

Comments
 (0)