Skip to content

Conversation

@ma-oli
Copy link
Contributor

@ma-oli ma-oli commented Nov 13, 2025

Depending on a swift_compiler_plugin target currently adds:

--plugin-path
__BAZEL_XCODE_DEVELOPER_DIR__/usr/lib/swift/host/plugins/testing

to the compiler action. It's ok when using an Xcode toolchain, but when used with a standalone non-apple cc_toolchain (such as one from llvm_toolchain for instance), DEVELOPER_DIR will not be set, therefore causing the swift worker executable to either crash (on MacOS) or just return the empty string (on Linux). None of which are particularly helpful.

The right thing to do, from a swift perspective, would be to return a path inside the swift toolchain currently in use, regardless of whether we're using an Xcode toolchain or an alternative toolchain.

In this commit, we're therefore changing the meaning of the variable currently named __BAZEL_CUSTOM_XCODE_TOOLCHAIN_PATH__. It is currently meant to contain the name of the xcode toolchain when set through the TOOLCHAINS variable (in --action_env), and nothing otherwise. We're repurposing it to always return the swift toolchain location, regardless of the toolchain currently in use. When using TOOLCHAINS, it will return the path to the toolchain, and when using DEVELOPER_DIR, it will return the swift toolchain path inside the Xcode folder.

To reflect its new meaning, we're giving it a new name by the same occasion: BAZEL_SWIFT_TOOLCHAIN_PATH. Which just so happens, is also the private name it is given inside bazel_substitutions.cc.

Finally, we're making use of that new variable in
swift_compiler_plugin(), so --plugin-path work in non-Xcode environments.

Copy link
Member

@keith keith left a comment

Choose a reason for hiding this comment

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

it's notable that the result here is every swift compile will now call xcrun in this where it didn't before

Depending on a swift_compiler_plugin target currently adds:
```
--plugin-path
__BAZEL_XCODE_DEVELOPER_DIR__/usr/lib/swift/host/plugins/testing
```
to the compiler action. It's ok when using an Xcode toolchain, but when
used with a standalone non-apple cc_toolchain (such as one from
llvm_toolchain for instance), DEVELOPER_DIR will not be set, therefore
causing the swift worker executable to either crash (on MacOS) or just
return the empty string (on Linux). None of which are particularly
helpful.

The right thing to do, from a swift perspective, would be to return a
path inside the swift toolchain currently in use, regardless of whether
we're using an Xcode toolchain or an alternative toolchain.

In this commit, we're therefore changing the meaning of the variable
currently named `__BAZEL_CUSTOM_XCODE_TOOLCHAIN_PATH__`. It is currently
meant to contain the name of the xcode toolchain when set through the
TOOLCHAINS variable (in --action_env), and nothing otherwise. We're
repurposing it to always return the swift toolchain location, regardless
of the toolchain currently in use. When using TOOLCHAINS, it will return
the path to the toolchain, and when using DEVELOPER_DIR, it will return
the swift toolchain path inside the Xcode folder.

To reflect its new meaning, we're giving it a new name by the same
occasion: __BAZEL_SWIFT_TOOLCHAIN_PATH__. Which just so happens, is also
the private name it is given inside bazel_substitutions.cc.

Finally, we're making use of that new variable in
swift_compiler_plugin(), so --plugin-path work in non-Xcode
environments.
@ma-oli ma-oli force-pushed the fix-plugin-path-with-non-xcode-toolchain branch from ed4ef2f to a9f4ec7 Compare November 14, 2025 02:34
@aaronsky aaronsky requested a review from keith November 14, 2025 12:40
@keith keith merged commit 4de81e3 into bazelbuild:master Nov 14, 2025
15 checks passed
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.

4 participants