Skip to content

Commit 695bfe7

Browse files
authored
Merge pull request #22905 from jketema/jketema/swift-fix
Cache the downloaded Xcode Swift toolchain across Bazel restarts
2 parents 748b492 + 610d17f commit 695bfe7

6 files changed

Lines changed: 24 additions & 89 deletions

File tree

‎MODULE.bazel‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ bazel_dep(name = "gazelle", version = "0.54.0")
3131
bazel_dep(name = "rules_dotnet", version = "0.21.5-codeql.1")
3232
bazel_dep(name = "googletest", version = "1.17.0.bcr.2")
3333
bazel_dep(name = "rules_rust", version = "0.74.0")
34-
bazel_dep(name = "rules_swift", version = "4.0.0-rc5-codeql.2")
34+
bazel_dep(name = "rules_swift", version = "4.0.0-rc5-codeql.3")
3535
bazel_dep(name = "swift-syntax", version = "603.0.2")
3636
bazel_dep(name = "zstd", version = "1.5.7.bcr.1")
3737

misc/bazel/registry/modules/rules_swift/4.0.0-rc5-codeql.2/MODULE.bazel renamed to misc/bazel/registry/modules/rules_swift/4.0.0-rc5-codeql.3/MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module(
44
name = "rules_swift",
5-
version = "4.0.0-rc5-codeql.2",
5+
version = "4.0.0-rc5-codeql.3",
66
bazel_compatibility = [">=8.0.0"],
77
compatibility_level = 3,
88
)

