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>">, MetaVarName<"<arg>">,
HelpText<"Pass <arg> to llvm.">; 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]>, def target : Joined<["--"], "target=">, Flags<[DriverOption, FrontendOption]>,
HelpText<"Generate code for the given target">; HelpText<"Generate code for the given target">;
def target_legacy_spelling : Separate<["-"], "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.AddAllArgs(arguments, options::OPT_I);
inputArgs.AddLastArg(arguments, options::OPT_g); inputArgs.AddLastArg(arguments, options::OPT_g);
inputArgs.AddLastArg(arguments, options::OPT_resource_dir);
// Pass through any -Xllvm flags. // Pass through any -Xllvm flags.
inputArgs.AddAllArgs(arguments, options::OPT_Xllvm); 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 // FIXME: Duplicated from CompilerInvocation, but in theory the runtime
// library link path and the standard library module import path don't // library link path and the standard library module import path don't
// need to be the same. // 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 /swift
llvm::sys::path::remove_filename(RuntimeLibPath); // remove /bin llvm::sys::path::remove_filename(RuntimeLibPath); // remove /bin
llvm::sys::path::append(RuntimeLibPath, "lib", "swift"); llvm::sys::path::append(RuntimeLibPath, "lib", "swift");
}
llvm::sys::path::append(RuntimeLibPath, llvm::sys::path::append(RuntimeLibPath,
getPlatformNameForTriple(TC.getTriple())); getPlatformNameForTriple(TC.getTriple()));
Arguments.push_back("-L"); Arguments.push_back("-L");

View File

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

View File

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

View File

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