mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Add a -l flag to Swift and use it to provide autolinking information.
The spelling of the flag can certainly be changed; I just wanted to get something up and running. Swift SVN r7582
This commit is contained in:
@@ -279,13 +279,15 @@ public:
|
|||||||
/// external references in a translation unit, which is one file.
|
/// external references in a translation unit, which is one file.
|
||||||
class TranslationUnit : public Module {
|
class TranslationUnit : public Module {
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/// This is the list of modules that are imported by this module, with the
|
/// This is the list of modules that are imported by this module, with the
|
||||||
/// second element of the pair declaring whether the module is reexported.
|
/// second element of the pair declaring whether the module is reexported.
|
||||||
///
|
///
|
||||||
/// This is filled in by the Name Binding phase.
|
/// This is filled in by the Name Binding phase.
|
||||||
ArrayRef<std::pair<ImportedModule, bool>> Imports;
|
ArrayRef<std::pair<ImportedModule, bool>> Imports;
|
||||||
|
|
||||||
|
/// The list of libraries specified as link-time dependencies at compile time.
|
||||||
|
ArrayRef<LinkLibrary> LinkLibraries;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// Kind - This is the sort of file the translation unit was parsed for, which
|
/// Kind - This is the sort of file the translation unit was parsed for, which
|
||||||
/// can affect some type checking and other behavior.
|
/// can affect some type checking and other behavior.
|
||||||
@@ -330,6 +332,14 @@ public:
|
|||||||
Imports = IM;
|
Imports = IM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setLinkLibraries(ArrayRef<LinkLibrary> libs) {
|
||||||
|
assert(LinkLibraries.empty() && "link libraries already set");
|
||||||
|
LinkLibraries = libs;
|
||||||
|
}
|
||||||
|
ArrayRef<LinkLibrary> getLinkLibraries() const {
|
||||||
|
return LinkLibraries;
|
||||||
|
}
|
||||||
|
|
||||||
void clearLookupCache();
|
void clearLookupCache();
|
||||||
|
|
||||||
void cacheVisibleDecls(SmallVectorImpl<ValueDecl *> &&globals) const;
|
void cacheVisibleDecls(SmallVectorImpl<ValueDecl *> &&globals) const;
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
#include "swift/Basic/LangOptions.h"
|
#include "swift/Basic/LangOptions.h"
|
||||||
#include "swift/Basic/SourceManager.h"
|
#include "swift/Basic/SourceManager.h"
|
||||||
#include "swift/AST/DiagnosticEngine.h"
|
#include "swift/AST/DiagnosticEngine.h"
|
||||||
|
#include "swift/AST/LinkLibrary.h"
|
||||||
#include "swift/AST/Module.h"
|
#include "swift/AST/Module.h"
|
||||||
#include "swift/Parse/CodeCompletionCallbacks.h"
|
#include "swift/Parse/CodeCompletionCallbacks.h"
|
||||||
#include "swift/Parse/Parser.h"
|
#include "swift/Parse/Parser.h"
|
||||||
@@ -44,6 +45,7 @@ class CompilerInvocation {
|
|||||||
std::string ClangModuleCachePath;
|
std::string ClangModuleCachePath;
|
||||||
std::vector<std::string> ImportSearchPaths;
|
std::vector<std::string> ImportSearchPaths;
|
||||||
std::vector<std::string> FrameworkSearchPaths;
|
std::vector<std::string> FrameworkSearchPaths;
|
||||||
|
SmallVector<LinkLibrary, 4> LinkLibraries;
|
||||||
std::string RuntimeIncludePath;
|
std::string RuntimeIncludePath;
|
||||||
std::string SDKPath;
|
std::string SDKPath;
|
||||||
|
|
||||||
@@ -107,6 +109,14 @@ public:
|
|||||||
return FrameworkSearchPaths;
|
return FrameworkSearchPaths;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void addLinkLibrary(StringRef name, LibraryKind kind) {
|
||||||
|
LinkLibraries.push_back({name, kind});
|
||||||
|
}
|
||||||
|
|
||||||
|
ArrayRef<LinkLibrary> getLinkLibraries() const {
|
||||||
|
return LinkLibraries;
|
||||||
|
}
|
||||||
|
|
||||||
void setMainExecutablePath(StringRef Path);
|
void setMainExecutablePath(StringRef Path);
|
||||||
|
|
||||||
void setRuntimeIncludePath(StringRef Path) {
|
void setRuntimeIncludePath(StringRef Path) {
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "swift/AST/Diagnostics.h"
|
#include "swift/AST/Diagnostics.h"
|
||||||
|
#include "swift/AST/LinkLibrary.h"
|
||||||
#include "swift/AST/Module.h"
|
#include "swift/AST/Module.h"
|
||||||
#include "swift/AST/ModuleLoader.h"
|
#include "swift/AST/ModuleLoader.h"
|
||||||
#include "swift/AST/NameLookup.h"
|
#include "swift/AST/NameLookup.h"
|
||||||
@@ -535,8 +536,9 @@ void Module::collectLinkLibraries(LinkLibraryCallback callback) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isa<TranslationUnit>(module)) {
|
if (auto TU = dyn_cast<TranslationUnit>(module)) {
|
||||||
// FIXME: Should we include libraries specified by the user here?
|
for (auto lib : TU->getLinkLibraries())
|
||||||
|
callback(lib);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -123,6 +123,10 @@ bool CompilerInvocation::parseArgs(ArrayRef<const char *> Args,
|
|||||||
case OPT_enable_definite_init:
|
case OPT_enable_definite_init:
|
||||||
LangOpts.UseDefiniteInit = true;
|
LangOpts.UseDefiniteInit = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case OPT_link_library:
|
||||||
|
addLinkLibrary(InputArg->getValue(), LibraryKind::Library);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -124,6 +124,7 @@ void swift::CompilerInstance::doIt() {
|
|||||||
Context->LoadedModules[ID.str()] = TU;
|
Context->LoadedModules[ID.str()] = TU;
|
||||||
|
|
||||||
TU->HasBuiltinModuleAccess = Invocation.getParseStdlib();
|
TU->HasBuiltinModuleAccess = Invocation.getParseStdlib();
|
||||||
|
TU->setLinkLibraries(Invocation.getLinkLibraries());
|
||||||
|
|
||||||
// If we're in SIL mode, don't auto import any libraries.
|
// If we're in SIL mode, don't auto import any libraries.
|
||||||
// Also don't perform auto import if we are not going to do semantic
|
// Also don't perform auto import if we are not going to do semantic
|
||||||
|
|||||||
@@ -20,6 +20,9 @@ def parse_as_library : Flag<["-"], "parse-as-library">,
|
|||||||
def parse_stdlib : Flag<["-"], "parse-stdlib">,
|
def parse_stdlib : Flag<["-"], "parse-stdlib">,
|
||||||
HelpText<"Parse the input as the swift standard library">;
|
HelpText<"Parse the input as the swift standard library">;
|
||||||
|
|
||||||
|
def link_library : Joined<["-"], "l">,
|
||||||
|
HelpText<"Link the given library into the output product">;
|
||||||
|
|
||||||
// LangOptions
|
// LangOptions
|
||||||
def debug_constraints : Flag<["-"], "debug-constraints">,
|
def debug_constraints : Flag<["-"], "debug-constraints">,
|
||||||
HelpText<"Debug the constraint-based type checker">;
|
HelpText<"Debug the constraint-based type checker">;
|
||||||
|
|||||||
5
test/Serialization/autolinking.swift
Normal file
5
test/Serialization/autolinking.swift
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
// RUN: %swift -emit-llvm -lmagic %s | FileCheck %s
|
||||||
|
|
||||||
|
// CHECK: !{{[0-9]+}} = metadata !{i32 6, metadata !"Linker Options", metadata ![[LINK_LIST:[0-9]+]]}
|
||||||
|
// CHECK: ![[LINK_LIST]] = metadata !{
|
||||||
|
// CHECK-DAG: !{{[0-9]+}} = metadata !{metadata !"-lmagic"}
|
||||||
Reference in New Issue
Block a user