misc/bazel/registry/modules/rules_swift/4.0.0-rc5-codeql.2/patches/external_static_runtime.patch renamed to misc/bazel/registry/modules/rules_swift/4.0.0-rc5-codeql.3/patches/external_static_runtime.patch

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,29 @@ index b77f636..1255ba7 100644
2121
"swift_version_file": attr.label(doc = "A label to the .swift_version file to use. Cannot be used concurrently with `swift_version`"),
2222
})
2323
diff --git a/swift/internal/extensions/standalone_toolchain.bzl b/swift/internal/extensions/standalone_toolchain.bzl
24-
index a1e09ea..1fcf56d 100644
24+
index 801aad7..119ded9 100644
2525
--- a/swift/internal/extensions/standalone_toolchain.bzl
2626
+++ b/swift/internal/extensions/standalone_toolchain.bzl
27-
@@ -105,6 +105,9 @@ def _standalone_toolchain_impl(repository_ctx):
27+
@@ -100,6 +100,9 @@ def _standalone_toolchain_impl(repository_ctx):
2828
"BUILD.bazel",
2929
repository_ctx.attr._build_template,
3030
substitutions = {
3131
+ "{external_static_runtime}": (
3232
+ ' external_static_runtime = "{}",'.format(repository_ctx.attr.static_runtime) if repository_ctx.attr.static_runtime else ""
3333
+ ),
34-
"{macos_sdkroot}": macos_sdkroot,
3534
"{swift_version}": repository_ctx.attr.swift_version,
3635
},
37-
@@ -121,6 +124,9 @@ _STANDALONE_TOOLCHAIN_ATTRS = {
38-
"sha256": attr.string(
39-
doc = "The expected SHA-256 of the file downloaded. This must match the SHA-256 of the file downloaded.",
40-
),
41-
+ "static_runtime": attr.label(
42-
+ doc = "External static runtime package used by this execution toolchain.",
43-
+ ),
44-
"swift_version": attr.string(
45-
doc = "Version of the swift toolchain to be installed.",
46-
mandatory = True,
36+
)
37+
@@ -117,6 +120,9 @@ standalone_toolchain = repository_rule(
38+
"sha256": attr.string(
39+
doc = "The expected SHA-256 of the file downloaded. This must match the SHA-256 of the file downloaded.",
40+
),
41+
+ "static_runtime": attr.label(
42+
+ doc = "External static runtime package used by this execution toolchain.",
43+
+ ),
44+
"swift_version": attr.string(
45+
doc = "Version of the swift toolchain to be installed.",
46+
mandatory = True,
4747
diff --git a/swift/internal/extensions/toolchain.BUILD b/swift/internal/extensions/toolchain.BUILD
4848
index 1304dc2..ee77866 100644
4949
--- a/swift/internal/extensions/toolchain.BUILD

misc/bazel/registry/modules/rules_swift/4.0.0-rc5-codeql.2/patches/register_downloaded_macos_toolchain.patch renamed to misc/bazel/registry/modules/rules_swift/4.0.0-rc5-codeql.3/patches/register_downloaded_macos_toolchain.patch

Lines changed: 6 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,10 @@ diff --git a/swift/internal/extensions/toolchain.BUILD b/swift/internal/extensio
8585
+ sdkroot = "{macos_sdkroot}",
8686
static_runtime = select({
8787
diff --git a/swift/internal/extensions/standalone_toolchain.bzl b/swift/internal/extensions/standalone_toolchain.bzl
88+
index 119ded9..b7065b7 100644
8889
--- a/swift/internal/extensions/standalone_toolchain.bzl
8990
+++ b/swift/internal/extensions/standalone_toolchain.bzl
90-
@@ -91,11 +91,17 @@ def _standalone_toolchain_impl(repository_ctx):
91+
@@ -95,6 +95,11 @@ def _standalone_toolchain_impl(repository_ctx):
9192
strip_prefix = filename.removesuffix(".tar.gz"),
9293
)
9394

@@ -99,77 +100,11 @@ diff --git a/swift/internal/extensions/standalone_toolchain.bzl b/swift/internal
99100
repository_ctx.file(".swift-version", repository_ctx.attr.swift_version)
100101
repository_ctx.template(
101102
"BUILD.bazel",
102-
repository_ctx.attr._build_template,
103-
substitutions = {
103+
@@ -103,6 +108,7 @@ def _standalone_toolchain_impl(repository_ctx):
104+
"{external_static_runtime}": (
105+
' external_static_runtime = "{}",'.format(repository_ctx.attr.static_runtime) if repository_ctx.attr.static_runtime else ""
106+
),
104107
+ "{macos_sdkroot}": macos_sdkroot,
105108
"{swift_version}": repository_ctx.attr.swift_version,
106109
},
107110
)
108-
@@ -107,19 +109,29 @@ def _standalone_toolchain_impl(repository_ctx):
109-
-standalone_toolchain = repository_rule(
110-
- implementation = _standalone_toolchain_impl,
111-
- attrs = {
112-
- "_build_template": attr.label(
113-
- default = "//swift/internal/extensions:toolchain.BUILD",
114-
- ),
115-
- "platform": attr.string(
116-
- doc = "The host platform name in the swift package download URL",
117-
- mandatory = True,
118-
- ),
119-
- "sha256": attr.string(
120-
- doc = "The expected SHA-256 of the file downloaded. This must match the SHA-256 of the file downloaded.",
121-
- ),
122-
- "swift_version": attr.string(
123-
- doc = "Version of the swift toolchain to be installed.",
124-
- mandatory = True,
125-
- ),
126-
- },
127-
+_STANDALONE_TOOLCHAIN_ATTRS = {
128-
+ "_build_template": attr.label(
129-
+ default = "//swift/internal/extensions:toolchain.BUILD",
130-
+ ),
131-
+ "platform": attr.string(
132-
+ doc = "The host platform name in the swift package download URL",
133-
+ mandatory = True,
134-
+ ),
135-
+ "sha256": attr.string(
136-
+ doc = "The expected SHA-256 of the file downloaded. This must match the SHA-256 of the file downloaded.",
137-
+ ),
138-
+ "swift_version": attr.string(
139-
+ doc = "Version of the swift toolchain to be installed.",
140-
+ mandatory = True,
141-
+ ),
142-
+}
143-
+
144-
+standalone_toolchain = repository_rule(
145-
+ implementation = _standalone_toolchain_impl,
146-
+ attrs = _STANDALONE_TOOLCHAIN_ATTRS,
147-
+)
148-
+
149-
+standalone_macos_toolchain = repository_rule(
150-
+ implementation = _standalone_toolchain_impl,
151-
+ attrs = _STANDALONE_TOOLCHAIN_ATTRS,
152-
+ configure = True,
153-
+ environ = ["DEVELOPER_DIR"],
154-
+ local = True,
155-
)
156-
diff --git a/swift/extensions.bzl b/swift/extensions.bzl
157-
--- a/swift/extensions.bzl
158-
+++ b/swift/extensions.bzl
159-
@@ -17 +17,5 @@
160-
-load("//swift/internal/extensions:standalone_toolchain.bzl", "standalone_toolchain")
161-
+load(
162-
+ "//swift/internal/extensions:standalone_toolchain.bzl",
163-
+ "standalone_macos_toolchain",
164-
+ "standalone_toolchain",
165-
+)
166-
@@ -182,7 +186,8 @@ def _standalone_toolchain_impl(module_ctx):
167-
toolchain_releases = toolchain.platform_sha256.items() or swift_releases[swift_version].items()
168-
for platform, sha256 in toolchain_releases:
169-
repository_name = toolchain.name + "_{}".format(platform)
170-
- standalone_toolchain(
171-
+ toolchain_repository = standalone_macos_toolchain if platform == "xcode" else standalone_toolchain
172-
+ toolchain_repository(
173-
name = repository_name,
174-
sha256 = sha256,
175-
platform = platform,

misc/bazel/registry/modules/rules_swift/4.0.0-rc5-codeql.2/source.json renamed to misc/bazel/registry/modules/rules_swift/4.0.0-rc5-codeql.3/source.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"integrity": "sha256-Ly2lS4AlZJMiyqAxKHyCB+2pGeP5aYkQ6zv8QheeSTI=",
33
"url": "https://github.com/bazelbuild/rules_swift/releases/download/4.0.0-rc5/rules_swift.4.0.0-rc5.tar.gz",
44
"patches": {
5-
"register_downloaded_macos_toolchain.patch": "sha256-249WJ4YEH2HmxlvGftl4eD53792joKJx9Dh0j5eHAgo=",
6-
"external_static_runtime.patch": "sha256-VY8UPZjCdlLjDB4taEpRfENRlkw4pGNYD2MAgNFITC4="
5+
"external_static_runtime.patch": "sha256-bnyDyK3dU+vmNVKr16y0vMrtkUSYlVOkWtIBVtjqBGw=",
6+
"register_downloaded_macos_toolchain.patch": "sha256-w6/S2LEFXEFE+eLUeowKl4mQ5bLvb2SxQknXfXEglyE="
77
},
88
"patch_strip": 1
99
}

‎misc/bazel/registry/modules/rules_swift/metadata.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"github:bazelbuild/rules_swift"
66
],
77
"versions": [
8-
"4.0.0-rc5-codeql.2"
8+
"4.0.0-rc5-codeql.3"
99
],
1010
"yanked_versions": {}
1111
}

0 commit comments

Comments
 (0)