Skip to content

Commit 113d4f3

Browse files
authored
Toolchain path is one folder up from swift bin path (#606)
* Toolchain path is one folder up from swift bin path Previously it was two folders up and swift executables were assumed to be in a usr/bin folder relative to the toolchain folder. It looks like this cannot be assumed so the toolchain path is now one folder up instead. I have also verified that sourcekit-lsp is happy with this as a valid toolchain path * Remove unnecessary check
1 parent 25f6120 commit 113d4f3

File tree

4 files changed

+18
-20
lines changed

4 files changed

+18
-20
lines changed

src/debugger/lldb.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { SwiftToolchain } from "../toolchain/toolchain";
2727
* @returns Library path for LLDB
2828
*/
2929
export async function getLLDBLibPath(toolchain: SwiftToolchain): Promise<Result<string>> {
30+
// can't use toolchain path here as LLDB is not in macOS toolchain path
3031
const executable = path.join(toolchain.swiftFolderPath, "lldb");
3132
let pathHint = path.dirname(toolchain.swiftFolderPath);
3233
try {

src/sourcekit-lsp/LanguageClientManager.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -413,16 +413,13 @@ export class LanguageClientManager {
413413
configuration.path.length > 0 &&
414414
serverPathConfig !== toolchainSourceKitLSP
415415
) {
416-
// if configuration has custom swift path then set toolchain path
417-
if (configuration.path) {
418-
// eslint-disable-next-line @typescript-eslint/naming-convention
419-
sourcekit.options = {
420-
env: {
421-
...sourcekit.options?.env,
422-
SOURCEKIT_TOOLCHAIN_PATH: this.workspaceContext.toolchain.toolchainPath,
423-
},
424-
};
425-
}
416+
// eslint-disable-next-line @typescript-eslint/naming-convention
417+
sourcekit.options = {
418+
env: {
419+
...sourcekit.options?.env,
420+
SOURCEKIT_TOOLCHAIN_PATH: this.workspaceContext.toolchain.toolchainPath,
421+
},
422+
};
426423
}
427424

428425
const serverOptions: langclient.ServerOptions = sourcekit;

src/toolchain/Sanitizer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ export class Sanitizer {
2525
}
2626
}
2727

28-
/** Return runtime environment variables */
28+
/** Return runtime environment variables for macOS */
2929
get runtimeEnvironment(): Record<string, string> | undefined {
3030
if (!this.toolchain.toolchainPath) {
3131
return undefined;
3232
}
33-
const lib = `/usr/lib/swift/clang/lib/darwin/libclang_rt.${this.clangName}_osx_dynamic.dylib`;
33+
const lib = `/lib/swift/clang/lib/darwin/libclang_rt.${this.clangName}_osx_dynamic.dylib`;
3434
const libFullPath = path.join(this.toolchain.toolchainPath, lib);
3535
return { DYLD_INSERT_LIBRARIES: libFullPath };
3636
}

src/toolchain/toolchain.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ export function getDarwinTargetTriple(target: DarwinCompatibleTarget): string |
8282

8383
export class SwiftToolchain {
8484
constructor(
85-
public swiftFolderPath: string,
86-
public toolchainPath: string,
87-
public swiftVersionString: string,
88-
public swiftVersion: Version,
89-
public runtimePath?: string,
85+
public swiftFolderPath: string, // folder swift executable in $PATH was found in
86+
public toolchainPath: string, // toolchain folder. One folder up from swift bin folder. This is to support toolchains without usr folder
87+
public swiftVersionString: string, // Swift version as a string, including description
88+
public swiftVersion: Version, // Swift version as semVar variable
89+
public runtimePath?: string, // runtime library included in output from `swift -print-target-info`
9090
private defaultTarget?: string,
9191
private defaultSDK?: string,
9292
private customSDK?: string,
@@ -179,7 +179,7 @@ export class SwiftToolchain {
179179
public getToolchainExecutable(exe: string): string {
180180
// should we add `.exe` at the end of the executable name
181181
const windowsExeSuffix = process.platform === "win32" ? ".exe" : "";
182-
return `${this.toolchainPath}/usr/bin/${exe}${windowsExeSuffix}`;
182+
return `${this.toolchainPath}/bin/${exe}${windowsExeSuffix}`;
183183
}
184184

185185
logDiagnostics(channel: SwiftOutputChannel) {
@@ -286,10 +286,10 @@ export class SwiftToolchain {
286286
env: configuration.swiftEnvironmentVariables,
287287
});
288288
const swift = stdout.trimEnd();
289-
return path.dirname(path.dirname(path.dirname(swift)));
289+
return path.dirname(path.dirname(swift));
290290
}
291291
default: {
292-
return path.dirname(path.dirname(swiftPath));
292+
return path.dirname(swiftPath);
293293
}
294294
}
295295
} catch {

0 commit comments

Comments
 (0)