diff --git a/include/swift/ClangImporter/ClangImporter.h b/include/swift/ClangImporter/ClangImporter.h index c0c8e823c2d..81dd56e2471 100644 --- a/include/swift/ClangImporter/ClangImporter.h +++ b/include/swift/ClangImporter/ClangImporter.h @@ -76,7 +76,8 @@ public: StringRef moduleCachePath, ArrayRef importSearchPaths = {}, ArrayRef frameworkSearchPaths = {}, - StringRef overrideResourceDir = StringRef()); + StringRef overrideResourceDir = StringRef(), + ArrayRef extraArgs = {}); ClangImporter(const ClangImporter &) = delete; ClangImporter(ClangImporter &&) = delete; diff --git a/include/swift/Frontend/Frontend.h b/include/swift/Frontend/Frontend.h index 7856bce1c14..53fe83b383b 100644 --- a/include/swift/Frontend/Frontend.h +++ b/include/swift/Frontend/Frontend.h @@ -50,6 +50,7 @@ class CompilerInvocation { SmallVector LinkLibraries; std::string RuntimeIncludePath; std::string SDKPath; + std::vector ExtraClangArgs; LangOptions LangOpts; @@ -100,7 +101,7 @@ public: ImportSearchPaths = Paths; } - std::vector getImportSearchPaths() const { + ArrayRef getImportSearchPaths() const { return ImportSearchPaths; } @@ -108,10 +109,18 @@ public: FrameworkSearchPaths = Paths; } - std::vector getFrameworkSearchPaths() const { + ArrayRef getFrameworkSearchPaths() const { return FrameworkSearchPaths; } + void setExtraClangArgs(const std::vector &Args) { + ExtraClangArgs = Args; + } + + ArrayRef getExtraClangArgs() const { + return ExtraClangArgs; + } + void addLinkLibrary(StringRef name, LibraryKind kind) { LinkLibraries.push_back({name, kind}); } diff --git a/lib/ClangImporter/ClangImporter.cpp b/lib/ClangImporter/ClangImporter.cpp index c8a4907dafc..407cf4e1b9e 100644 --- a/lib/ClangImporter/ClangImporter.cpp +++ b/lib/ClangImporter/ClangImporter.cpp @@ -85,7 +85,8 @@ ClangImporter *ClangImporter::create(ASTContext &ctx, StringRef sdkroot, StringRef moduleCachePath, ArrayRef importSearchPaths, ArrayRef frameworkSearchPaths, - StringRef overrideResourceDir) { + StringRef overrideResourceDir, + ArrayRef extraArgs) { std::unique_ptr importer(new ClangImporter(ctx)); // Create a Clang diagnostics engine. @@ -151,6 +152,10 @@ ClangImporter *ClangImporter::create(ASTContext &ctx, StringRef sdkroot, invocationArgStrs.push_back(overrideResourceDir); } + for (auto extraArg : extraArgs) { + invocationArgStrs.push_back(extraArg); + } + std::vector invocationArgs; for (auto &argStr : invocationArgStrs) invocationArgs.push_back(argStr.c_str()); diff --git a/lib/Frontend/Frontend.cpp b/lib/Frontend/Frontend.cpp index bf94eadfaee..f421dd8a303 100644 --- a/lib/Frontend/Frontend.cpp +++ b/lib/Frontend/Frontend.cpp @@ -62,7 +62,7 @@ bool swift::CompilerInstance::setup(const CompilerInvocation &Invok) { Invocation.getClangModuleCachePath(), Invocation.getImportSearchPaths(), Invocation.getFrameworkSearchPaths(), - StringRef()); + StringRef(), Invocation.getExtraClangArgs()); if (!clangImporter) { Diagnostics.diagnose(SourceLoc(), diag::error_clang_importer_create_fail); return true;