Skip to content

Cascading Swift Support Search #26388

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
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
8 changes: 3 additions & 5 deletions lib/Driver/ToolChains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1172,11 +1172,6 @@ void ToolChain::getResourceDirPath(SmallVectorImpl<char> &resourceDirPath,
if (const Arg *A = args.getLastArg(options::OPT_resource_dir)) {
StringRef value = A->getValue();
resourceDirPath.append(value.begin(), value.end());
} else if (!getTriple().isOSDarwin() && args.hasArg(options::OPT_sdk)) {
StringRef value = args.getLastArg(options::OPT_sdk)->getValue();
resourceDirPath.append(value.begin(), value.end());
llvm::sys::path::append(resourceDirPath, "usr", "lib",
shared ? "swift" : "swift_static");
} else {
auto programPath = getDriver().getSwiftProgramPath();
resourceDirPath.append(programPath.begin(), programPath.end());
Expand All @@ -1200,6 +1195,9 @@ void ToolChain::getRuntimeLibraryPaths(SmallVectorImpl<std::string> &runtimeLibP
scratchPath = SDKPath;
llvm::sys::path::append(scratchPath, "usr", "lib", "swift");
runtimeLibPaths.push_back(scratchPath.str());

llvm::sys::path::append(scratchPath, getPlatformNameForTriple(getTriple()));
runtimeLibPaths.push_back(scratchPath.str());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't make sense either. Right now there's no difference between an SDK and a sysroot; we should not have platform-specific subdirs in a sysroot. (Architecture, maybe, but not platform.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with you on that in principle. The problem is that the current swift build doesn't have a way to do this. I think that doing this improperly and then working to address the limitation in the swift build is an effective way forward. I've tested this set of changes and it is sufficient to build libdispatch, foundation, xctest. Without this, the builds do fail.

The layout is something that I will be bringing up on the forums as well because I think that we need to figure this out to get some stability going forward.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that the current swift build doesn't have a way to do this.

I'm not sure what you mean. The "current Swift build" is Apple platforms and "Linux", plus perhaps the platforms tested by the ci-external bots. What scenario are you actually trying to handle by searching for $SDK/usr/lib/swift/$PLATFORM/swiftrt.o?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant that the current CMake setup in the swift repository doesn't have a way to generate the desired layout. I'd like to improve that, but, doing the split build is extremely helpful and I'd like to have that working as we start to iterate on the CMake support to build the SDK layout.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we care about the CMake support producing the desired layout, rather than needing a post-processing step?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, ideally, we wouldn't need to have a post-processing step. In the ideal mythical configuration, we would use the LLVM's distribution mechanism to control which pieces are installed into a distribution image, which is fully ready to use and installed to the location of choice (that is, you just specify the DESTDIR= to say where you want the image rooted). You can just package that up or copy that to another location and just use it.

Copy link
Contributor

@jrose-apple jrose-apple Jul 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but while we're in the non-ideal world, I'd prefer that cross-compile configurations need a bit of manual fix-up rather than the compiler adding default search paths that don't make sense.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are just coming at it from a different perspective I suppose. I would prefer that we do the work in the driver until the build works, and you would prefer that some other entity do the work until the build does it. Does it make that much of a difference?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, yes. If it's in the compiler, people start depending on it, and it can have effects on configurations other than the one we care about, and it affects other contributors who now need to take the case into consideration.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There already are a number of incorrect things in the layout that people may be depending on. If this is specifically about Darwin, I can easily limit this to non-Darwin targets. That said, I do agree that if we can avoid it, its better. I've start working on this in #26409 which tries to build up the SDK image. Probably would be a good idea to identify the missing pieces.

}
}

Expand Down
2 changes: 2 additions & 0 deletions lib/Driver/ToolChains.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ class LLVM_LIBRARY_VISIBILITY GenericUnix : public ToolChain {
InvocationInfo constructInvocation(const StaticLinkJobAction &job,
const JobContext &context) const override;

const char *getSwiftRuntimeSupportPath(const llvm::opt::ArgList &Arg) const;

public:
GenericUnix(const Driver &D, const llvm::Triple &Triple)
: ToolChain(D, Triple) {}
Expand Down
39 changes: 31 additions & 8 deletions lib/Driver/UnixToolChains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,32 @@ bool toolchains::GenericUnix::shouldProvideRPathToLinker() const {
return true;
}

const char *toolchains::GenericUnix::getSwiftRuntimeSupportPath(
const llvm::opt::ArgList &Args) const {
const llvm::Triple &Triple = getTriple();
StringRef platform = swift::getPlatformNameForTriple(Triple);
StringRef arch = swift::getMajorArchitectureName(Triple);

// prefer the content in `-sdk`
if (const auto *A = Args.getLastArg(options::OPT_sdk)) {
StringRef SDKPath = A->getValue();
SmallString<128> buffer;

buffer.append(SDKPath.begin(), SDKPath.end());
llvm::sys::path::append(buffer, "usr", "lib", "swift");
llvm::sys::path::append(buffer, platform, arch, "swiftrt.o");

if (llvm::sys::fs::exists(buffer))
return Args.MakeArgString(buffer);
}

// fallback to the resource dir
SmallString<128> buffer;
getResourceDirPath(buffer, Args, /*Shared=*/true);
llvm::sys::path::append(buffer, arch, "swiftrt.o");
return Args.MakeArgString(buffer);
}

ToolChain::InvocationInfo
toolchains::GenericUnix::constructInvocation(const DynamicLinkJobAction &job,
const JobContext &context) const {
Expand Down Expand Up @@ -219,14 +245,8 @@ toolchains::GenericUnix::constructInvocation(const DynamicLinkJobAction &job,
}
}

SmallString<128> SharedResourceDirPath;
getResourceDirPath(SharedResourceDirPath, context.Args, /*Shared=*/true);

SmallString<128> swiftrtPath = SharedResourceDirPath;
llvm::sys::path::append(swiftrtPath,
swift::getMajorArchitectureName(getTriple()));
llvm::sys::path::append(swiftrtPath, "swiftrt.o");
Arguments.push_back(context.Args.MakeArgString(swiftrtPath));
// swiftrt.o
Arguments.push_back(getSwiftRuntimeSupportPath(context.Args));

addPrimaryInputsOfType(Arguments, context.Inputs, context.Args,
file_types::TY_Object);
Expand Down Expand Up @@ -302,6 +322,9 @@ toolchains::GenericUnix::constructInvocation(const DynamicLinkJobAction &job,
}

if (context.Args.hasArg(options::OPT_profile_generate)) {
SmallString<128> SharedResourceDirPath;
getResourceDirPath(SharedResourceDirPath, context.Args, /*Shared=*/true);

SmallString<128> LibProfile(SharedResourceDirPath);
llvm::sys::path::remove_filename(LibProfile); // remove platform name
llvm::sys::path::append(LibProfile, "clang", "lib");
Expand Down
4 changes: 2 additions & 2 deletions test/Driver/options-interpreter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
// CHECK-L2: # DYLD_LIBRARY_PATH={{/foo/:/bar/:[^:]+/lib/swift/macosx$}}

// RUN: env DYLD_LIBRARY_PATH=/abc/ SDKROOT=/sdkroot %swift_driver_plain -### -target x86_64-apple-macosx10.9 -L/foo/ -L/bar/ %s | %FileCheck -check-prefix=CHECK-L2-ENV %s
// CHECK-L2-ENV: # DYLD_LIBRARY_PATH={{/foo/:/bar/:[^:]+/lib/swift/macosx:/sdkroot/usr/lib/swift:/abc/$}}
// CHECK-L2-ENV: # DYLD_LIBRARY_PATH={{/foo/:/bar/:[^:]+/lib/swift/macosx:/sdkroot/usr/lib/swift:/sdkroot/usr/lib/swift/macosx:/abc/$}}

// RUN: %swift_driver -### -target x86_64-apple-macosx10.9 %s | %FileCheck -check-prefix=CHECK-NO-FRAMEWORKS %s
// RUN: env DYLD_FRAMEWORK_PATH=/abc/ %swift_driver_plain -### -target x86_64-apple-macosx10.9 %s | %FileCheck -check-prefix=CHECK-NO-FRAMEWORKS %s
Expand Down Expand Up @@ -56,7 +56,7 @@
// CHECK-COMPLEX: -F /bar/
// CHECK-COMPLEX: #
// CHECK-COMPLEX-DAG: DYLD_FRAMEWORK_PATH=/foo/:/bar/:/abc/{{$| }}
// CHECK-COMPLEX-DAG: DYLD_LIBRARY_PATH={{/foo2/:/bar2/:[^:]+/lib/swift/macosx:/sdkroot/usr/lib/swift($| )}}
// CHECK-COMPLEX-DAG: DYLD_LIBRARY_PATH={{/foo2/:/bar2/:[^:]+/lib/swift/macosx:/sdkroot/usr/lib/swift:/sdkroot/usr/lib/swift/macosx($| )}}

// RUN: %swift_driver -### -target x86_64-unknown-linux-gnu -L/foo/ %s | %FileCheck -check-prefix=CHECK-L-LINUX${LD_LIBRARY_PATH+_LAX} %s
// CHECK-L-LINUX: # LD_LIBRARY_PATH={{/foo/:[^:]+/lib/swift/linux$}}
Expand Down