From 610d17fdc4f95dff2b6c51409b9e5975adced9e5 Mon Sep 17 00:00:00 2001 From: Jeroen Ketema Date: Tue, 27 Oct 2026 16:43:45 +0100 Subject: [PATCH] Cache the downloaded Xcode Swift toolchain across Bazel restarts Use upstream's standalone_toolchain for Xcode instead of a separate local, configuring repository rule that refetches the pinned download on every server restart. Keep the SDK lookup and path watch. Publish rules_swift as 4.0.0-rc5-codeql.3 and regenerate registry metadata. Rebase the external static runtime patch onto upstream's inline attributes so the patches apply in the generated order. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 477ddbb2-ed60-4303-bada-daa9aecee456 --- MODULE.bazel | 2 +- .../MODULE.bazel | 2 +- .../patches/external_static_runtime.patch | 26 +++---- .../register_downloaded_macos_toolchain.patch | 77 ++----------------- .../source.json | 4 +- .../modules/rules_swift/metadata.json | 2 +- 6 files changed, 24 insertions(+), 89 deletions(-) rename misc/bazel/registry/modules/rules_swift/{4.0.0-rc5-codeql.2 => 4.0.0-rc5-codeql.3}/MODULE.bazel (98%) rename misc/bazel/registry/modules/rules_swift/{4.0.0-rc5-codeql.2 => 4.0.0-rc5-codeql.3}/patches/external_static_runtime.patch (93%) rename misc/bazel/registry/modules/rules_swift/{4.0.0-rc5-codeql.2 => 4.0.0-rc5-codeql.3}/patches/register_downloaded_macos_toolchain.patch (62%) rename misc/bazel/registry/modules/rules_swift/{4.0.0-rc5-codeql.2 => 4.0.0-rc5-codeql.3}/source.json (53%) diff --git a/MODULE.bazel b/MODULE.bazel index 287a999232f5..f7ac5edfa578 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -31,7 +31,7 @@ bazel_dep(name = "gazelle", version = "0.50.0") bazel_dep(name = "rules_dotnet", version = "0.21.5-codeql.1") bazel_dep(name = "googletest", version = "1.17.0.bcr.2") bazel_dep(name = "rules_rust", version = "0.74.0") -bazel_dep(name = "rules_swift", version = "4.0.0-rc5-codeql.2") +bazel_dep(name = "rules_swift", version = "4.0.0-rc5-codeql.3") bazel_dep(name = "swift-syntax", version = "603.0.2") bazel_dep(name = "zstd", version = "1.5.7.bcr.1") diff --git a/misc/bazel/registry/modules/rules_swift/4.0.0-rc5-codeql.2/MODULE.bazel b/misc/bazel/registry/modules/rules_swift/4.0.0-rc5-codeql.3/MODULE.bazel similarity index 98% rename from misc/bazel/registry/modules/rules_swift/4.0.0-rc5-codeql.2/MODULE.bazel rename to misc/bazel/registry/modules/rules_swift/4.0.0-rc5-codeql.3/MODULE.bazel index a6b75782dc5c..df425921773f 100644 --- a/misc/bazel/registry/modules/rules_swift/4.0.0-rc5-codeql.2/MODULE.bazel +++ b/misc/bazel/registry/modules/rules_swift/4.0.0-rc5-codeql.3/MODULE.bazel @@ -2,7 +2,7 @@ module( name = "rules_swift", - version = "4.0.0-rc5-codeql.2", + version = "4.0.0-rc5-codeql.3", bazel_compatibility = [">=8.0.0"], compatibility_level = 3, ) diff --git a/misc/bazel/registry/modules/rules_swift/4.0.0-rc5-codeql.2/patches/external_static_runtime.patch b/misc/bazel/registry/modules/rules_swift/4.0.0-rc5-codeql.3/patches/external_static_runtime.patch similarity index 93% rename from misc/bazel/registry/modules/rules_swift/4.0.0-rc5-codeql.2/patches/external_static_runtime.patch rename to misc/bazel/registry/modules/rules_swift/4.0.0-rc5-codeql.3/patches/external_static_runtime.patch index 11f32aacd257..6614436073bb 100644 --- a/misc/bazel/registry/modules/rules_swift/4.0.0-rc5-codeql.2/patches/external_static_runtime.patch +++ b/misc/bazel/registry/modules/rules_swift/4.0.0-rc5-codeql.3/patches/external_static_runtime.patch @@ -21,29 +21,29 @@ index b77f636..1255ba7 100644 "swift_version_file": attr.label(doc = "A label to the .swift_version file to use. Cannot be used concurrently with `swift_version`"), }) diff --git a/swift/internal/extensions/standalone_toolchain.bzl b/swift/internal/extensions/standalone_toolchain.bzl -index a1e09ea..1fcf56d 100644 +index 801aad7..119ded9 100644 --- a/swift/internal/extensions/standalone_toolchain.bzl +++ b/swift/internal/extensions/standalone_toolchain.bzl -@@ -105,6 +105,9 @@ def _standalone_toolchain_impl(repository_ctx): +@@ -100,6 +100,9 @@ def _standalone_toolchain_impl(repository_ctx): "BUILD.bazel", repository_ctx.attr._build_template, substitutions = { + "{external_static_runtime}": ( + ' external_static_runtime = "{}",'.format(repository_ctx.attr.static_runtime) if repository_ctx.attr.static_runtime else "" + ), - "{macos_sdkroot}": macos_sdkroot, "{swift_version}": repository_ctx.attr.swift_version, }, -@@ -121,6 +124,9 @@ _STANDALONE_TOOLCHAIN_ATTRS = { - "sha256": attr.string( - doc = "The expected SHA-256 of the file downloaded. This must match the SHA-256 of the file downloaded.", - ), -+ "static_runtime": attr.label( -+ doc = "External static runtime package used by this execution toolchain.", -+ ), - "swift_version": attr.string( - doc = "Version of the swift toolchain to be installed.", - mandatory = True, + ) +@@ -117,6 +120,9 @@ standalone_toolchain = repository_rule( + "sha256": attr.string( + doc = "The expected SHA-256 of the file downloaded. This must match the SHA-256 of the file downloaded.", + ), ++ "static_runtime": attr.label( ++ doc = "External static runtime package used by this execution toolchain.", ++ ), + "swift_version": attr.string( + doc = "Version of the swift toolchain to be installed.", + mandatory = True, diff --git a/swift/internal/extensions/toolchain.BUILD b/swift/internal/extensions/toolchain.BUILD index 1304dc2..ee77866 100644 --- a/swift/internal/extensions/toolchain.BUILD diff --git a/misc/bazel/registry/modules/rules_swift/4.0.0-rc5-codeql.2/patches/register_downloaded_macos_toolchain.patch b/misc/bazel/registry/modules/rules_swift/4.0.0-rc5-codeql.3/patches/register_downloaded_macos_toolchain.patch similarity index 62% rename from misc/bazel/registry/modules/rules_swift/4.0.0-rc5-codeql.2/patches/register_downloaded_macos_toolchain.patch rename to misc/bazel/registry/modules/rules_swift/4.0.0-rc5-codeql.3/patches/register_downloaded_macos_toolchain.patch index 6d94822e0247..730735b9e09e 100644 --- a/misc/bazel/registry/modules/rules_swift/4.0.0-rc5-codeql.2/patches/register_downloaded_macos_toolchain.patch +++ b/misc/bazel/registry/modules/rules_swift/4.0.0-rc5-codeql.3/patches/register_downloaded_macos_toolchain.patch @@ -85,9 +85,10 @@ diff --git a/swift/internal/extensions/toolchain.BUILD b/swift/internal/extensio + sdkroot = "{macos_sdkroot}", static_runtime = select({ diff --git a/swift/internal/extensions/standalone_toolchain.bzl b/swift/internal/extensions/standalone_toolchain.bzl +index 119ded9..b7065b7 100644 --- a/swift/internal/extensions/standalone_toolchain.bzl +++ b/swift/internal/extensions/standalone_toolchain.bzl -@@ -91,11 +91,17 @@ def _standalone_toolchain_impl(repository_ctx): +@@ -95,6 +95,11 @@ def _standalone_toolchain_impl(repository_ctx): strip_prefix = filename.removesuffix(".tar.gz"), ) @@ -99,77 +100,11 @@ diff --git a/swift/internal/extensions/standalone_toolchain.bzl b/swift/internal repository_ctx.file(".swift-version", repository_ctx.attr.swift_version) repository_ctx.template( "BUILD.bazel", - repository_ctx.attr._build_template, - substitutions = { +@@ -103,6 +108,7 @@ def _standalone_toolchain_impl(repository_ctx): + "{external_static_runtime}": ( + ' external_static_runtime = "{}",'.format(repository_ctx.attr.static_runtime) if repository_ctx.attr.static_runtime else "" + ), + "{macos_sdkroot}": macos_sdkroot, "{swift_version}": repository_ctx.attr.swift_version, }, ) -@@ -107,19 +109,29 @@ def _standalone_toolchain_impl(repository_ctx): --standalone_toolchain = repository_rule( -- implementation = _standalone_toolchain_impl, -- attrs = { -- "_build_template": attr.label( -- default = "//swift/internal/extensions:toolchain.BUILD", -- ), -- "platform": attr.string( -- doc = "The host platform name in the swift package download URL", -- mandatory = True, -- ), -- "sha256": attr.string( -- doc = "The expected SHA-256 of the file downloaded. This must match the SHA-256 of the file downloaded.", -- ), -- "swift_version": attr.string( -- doc = "Version of the swift toolchain to be installed.", -- mandatory = True, -- ), -- }, -+_STANDALONE_TOOLCHAIN_ATTRS = { -+ "_build_template": attr.label( -+ default = "//swift/internal/extensions:toolchain.BUILD", -+ ), -+ "platform": attr.string( -+ doc = "The host platform name in the swift package download URL", -+ mandatory = True, -+ ), -+ "sha256": attr.string( -+ doc = "The expected SHA-256 of the file downloaded. This must match the SHA-256 of the file downloaded.", -+ ), -+ "swift_version": attr.string( -+ doc = "Version of the swift toolchain to be installed.", -+ mandatory = True, -+ ), -+} -+ -+standalone_toolchain = repository_rule( -+ implementation = _standalone_toolchain_impl, -+ attrs = _STANDALONE_TOOLCHAIN_ATTRS, -+) -+ -+standalone_macos_toolchain = repository_rule( -+ implementation = _standalone_toolchain_impl, -+ attrs = _STANDALONE_TOOLCHAIN_ATTRS, -+ configure = True, -+ environ = ["DEVELOPER_DIR"], -+ local = True, - ) -diff --git a/swift/extensions.bzl b/swift/extensions.bzl ---- a/swift/extensions.bzl -+++ b/swift/extensions.bzl -@@ -17 +17,5 @@ --load("//swift/internal/extensions:standalone_toolchain.bzl", "standalone_toolchain") -+load( -+ "//swift/internal/extensions:standalone_toolchain.bzl", -+ "standalone_macos_toolchain", -+ "standalone_toolchain", -+) -@@ -182,7 +186,8 @@ def _standalone_toolchain_impl(module_ctx): - toolchain_releases = toolchain.platform_sha256.items() or swift_releases[swift_version].items() - for platform, sha256 in toolchain_releases: - repository_name = toolchain.name + "_{}".format(platform) -- standalone_toolchain( -+ toolchain_repository = standalone_macos_toolchain if platform == "xcode" else standalone_toolchain -+ toolchain_repository( - name = repository_name, - sha256 = sha256, - platform = platform, diff --git a/misc/bazel/registry/modules/rules_swift/4.0.0-rc5-codeql.2/source.json b/misc/bazel/registry/modules/rules_swift/4.0.0-rc5-codeql.3/source.json similarity index 53% rename from misc/bazel/registry/modules/rules_swift/4.0.0-rc5-codeql.2/source.json rename to misc/bazel/registry/modules/rules_swift/4.0.0-rc5-codeql.3/source.json index 8467cad623bc..71710b254ccf 100644 --- a/misc/bazel/registry/modules/rules_swift/4.0.0-rc5-codeql.2/source.json +++ b/misc/bazel/registry/modules/rules_swift/4.0.0-rc5-codeql.3/source.json @@ -2,8 +2,8 @@ "integrity": "sha256-Ly2lS4AlZJMiyqAxKHyCB+2pGeP5aYkQ6zv8QheeSTI=", "url": "https://github.com/bazelbuild/rules_swift/releases/download/4.0.0-rc5/rules_swift.4.0.0-rc5.tar.gz", "patches": { - "register_downloaded_macos_toolchain.patch": "sha256-249WJ4YEH2HmxlvGftl4eD53792joKJx9Dh0j5eHAgo=", - "external_static_runtime.patch": "sha256-VY8UPZjCdlLjDB4taEpRfENRlkw4pGNYD2MAgNFITC4=" + "external_static_runtime.patch": "sha256-bnyDyK3dU+vmNVKr16y0vMrtkUSYlVOkWtIBVtjqBGw=", + "register_downloaded_macos_toolchain.patch": "sha256-w6/S2LEFXEFE+eLUeowKl4mQ5bLvb2SxQknXfXEglyE=" }, "patch_strip": 1 } diff --git a/misc/bazel/registry/modules/rules_swift/metadata.json b/misc/bazel/registry/modules/rules_swift/metadata.json index b07a19493505..da9cf33a95eb 100644 --- a/misc/bazel/registry/modules/rules_swift/metadata.json +++ b/misc/bazel/registry/modules/rules_swift/metadata.json @@ -5,7 +5,7 @@ "github:bazelbuild/rules_swift" ], "versions": [ - "4.0.0-rc5-codeql.2" + "4.0.0-rc5-codeql.3" ], "yanked_versions": {} }