Skip to content

Merge getRuntimeLibraryPath and getRuntimeStaticLibraryPath #15388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 22, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 11 additions & 32 deletions lib/Driver/ToolChains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,8 @@ static void addPathEnvironmentVariableIfNeeded(Job::EnvironmentVector &env,
/// relative to the compiler.
static void getRuntimeLibraryPath(SmallVectorImpl<char> &runtimeLibPath,
const llvm::opt::ArgList &args,
const ToolChain &TC) {
const ToolChain &TC,
bool shared) {
// 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.
Expand All @@ -1037,7 +1038,7 @@ static void getRuntimeLibraryPath(SmallVectorImpl<char> &runtimeLibPath,
runtimeLibPath.append(programPath.begin(), programPath.end());
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, "lib", shared ? "swift" : "swift_static");
}
llvm::sys::path::append(runtimeLibPath,
getPlatformNameForTriple(TC.getTriple()));
Expand All @@ -1047,43 +1048,21 @@ static void getClangLibraryPath(const ToolChain &TC, const ArgList &Args,
SmallString<128> &LibPath) {
const llvm::Triple &T = TC.getTriple();

getRuntimeLibraryPath(LibPath, Args, TC);
getRuntimeLibraryPath(LibPath, Args, TC, /*Shared=*/ true);
// Remove platform name.
llvm::sys::path::remove_filename(LibPath);
llvm::sys::path::append(LibPath, "clang", "lib",
T.isOSDarwin() ? "darwin"
: getPlatformNameForTriple(T));
}

/// Get the runtime library link path for static linking,
/// which is platform-specific and found relative to the compiler.
static void getRuntimeStaticLibraryPath(SmallVectorImpl<char> &runtimeLibPath,
const llvm::opt::ArgList &args,
const ToolChain &TC) {
// 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.
if (const Arg *A = args.getLastArg(options::OPT_resource_dir)) {
StringRef value = A->getValue();
runtimeLibPath.append(value.begin(), value.end());
} else {
auto programPath = TC.getDriver().getSwiftProgramPath();
runtimeLibPath.append(programPath.begin(), programPath.end());
llvm::sys::path::remove_filename(runtimeLibPath); // remove /swift
llvm::sys::path::remove_filename(runtimeLibPath); // remove /bin
llvm::sys::path::append(runtimeLibPath, "lib", "swift_static");
}
llvm::sys::path::append(runtimeLibPath,
getPlatformNameForTriple(TC.getTriple()));
}

ToolChain::InvocationInfo
toolchains::Darwin::constructInvocation(const InterpretJobAction &job,
const JobContext &context) const {
InvocationInfo II = ToolChain::constructInvocation(job, context);

SmallString<128> runtimeLibraryPath;
getRuntimeLibraryPath(runtimeLibraryPath, context.Args, *this);
getRuntimeLibraryPath(runtimeLibraryPath, context.Args, *this, /*Shared=*/ true);

addPathEnvironmentVariableIfNeeded(II.ExtraEnvironment, "DYLD_LIBRARY_PATH",
":", options::OPT_L, context.Args,
Expand Down Expand Up @@ -1188,7 +1167,7 @@ addLinkRuntimeLibForLinux(const ArgList &Args, ArgStringList &Arguments,
StringRef LinuxLibName,
const ToolChain &TC) {
SmallString<128> Dir;
getRuntimeLibraryPath(Dir, Args, TC);
getRuntimeLibraryPath(Dir, Args, TC, /*Shared=*/ true);
// Remove platform name.
llvm::sys::path::remove_filename(Dir);
llvm::sys::path::append(Dir, "clang", "lib", "linux");
Expand Down Expand Up @@ -1397,15 +1376,15 @@ toolchains::Darwin::constructInvocation(const LinkJobAction &job,
// Add the runtime library link path, which is platform-specific and found
// relative to the compiler.
SmallString<128> RuntimeLibPath;
getRuntimeLibraryPath(RuntimeLibPath, context.Args, *this);
getRuntimeLibraryPath(RuntimeLibPath, context.Args, *this, /*Shared=*/ true);

// Link the standard library.
Arguments.push_back("-L");
if (context.Args.hasFlag(options::OPT_static_stdlib,
options::OPT_no_static_stdlib,
false)) {
SmallString<128> StaticRuntimeLibPath;
getRuntimeStaticLibraryPath(StaticRuntimeLibPath, context.Args, *this);
getRuntimeLibraryPath(StaticRuntimeLibPath, context.Args, *this, /*Shared=*/ false);
Arguments.push_back(context.Args.MakeArgString(StaticRuntimeLibPath));
Arguments.push_back("-lc++");
Arguments.push_back("-framework");
Expand Down Expand Up @@ -1504,7 +1483,7 @@ toolchains::GenericUnix::constructInvocation(const InterpretJobAction &job,
InvocationInfo II = ToolChain::constructInvocation(job, context);

SmallString<128> runtimeLibraryPath;
getRuntimeLibraryPath(runtimeLibraryPath, context.Args, *this);
getRuntimeLibraryPath(runtimeLibraryPath, context.Args, *this, /*Shared=*/ true);

addPathEnvironmentVariableIfNeeded(II.ExtraEnvironment, "LD_LIBRARY_PATH",
":", options::OPT_L, context.Args,
Expand Down Expand Up @@ -1638,10 +1617,10 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job,
}

SmallString<128> SharedRuntimeLibPath;
getRuntimeLibraryPath(SharedRuntimeLibPath, context.Args, *this);
getRuntimeLibraryPath(SharedRuntimeLibPath, context.Args, *this, /*Shared=*/ true);

SmallString<128> StaticRuntimeLibPath;
getRuntimeStaticLibraryPath(StaticRuntimeLibPath, context.Args, *this);
getRuntimeLibraryPath(StaticRuntimeLibPath, context.Args, *this, /*Shared=*/ false);

// Add the runtime library link path, which is platform-specific and found
// relative to the compiler.
Expand Down