bazelbuild / bazelbuild/rules_swift

`TOOLCHAINS=<swift snapshot bundle id>` emits unresolved Swift toolchain linker search path on macOS

Open
#1,672 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Starlark
Stars
353
Forks
172
Avg merge
23h 14m
Merged PRs (30d)
8

Description

Using a system-wide installed Swift snapshot on macOS can emit a nonexistent linker search path.

I installed this snapshot:

https://download.swift.org/development/xcode/swift-DEVELOPMENT-SNAPSHOT-2026-03-16-a/swift-DEVELOPMENT-SNAPSHOT-2026-03-16-a-osx.pkg

Then I built one of my Swift projects with:

```bash
bazel build ... --action_env=TOOLCHAINS=org.swift.64202603161a
```

The bundle identifier was extracted with:

```bash
plutil -extract CFBundleIdentifier raw -o - \
/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2026-03-16-a.xctoolchain/Info.plist
```

Basic compilation works, but the link step emits this warning:

```text
ld: warning: search path '__BAZEL_SWIFT_TOOLCHAIN_PATH__/usr/lib/swift/macosx' not found
```

## Root cause

After digging into this, the issue appears to be a placeholder mismatch inside `rules_swift`.

`rules_swift` emits `__BAZEL_SWIFT_TOOLCHAIN_PATH__` into linker flags for the custom toolchain path, but [apple_support](https://github.com/bazelbuild/apple_support/blob/a99414ad848c3aeb84640934352ecc85d8a937f5/crosstool/wrapped_clang.cc#L396) only substitutes `__BAZEL_CUSTOM_XCODE_TOOLCHAIN_PATH__` during link argument processing.

That leaves this linker flag unresolved:

```text
-L__BAZEL_SWIFT_TOOLCHAIN_PATH__/usr/lib/swift/macosx
```

## Expected behavior

When `TOOLCHAINS` is used with an installed Swift snapshot toolchain, `rules_swift` should emit a linker-side placeholder that is actually resolved during link argument processing, so no nonexistent search path warning is produced.

## Proposed fix

Use the Swift placeholder for Swift-side worker/tool behavior, but use the linker-compatible custom Xcode toolchain placeholder when constructing linker search paths for custom toolchains.

I have a small patch and regression test for this and can open a PR.

Contributor guide

Open the contributing guide

Research direction

Start by locating the rules_swift code that constructs linker search paths for custom toolchains, and compare its placeholder with apple_support's crosstool/wrapped_clang.cc link-argument handling. Review the proposed regression test or add one covering TOOLCHAINS with an installed Swift snapshot; done means the linker uses a resolved custom-toolchain path without the unresolved-path warning.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
67/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.