Skip to content

Add optional sysroot and env to swift.toolchain - #1993

Open
TrapsterDK wants to merge 5 commits into
bazelbuild:mainfrom
TrapsterDK:standalone-toolchain-sysroot
Open

TrapsterDK wants to merge 5 commits into
bazelbuild:mainfrom
TrapsterDK:standalone-toolchain-sysroot

Conversation

@TrapsterDK

@TrapsterDK TrapsterDK commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Adds two optional attributes to the swift.toolchain tag:

  • sysroot: a map of platform -> label of sysroot files, e.g. {"ubuntu22.04": "@my_sysroot_amd64//:files"}. That platform's exec Swift toolchain passes the label's repo root as -sdk and adds the files to the inputs of its Swift tools. A platform the toolchain doesn't download fails.
  • env: environment variables for the exec Swift toolchain. {sysroot} in a value is replaced with that platform's sysroot root, so one tag can set e.g. LD_LIBRARY_PATH per platform. Using {sysroot} without a sysroot fails.

With both unset, nothing changes: sdkroot is empty, env is {}, and -sdk still comes from the C++ toolchain's sysroot. The embedded toolchains are unchanged.

Tests:

  • rules_swift's dev swift.toolchain now sets sysroot to its existing swift_ubuntu22.04_{amd64,arm64}_sysroot, which is the same sysroot the C++ toolchain uses, so the existing tests are unaffected.
  • New //test:swift_toolchain_linux_sdk_from_swift_sysroot points //swift/toolchains:linux_sysroot_feature at a local fixture directory and expects -sdk to still be the amd64 sysroot. Without sysroot on the tag it fails with -sdk test/fixtures/toolchains.
  • test/utils_tests.bzl covers the {sysroot} substitution in env.
  • bazel test //test:swift_toolchain //test:utils passes, and buildifier is clean.

Part of #1991. Non-root use is in #1996.

🤖 Generated with Claude Code

https://claude.ai/code/session_01TGY1iq223a2QbjAKgmPghQ

@TrapsterDK TrapsterDK changed the title Add optional sysroot and env to standalone_toolchain Add optional sysroot and env to swift.toolchain Nov 5, 2026
@TrapsterDK
TrapsterDK force-pushed the standalone-toolchain-sysroot branch from 8a3a373 to 44c5077 Compare November 5, 2026 11:07
TrapsterDK added a commit to devhusdk/rules_dx that referenced this pull request Nov 9, 2026
…loses #5714) (#9375)

Carry bazelbuild/rules_swift#1993 (sysroot/env on swift.toolchain) and
#1996 (non-root swift.toolchain) as patches on rules_swift 4.2.2, ship
them through the dx init override table, and declare the Linux Swift
toolchain with the public swift.toolchain tag. swift/toolchain keeps
only the link-libs wrapper and the toolchain registration; the local
archive download, pins.bzl and the hand-built swift_toolchain go away.


Claude-Session: https://claude.ai/code/session_01Xut2hwESun1HL2eSVd1d5B

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@TrapsterDK
TrapsterDK force-pushed the standalone-toolchain-sysroot branch from 055fb39 to ed854a0 Compare November 11, 2026 23:06
`sysroot` maps each platform to the sysroot files for its exec Swift
toolchain. `env` sets environment variables for it, with `{sysroot}`
replaced by that platform's sysroot root. Unset, nothing changes.

rules_swift's own dev toolchain now sets `sysroot`, and a new argv test
checks that `-sdk` follows it rather than the C++ toolchain's sysroot.
The fixture referenced an apt sysroot repo, which can't be fetched on macOS hosts.
@TrapsterDK
TrapsterDK force-pushed the standalone-toolchain-sysroot branch from ed854a0 to b275fb1 Compare November 16, 2026 23:44
Resolve the conflict in test/swift_toolchain_tests.bzl by keeping both
the Windows sdkroot test rule from main and the Linux sysroot test rule.

Assisted-by: Claude
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.

1 participant