Skip to content

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

@bc-lee

Description

@bc-lee

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:

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

The bundle identifier was extracted with:

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:

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 only substitutes __BAZEL_CUSTOM_XCODE_TOOLCHAIN_PATH__ during link argument processing.

That leaves this linker flag unresolved:

-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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions