-
Notifications
You must be signed in to change notification settings - Fork 216
Allow libSwiftDriver client passing down a compiler executable directory #488
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
Conversation
When using swift-driver as a library, we cannot assume compiler is adjacent to the build system executable.
|
@swift-ci please test |
|
@nkcsgexi what are your thoughts on using this versus passing in a path to a toolchain "root"? We need many different things from the toolchain beyond a compiler executable so I wonder if it's better to find them relative to a toolchain itself, vs. relative to a compiler executable. Either way, we are beholden to a toolchain's directory structure being fixed. |
| fileSystem: FileSystem = localFileSystem, | ||
| executor: DriverExecutor, | ||
| integratedDriver: Bool = true, | ||
| compilerExecutableDir: AbsolutePath? = nil, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not as explicitly typed, but you can already do this by changing the env that you provide the driver.
Using SWIFT_DRIVER_<TOOLNAME>_EXEC environment variables. It also happens sooner.
if let overrideString = envVar(forExecutable: executable) {
return try AbsolutePath(validating: overrideString)
} else if let toolDir = toolDirectory,
let path = lookupExecutablePath(filename: executable, searchPaths: [toolDir]) {
// Looking for tools from the tools directory.
return path
} else if let path = lookupExecutablePath(filename: executable, searchPaths: [executableDir]) {
return path
} else if let path = try? xcrunFind(executable: executable) {
return path
} else if !["swift-frontend", "swift"].contains(executable),
let parentDirectory = try? getToolPath(.swiftCompiler).parentDirectory,
parentDirectory != executableDir,
let path = lookupExecutablePath(filename: executable, searchPaths: [parentDirectory]) {
// If the driver library's client and the frontend are in different directories,
// try looking for tools next to the frontend.
return path
} else if let path = lookupExecutablePath(filename: executable, searchPaths: searchPaths) {
return path
} else if executable == "swift-frontend" {
// Temporary shim: fall back to looking for "swift" before failing.
return try lookup(executable: "swift")
} else if fallbackToExecutableDefaultPath {
return AbsolutePath("/usr/bin/" + executable)
} else {
throw ToolchainError.unableToFind(tool: executable)
}
Also using the -tools-directory option is of higher precedence as well.
You're overriding the executableDir, which is the 3rd if statement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both SWIFT_DRIVER_<TOOLNAME>_EXEC and -tools-directory are global settings that the build system will honor no matter which toolchain is currently under use. This parameter compilerExecutableDir is mostly for the build system to create different driver instances for different toolchains.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right you pass the args and environment to the driver as you create it. So you can modify them there. Or just append, the argument to the existing logic. Users of libSwiftDriver are probably already creating argument lists.
It seems weird that the Driver creator needs another way to override this path.
|
@artemcm all tools are currently found with an anchor of the executable dir where swift-driver is installed, e.g. the scanner library. I think this still makes sense and more versatile in situations that we don't have a fully-defined toolchain (in build directories for example). |
When using swift-driver as a library, we cannot assume compiler is adjacent to the
build system executable.