Skip to content

Commit e8cb1cc

Browse files
committed
feat(tools): add utility to generate swift toolchain dictionaries
Generating the toolchain dictionary currently requires downloading toolchains one by one and calculating their checksum, which is tedious and time consuming. We're adding a utility here that will do that automatically. The tool supports caching downloaded archives and can fetch release information from swift.org's API to generate the checksums dictionary format used by the build system. While we're at it, we're running that utility for the 2 latest releases (6.2.2 and 6.2.3) and adding them to the dict. Because that dictionary is probably gonna keep growing over time, we're also moving it in its own standalone file (swift_releases.bzl).
1 parent 8e1fb2c commit e8cb1cc

File tree

4 files changed

+362
-22
lines changed

4 files changed

+362
-22
lines changed

swift/extensions.bzl

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
load("@bazel_features//:features.bzl", "bazel_features")
1818
load("//swift:repositories.bzl", "swift_rules_dependencies")
1919
load("//swift/internal:extensions/standalone_toolchain.bzl", _standalone_toolchain = "standalone_toolchain")
20+
load("//swift/internal:extensions/swift_releases.bzl", "SWIFT_RELEASES")
2021
load(
2122
"//swift/internal:extensions/toolchains.bzl",
2223
_toolchains_for_platform = "toolchains_for_platform",
@@ -36,25 +37,6 @@ def _non_module_deps_impl(module_ctx):
3637

3738
non_module_deps = module_extension(implementation = _non_module_deps_impl)
3839

39-
# This mapping is intended to map each version to its supported platforms and checksums
40-
_SWIFT_RELEASES = {
41-
"6.2.1": {
42-
"xcode": "4ca13d0abd364664d19facd75e23630c0884898bbcaf1920b45df288bdb86cb2",
43-
"amazonlinux2": "218fc55ba7224626fd25f8ca285b083fda020e3737146e2fe10b8ae9aaf2ae97",
44-
"amazonlinux2-aarch64": "00999039a82a81b1e9f3915eb2c78b63552fe727bcbfe9a2611628ac350287f2",
45-
"debian12": "d6405e4fb7f092cbb9973a892ce8410837b4335f67d95bf8607baef1f69939e4",
46-
"debian12-aarch64": "522d231bb332fe5da9648ca7811e8054721f05eccd1eefae491cf4a86eab4155",
47-
"fedora39": "ec78360dfa7817d7637f207b1ffb3a22164deb946c9a9f8c40ab8871856668e8",
48-
"fedora39-aarch64": "d8bc04e7e283e314d1b96adc55e1803dd01a0106dc0d0263e784a5c9f2a46d3b",
49-
"ubi9": "9a082c3efdeda2e65cbc7038d0c295b75fa48f360369b2538449fc665192da3e",
50-
"ubi9-aarch64": "47f109f1f63fa24df3659676bb1afac2fdd05c0954d4f00977da6a868dd31e66",
51-
"ubuntu22.04": "5ec23d4004f760fafdbb76c21e380d3bacef1824300427a458dc88c1c0bef381",
52-
"ubuntu22.04-aarch64": "ab5f3eb0349c575c38b96ed10e9a7ffa2741b0038285c12d56251a38749cadf0",
53-
"ubuntu24.04": "4022cb64faf7e2681c19f9b62a22fb7d9055db6194d9e4a4bef9107b6ce10946",
54-
"ubuntu24.04-aarch64": "3b70a3b23b9435c37112d96ee29aa70061e23059ef9c4d3cfa4951f49c4dfedb",
55-
},
56-
}
57-
5840
def _standalone_toolchain_impl(module_ctx):
5941
root_module = None
6042
for mod in module_ctx.modules:
@@ -77,13 +59,13 @@ def _standalone_toolchain_impl(module_ctx):
7759
if toolchain.swift_version_file:
7860
swift_version = module_ctx.read(toolchain.swift_version_file).strip()
7961

80-
if swift_version not in _SWIFT_RELEASES:
62+
if swift_version not in SWIFT_RELEASES:
8163
fail("Version `{}` is not supported by this version of rules_swift. Please choose one of: {}".format(
8264
swift_version,
83-
_SWIFT_RELEASES.keys(),
65+
SWIFT_RELEASES.keys(),
8466
))
8567

86-
for platform, sha256 in _SWIFT_RELEASES[swift_version].items():
68+
for platform, sha256 in SWIFT_RELEASES[swift_version].items():
8769
repository_name = toolchain.name + "_{}".format(platform)
8870
_standalone_toolchain(
8971
name = repository_name,
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
"""Swift release version mappings.
2+
3+
This module defines the SWIFT_RELEASES dictionary, which maps each Swift version
4+
to its supported platforms and their corresponding SHA256 checksums. This data is
5+
used to download and verify Swift toolchain releases for different platforms.
6+
7+
The structure is:
8+
SWIFT_RELEASES = {
9+
"version": {
10+
"platform": "sha256_checksum",
11+
...
12+
},
13+
...
14+
}
15+
16+
Supported platforms include various Linux distributions (amazonlinux2, debian12,
17+
fedora39, ubi9, ubuntu22.04, ubuntu24.04) in both x86_64 and aarch64 architectures,
18+
as well as Xcode toolchains for macOS.
19+
"""
20+
21+
SWIFT_RELEASES = {
22+
"6.2.1": {
23+
"amazonlinux2": "218fc55ba7224626fd25f8ca285b083fda020e3737146e2fe10b8ae9aaf2ae97",
24+
"amazonlinux2-aarch64": "00999039a82a81b1e9f3915eb2c78b63552fe727bcbfe9a2611628ac350287f2",
25+
"debian12": "d6405e4fb7f092cbb9973a892ce8410837b4335f67d95bf8607baef1f69939e4",
26+
"debian12-aarch64": "522d231bb332fe5da9648ca7811e8054721f05eccd1eefae491cf4a86eab4155",
27+
"fedora39": "ec78360dfa7817d7637f207b1ffb3a22164deb946c9a9f8c40ab8871856668e8",
28+
"fedora39-aarch64": "d8bc04e7e283e314d1b96adc55e1803dd01a0106dc0d0263e784a5c9f2a46d3b",
29+
"ubi9": "9a082c3efdeda2e65cbc7038d0c295b75fa48f360369b2538449fc665192da3e",
30+
"ubi9-aarch64": "47f109f1f63fa24df3659676bb1afac2fdd05c0954d4f00977da6a868dd31e66",
31+
"ubuntu22.04": "5ec23d4004f760fafdbb76c21e380d3bacef1824300427a458dc88c1c0bef381",
32+
"ubuntu22.04-aarch64": "ab5f3eb0349c575c38b96ed10e9a7ffa2741b0038285c12d56251a38749cadf0",
33+
"ubuntu24.04": "4022cb64faf7e2681c19f9b62a22fb7d9055db6194d9e4a4bef9107b6ce10946",
34+
"ubuntu24.04-aarch64": "3b70a3b23b9435c37112d96ee29aa70061e23059ef9c4d3cfa4951f49c4dfedb",
35+
"xcode": "4ca13d0abd364664d19facd75e23630c0884898bbcaf1920b45df288bdb86cb2",
36+
},
37+
"6.2.2": {
38+
"amazonlinux2": "2de884b0ccf1012750fd93c710506c3d216e34676b488ba318fefe711a136125",
39+
"amazonlinux2-aarch64": "4bb5714a683d8ddf78bc69027cb2acc9854ae51e91e55badba2e5c231b923a42",
40+
"debian12": "d4817caaf70e95639702b69be24730057f4220f76796573397cdc067a4360041",
41+
"debian12-aarch64": "1e225d1f9a78de78d5f4d0cdc4e58531b125788a7c5f904db68a3f6f21f639d9",
42+
"fedora39": "c68971618737c66e76e39e7304a59f6af332c68dca64f0a97ff2393bfd09e136",
43+
"fedora39-aarch64": "aaec949e278427fc8ba095a4edf67b80d1a8230a5c7c43ef9383d6860407dd75",
44+
"ubi9": "a90b616b97616fdc4906babced4961982ab36a1e3ce44cf07d4a036298529abb",
45+
"ubi9-aarch64": "a90b616b97616fdc4906babced4961982ab36a1e3ce44cf07d4a036298529abb",
46+
"ubuntu22.04": "b3cafe1ca87ba0bf253639aec53052b545c9fcccd810da8cf15ac9ad62561f7e",
47+
"ubuntu22.04-aarch64": "6f3bff4c2a69163e56d2bacfa8ede2535ae52f5a29824f3c13d9e4c3ad1ac155",
48+
"ubuntu24.04": "2e226607d419f7b6197a6a0a9b317ee1cdb4125c21c72b0b24adfb82d4274fa9",
49+
"ubuntu24.04-aarch64": "53152dfed20e971f4cdbb40a205e9b4a8d8d34a84e1d0fefbdfce7af87072db1",
50+
"xcode": "1173886e2084a6705a774875e4b1b2fceeb890d79ced54ee824cfd10bdc26328",
51+
},
52+
"6.2.3": {
53+
"amazonlinux2": "fe1513e441ab653a134f9fd35855fe5dddac5fa716c0b0fe119eb76757525f05",
54+
"amazonlinux2-aarch64": "0753ec4fb786c626a681803c25ea3c681df583f0f576a6e326a25bd92294b4c6",
55+
"debian12": "d47b7416f68e75b3b8ed538c939dc6e5a9e9a8de2d605389661d2ef31e75b772",
56+
"debian12-aarch64": "6d9703968ef399b953e67229c5feb0781ceca12d089208ecef8157b59e22582b",
57+
"fedora39": "34314fab3f8e975980bcddf6b372b10e6430fb5c469e7232b95e06ae2762f449",
58+
"fedora39-aarch64": "802154a68eade7051ddaa290cf30d51a801a6b291edfc34643398acde9dffde9",
59+
"ubi9": "a43399aad9d5b19f7d7d6f88ed19129ca6afaf34bb6b455ca01e61a98ec425f2",
60+
"ubi9-aarch64": "a43399aad9d5b19f7d7d6f88ed19129ca6afaf34bb6b455ca01e61a98ec425f2",
61+
"ubuntu22.04": "23653abba4b153aa6625f73e63e3f119bdaf18363b00e3770a306fbd9b192aef",
62+
"ubuntu22.04-aarch64": "fbb4282ec60107cc844700aac6c7a8115534defb1c9b36867bd77c0829e5b163",
63+
"ubuntu24.04": "3e0b8eaf9210131a1756e6a1a9e9103bac83609a0ae604d6f2e791053f98f115",
64+
"ubuntu24.04-aarch64": "48dc99bcabc54feadd2942f4830be854ca2396e2db4ca4ec6b6c926a25c87d55",
65+
"xcode": "c1ed84cf543286c549caaccc47e0b47d8c61c3c8fedbce1205dedcbebe7601a8",
66+
},
67+
}

tools/swift-releases/BUILD

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
load(
2+
"//swift:swift_binary.bzl",
3+
"swift_binary",
4+
)
5+
6+
package(default_visibility = ["//visibility:public"])
7+
8+
licenses(["notice"])
9+
10+
swift_binary(
11+
name = "swift-releases",
12+
srcs = ["SwiftReleases.swift"],
13+
visibility = ["//visibility:public"],
14+
deps = [
15+
"@com_github_apple_swift_argument_parser//:ArgumentParser",
16+
],
17+
)

0 commit comments

Comments
 (0)