Skip to content

Use Swiftly's toolchain path if active toolchain is managed by Swiftly #1470

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 31, 2025

Conversation

plemarquand
Copy link
Contributor

On macOS the toolchain path is determined by xcrun --find swift. xcrun will return paths inside the active Xcode. If the active toolchain is being managed by the newly released Swiftly 1.0 on macOS then the swift path and the toolchain path will be mismatched.

Check to see if the active toolchain is managed by Swiftly, and if so point the toolchain path to the Swiftly installed toolchain. The name of the .xctoolchain folder needs to be reverse engineered from Swiftly's in use toolchain name using the ToolchainVersion.parse method which was ported from Swiftly's codebase. A nice feature in the future would be to be able to ask Swiftly where its managed toolchains are stored on disk.

Verified

This commit was signed with the committer’s verified signature.
v1v Victor Martinez
On macOS the toolchain path is determined by `xcrun --find swift`.
`xcrun` will return paths inside the active Xcode. If the active
toolchain is being managed by the newly released Swiftly 1.0 on macOS
then the swift path and the toolchain path will be mismatched.

Check to see if the active toolchain is managed by Swiftly, and if so
point the toolchain path to the Swiftly installed toolchain. The name of
the `.xctoolchain` folder needs to be reverse engineered from Swiftly's
in use toolchain name using the ToolchainVersion.parse method which was
ported from Swiftly's codebase. A nice feature in the future would be to
be able to ask Swiftly where its managed toolchains are stored on disk.
@plemarquand plemarquand merged commit 3039bb3 into swiftlang:main Mar 31, 2025
13 of 15 checks passed
os.homedir(),
"Library/Developer/Toolchains/",
`${version.identifier}.xctoolchain`,
"usr"
Copy link
Member

Choose a reason for hiding this comment

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

question: Should this be a path to the <toolchain>/usr/bin where the binaries like swift are located?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For consistency with other toolchain paths in VS Code they're specified as name.xctoolchain/usr

const version = ToolchainVersion.parse(swiftlyConfig.inUse);
return path.join(
os.homedir(),
"Library/Developer/Toolchains/",
Copy link
Member

Choose a reason for hiding this comment

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

question: Should this toolchain function indicates that it is macOS-only?

if (swiftlyHomeDir) {
const { stdout: swiftLocation } = await execFile("which", ["swift"]);
if (swiftLocation.indexOf(swiftlyHomeDir) === 0) {
const swiftlyConfig = await SwiftToolchain.getSwiftlyConfig();
Copy link
Member

Choose a reason for hiding this comment

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

thought: For the in use toolchain, swiftly has a swiftly use --print-location command that will give the filesystem path of the one that's in-use. It can be more expensive than reading the config.json, but it also takes into consideration toolchains that are in-use because of the .swift-version file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants