Skip to content

swift: open the rules_swift issue and PRs for a standalone_toolchain sysroot hook #6526

Closed

Description

@TrapsterDK

Blocked on: bazelbuild/rules_swift#1993

Goal: open the upstream rules_swift issue and small PRs that let standalone_toolchain build against a caller's Linux sysroot, and fix the dead root-only guard. No rules_dx code changes; rules_dx already carries the working local toolchain in swift/toolchain/toolchain.bzl.

Plan (agent): size M
Decision: add two optional passthrough attrs on upstream standalone_toolchain: sysroot (label of the sysroot's files) and env (string_dict). The template derives sdkroot from the label's workspace_root. Rejected: an sdkroot string plus a separate files label (two attrs that can drift apart); having upstream always use its own @swift_ubuntu*_sysroot for -sdk (our sysroot has extra host_libs/link_libs packages, and it would give one build two sysroots); patches or git_override in rules_dx (root-only, so consumers would not get them).
Cause: upstream swift/internal/extensions/toolchain.BUILD swift_toolchain_exec has no sdkroot, so -sdk comes from the resolved cc toolchain (--sysroot=/dev/null under @llvm, via PR bazelbuild/rules_swift#1913). Upstream swift/extensions.bzl:133 tests not module_ctx.is_dev_dependency without calling it, so the check is always false.
Change:

  1. Open the upstream issue in bazelbuild/rules_swift. Cover (a) no way to set the sdkroot, sysroot inputs or env on standalone_toolchain's exec toolchain when the resolved cc toolchain is not cc_toolchain_exec, (b) the guard bug, (c) a question: can standalone_toolchain become public API? rules_dx loads it from swift/internal/.... Include a minimal repro (aquery: a SwiftCompile with -sdk /dev/null under a rules-based cc toolchain).
  2. PR A (fork TrapsterDK/rules_swift, follow CONTRIBUTING.md and use buildifier): in swift/internal/extensions/standalone_toolchain.bzl, add optional sysroot = attr.label() and env = attr.string_dict(). Substitute {sdkroot} (from attr.sysroot.workspace_root, or "" when unset), {sysroot_inputs} and {env} into toolchain.BUILD. Feed them only to swift_toolchain_exec (sdkroot, env) and to a separate exec swift_tools (additional_inputs). Leave the embedded toolchain and the default (unset) behaviour byte-identical. Regression test: follow the pattern in test/swift_toolchain_tests.bzl from #1687: Use a shared real Starlark parser for MODULE dependency reads and version edits #1913. Add a dev-dep standalone_toolchain instance (or a template-render unit test) that asserts SwiftCompile argv carries -sdk <sysroot root> and that the sysroot files are action inputs. If reviewers push back on env, move it to its own PR.
  3. PR B: fix the guard. For each non-root module, fail if any toolchain tag has not module_ctx.is_dev_dependency(tag). Pull the check into a pure helper and unit-test it with skylib unittest, as in test/utils_tests.bzl. In the PR body, say that this can newly fail downstream modules that use the extension without dev_dependency.
  4. Link the upstream issue and both PRs on swift: upstream a sysroot hook for rules_swift standalone_toolchain #5714.
    Tests: in the rules_swift clone, bazel test //test:all (Linux), plus buildifier --lint=warn. No rules_dx tests.
    Host: none (Linux-only paths; upstream CI covers macOS).
    Upstream: this slice is the upstream work. The owner's Google CLA is already on file (merged Fix rust-analyzer proc-macro merge for k8-opt-exec paths bazelbuild/rules_rust#4140).

Part of #5714

Activity

  1. added
    P2
    model:sonnet
    on Nov 4, 2026
  2. TrapsterDK commented on Nov 5, 2026

    @TrapsterDK
    CollaboratorAuthor

    Upstream work is already open: issue bazelbuild/rules_swift#1991, guard fix #1992, sysroot/env hook #1993 (1993 includes a test in test/utils_tests.bzl). No rules_dx code change is needed. Waiting on upstream review; #6528 follows after a release. Left open until the upstream PRs merge.

    Assisted by Claude.

  3. TrapsterDK commented on Nov 5, 2026

    @TrapsterDK
    CollaboratorAuthor
  4. added
    blocked
    on Nov 5, 2026
  5. TrapsterDK commented on Nov 5, 2026

    @TrapsterDK
    CollaboratorAuthor

    Still waiting on upstream bazelbuild/rules_swift#1992 and #1993 review; no rules_dx change remains. Marked blocked.

    Assisted by Claude.

  6. github-actions commented on Nov 5, 2026

    @github-actions
    Contributor

    This issue has the blocked label but no Blocked on: line in its body. Add one naming the blocking issue (#N), a pull request URL, or the owner action. See CONTRIBUTING.md.

  7. removed
    blocked
    on Nov 7, 2026
  8. TrapsterDK commented on Nov 9, 2026

    @TrapsterDK
    CollaboratorAuthor

    The guard fix bazelbuild/rules_swift#1992 was closed without merging. bazelbuild/rules_swift#1996 (non-root swift.toolchain) replaces it. rules_dx carries #1993 and #1996 as local patches on rules_swift 4.2.2 in #9375.

    Assisted by Claude.

  9. TrapsterDK commented on Nov 9, 2026

    @TrapsterDK
    CollaboratorAuthor

    Done: the upstream issue and PRs exist.

    #6528 tracks the upstream merge, the release and dropping the patches, so nothing is left here. The standalone_toolchain plan above is superseded.

    Assisted by Claude.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2model:sonnet

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions