Add -resource-dir option to find lib/swift directory.

This is equivalent to Clang's -fresource-dir; it provides the location of
compiler modules and libraries.

No end-user-visible changes, but the iOS build will no longer have to use
-I to build and test its own standard libraries.

Swift SVN r13888
This commit is contained in:
Jordan Rose
2014-02-14 01:27:15 +00:00
parent 327439f3ab
commit 93b87edcbe
5 changed files with 40 additions and 32 deletions

View File

@@ -247,6 +247,11 @@ def Xllvm : Separate<["-"], "Xllvm">, Flags<[DriverOption, FrontendOption]>,
MetaVarName<"<arg>">,
HelpText<"Pass <arg> to llvm.">;
def resource_dir : Separate<["-"], "resource-dir">,
Flags<[DriverOption, FrontendOption, HelpHidden]>,
MetaVarName<"</usr/lib/swift>">,
HelpText<"The directory that holds the compiler resource files">;
def target : Joined<["--"], "target=">, Flags<[DriverOption, FrontendOption]>,
HelpText<"Generate code for the given target">;
def target_legacy_spelling : Separate<["-"], "target">,

View File

@@ -110,6 +110,7 @@ static void addCommonFrontendArgs(const ToolChain &TC,
inputArgs.AddAllArgs(arguments, options::OPT_I);
inputArgs.AddLastArg(arguments, options::OPT_g);
inputArgs.AddLastArg(arguments, options::OPT_resource_dir);
// Pass through any -Xllvm flags.
inputArgs.AddAllArgs(arguments, options::OPT_Xllvm);
@@ -431,10 +432,16 @@ Job *darwin::Linker::constructJob(const JobAction &JA,
// FIXME: Duplicated from CompilerInvocation, but in theory the runtime
// library link path and the standard library module import path don't
// need to be the same.
llvm::SmallString<128> RuntimeLibPath(D.getSwiftProgramPath());
llvm::SmallString<128> RuntimeLibPath;
if (const Arg *A = Args.getLastArg(options::OPT_resource_dir)) {
RuntimeLibPath = A->getValue();
} else {
RuntimeLibPath = D.getSwiftProgramPath();
llvm::sys::path::remove_filename(RuntimeLibPath); // remove /swift
llvm::sys::path::remove_filename(RuntimeLibPath); // remove /bin
llvm::sys::path::append(RuntimeLibPath, "lib", "swift");
}
llvm::sys::path::append(RuntimeLibPath,
getPlatformNameForTriple(TC.getTriple()));
Arguments.push_back("-L");

View File

@@ -550,6 +550,10 @@ static bool ParseSearchPathArgs(SearchPathOptions &Opts, ArgList &Args,
Opts.SDKPath = A->getValue();
}
if (const Arg *A = Args.getLastArg(OPT_resource_dir)) {
Opts.RuntimeResourcePath = A->getValue();
}
// Opts.RuntimeIncludePath is set by calls to
// setRuntimeIncludePath() or setMainExecutablePath().
// Opts.RuntimeImportPath is set by calls to

View File

@@ -71,10 +71,6 @@
#include <histedit.h>
#include <dlfcn.h>
#ifndef SWIFT_TOOLCHAIN_SUBDIR
#define SWIFT_TOOLCHAIN_SUBDIR "swift"
#endif
using namespace swift;
namespace {
@@ -169,24 +165,18 @@ static void convertToUTF8(llvm::ArrayRef<wchar_t> wide,
} // end anonymous namespace
static bool loadRuntimeLib(StringRef sharedLibName,
const ProcessCmdLine &CmdLine) {
static bool loadRuntimeLib(StringRef sharedLibName, StringRef runtimeLibPath) {
// FIXME: Need error-checking.
llvm::SmallString<128> Path(
llvm::sys::fs::getMainExecutable(CmdLine[0].data(),
(void*)&swift::RunImmediately));
llvm::sys::path::remove_filename(Path); // Remove /executable
llvm::sys::path::remove_filename(Path); // Remove /bin
llvm::sys::path::append(Path, "lib", SWIFT_TOOLCHAIN_SUBDIR, sharedLibName);
llvm::SmallString<128> Path = runtimeLibPath;
llvm::sys::path::append(Path, sharedLibName);
return dlopen(Path.c_str(), 0);
}
static bool loadSwiftRuntime(const ProcessCmdLine &CmdLine) {
// We rely on @rpath to find the core Swift stdlib.
return dlopen("libswift_stdlib_core.dylib", 0);
static bool loadSwiftRuntime(StringRef runtimeLibPath) {
return loadRuntimeLib("libswift_stdlib_core.dylib", runtimeLibPath);
}
static bool tryLoadLibrary(LinkLibrary linkLib, const ProcessCmdLine &CmdLine,
static bool tryLoadLibrary(LinkLibrary linkLib, StringRef runtimeLibPath,
DiagnosticEngine &diags) {
// If we have an absolute path, just try to load it now.
llvm::SmallString<128> path = linkLib.getName();
@@ -216,7 +206,7 @@ static bool tryLoadLibrary(LinkLibrary linkLib, const ProcessCmdLine &CmdLine,
success = dlopen(path.c_str(), 0);
if (!success && linkLib.getKind() == LibraryKind::Library) {
// Try our runtime library path.
success = loadRuntimeLib(path, CmdLine);
success = loadRuntimeLib(path, runtimeLibPath);
}
}
@@ -230,7 +220,6 @@ static bool tryLoadLibrary(LinkLibrary linkLib, const ProcessCmdLine &CmdLine,
static bool IRGenImportedModules(CompilerInstance &CI,
llvm::Module &Module,
const ProcessCmdLine &CmdLine,
llvm::SmallPtrSet<swift::Module *, 8>
&ImportedModules,
SmallVectorImpl<llvm::Function*> &InitFns,
@@ -242,7 +231,9 @@ static bool IRGenImportedModules(CompilerInstance &CI,
// Perform autolinking.
auto addLinkLibrary = [&](LinkLibrary linkLib) {
if (!tryLoadLibrary(linkLib, CmdLine, CI.getDiags()))
if (!tryLoadLibrary(linkLib,
CI.getASTContext().SearchPathOpts.RuntimeLibraryPath,
CI.getDiags()))
hadError = true;
};
std::for_each(IRGenOpts.LinkLibraries.begin(), IRGenOpts.LinkLibraries.end(),
@@ -328,8 +319,8 @@ void swift::RunImmediately(CompilerInstance &CI, const ProcessCmdLine &CmdLine,
SmallVector<llvm::Function*, 8> InitFns;
llvm::SmallPtrSet<swift::Module *, 8> ImportedModules;
if (IRGenImportedModules(CI, *Module, CmdLine, ImportedModules,
InitFns, IRGenOpts, SILOpts, /*IsREPL*/false))
if (IRGenImportedModules(CI, *Module, ImportedModules, InitFns,
IRGenOpts, SILOpts, /*IsREPL*/false))
return;
llvm::PassManagerBuilder PMBuilder;
@@ -340,7 +331,7 @@ void swift::RunImmediately(CompilerInstance &CI, const ProcessCmdLine &CmdLine,
PMBuilder.populateModulePassManager(ModulePasses);
ModulePasses.run(*Module);
if (!loadSwiftRuntime(CmdLine)) {
if (!loadSwiftRuntime(Context.SearchPathOpts.RuntimeLibraryPath)) {
CI.getDiags().diagnose(SourceLoc(),
diag::error_immediate_mode_missing_stdlib);
return;
@@ -1012,7 +1003,7 @@ private:
llvm::Function *DumpModuleMain = DumpModule.getFunction("main");
DumpModuleMain->setName("repl.line");
if (IRGenImportedModules(CI, Module, CmdLine, ImportedModules, InitFns,
if (IRGenImportedModules(CI, Module, ImportedModules, InitFns,
IRGenOpts, SILOpts, sil.get()))
return false;
@@ -1056,14 +1047,16 @@ public:
/*RanREPLApplicationMain*/ false
}
{
if (!loadSwiftRuntime(CmdLine)) {
ASTContext &Ctx = CI.getASTContext();
if (!loadSwiftRuntime(Ctx.SearchPathOpts.RuntimeLibraryPath)) {
CI.getDiags().diagnose(SourceLoc(),
diag::error_immediate_mode_missing_stdlib);
return;
}
std::for_each(CI.getLinkLibraries().begin(), CI.getLinkLibraries().end(),
[&](LinkLibrary linkLib) {
tryLoadLibrary(linkLib, CmdLine, CI.getDiags());
tryLoadLibrary(linkLib, Ctx.SearchPathOpts.RuntimeLibraryPath,
CI.getDiags());
});
llvm::EngineBuilder builder(&Module);
@@ -1092,7 +1085,7 @@ public:
REPLInputFile, PersistentState, RC,
llvm::MemoryBuffer::getMemBufferCopy(WarmUpStmt,
"<REPL Initialization>"));
if (CI.getASTContext().hadError())
if (Ctx.hadError())
return;
RC.CurElem = RC.CurIRGenElem = REPLInputFile.Decls.size();

View File

@@ -11,8 +11,7 @@ target_link_libraries(swift_old edit ${CORE_FOUNDATION})
if(MODULES_SDK)
add_definitions( -DSWIFT_MODULES_SDK="${MODULES_SDK}"
-DSWIFT_MODULE_CACHE_PATH="${SWIFT_MODULE_CACHE_PATH}"
-DSWIFT_TOOLCHAIN_SUBDIR="${SWIFTLIB_SUBDIR}" )
-DSWIFT_MODULE_CACHE_PATH="${SWIFT_MODULE_CACHE_PATH}" )
endif()
if (SWIFT_SUBMIT_VERSION)