Skip to content

Commit 7474a33

Browse files
committed
unified: Hardcode swift_version
It seems that using swift_version_file has some issues when `codeql` is consumed as a dependency module. I'm hoping hardcoding the version instead will fix this, but ideally we should find a more robust solution.
1 parent 205c9a9 commit 7474a33

3 files changed

Lines changed: 24 additions & 16 deletions

File tree

MODULE.bazel

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,19 @@ use_repo(
229229
# Swift toolchain for building `unified/swift-syntax-rs`. On Linux we register
230230
# a hermetic swift.org toolchain as the exec toolchain; on macOS `rules_swift`
231231
# auto-registers `xcode_swift_toolchain` (host Xcode + OS-provided Swift
232-
# runtime), which is not hermetic. Version comes from
233-
# `unified/swift-syntax-rs/.swift-version`.
232+
# runtime), which is not hermetic.
233+
#
234+
# The version is pinned as a literal rather than read from
235+
# `unified/swift-syntax-rs/.swift-version` via `swift_version_file`: the latter
236+
# makes the extension `module_ctx.read` a `//unified/...` label, which fails to
237+
# resolve when this repo is consumed as a dependency module (`@@ql+`) whose
238+
# `unified/swift-syntax-rs` package is not loadable in that context. Keep this
239+
# in sync with `unified/swift-syntax-rs/.swift-version` (used by the `cargo`
240+
# build) and the `swift-syntax` release in `swift/Package.swift`.
234241
swift = use_extension("@rules_swift//swift:extensions.bzl", "swift")
235242
swift.toolchain(
236243
name = "swift_toolchain",
237-
swift_version_file = "//unified/swift-syntax-rs:.swift-version",
244+
swift_version = "6.3.2",
238245
)
239246
use_repo(
240247
swift,

unified/swift-syntax-rs/BUILD.bazel

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ load(":xcode_transition.bzl", "xcode_transition_swift_library")
33

44
package(default_visibility = ["//visibility:public"])
55

6-
# Pinned Swift version, shared with `cargo` and `swift/Package.swift`.
7-
# Referenced by `swift.toolchain(swift_version_file = ...)` in //:MODULE.bazel.
8-
exports_files([".swift-version"])
9-
106
# Targets in this package require a Swift toolchain (Linux or macOS).
117
# `select()` gives us OR-of-OSes; other platforms get marked incompatible
128
# so `bazel build/test //...` skips them cleanly.

unified/swift-syntax-rs/README.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,20 @@ Requirements:
155155
[`xcode_transition.bzl`](xcode_transition.bzl)), so other targets on macOS
156156
keep using Bazel's default CC toolchain.
157157

158-
The Swift compiler version in [`.swift-version`](.swift-version) is kept in sync
159-
with the `swift-syntax` release pinned in `swift/Package.swift`. It is honored on
160-
**Linux**, where the hermetic swift.org Bazel toolchain
161-
(`swift.toolchain(swift_version_file = …)`) and the local `cargo`/`swift build`
162-
both read it. On **macOS** it is *not* honored by the Bazel build: `rules_swift`
163-
auto-registers the host `xcode_swift_toolchain`, which uses whichever Swift ships
164-
with the installed Xcode and ignores `.swift-version`. So the pinned version
165-
governs Linux (and local) builds, while the macOS compiler version depends on the
166-
host Xcode.
158+
The Swift compiler version is kept in sync across three places: the
159+
[`.swift-version`](.swift-version) file (read by the local `cargo`/`swift build`
160+
and by [swiftly](https://www.swift.org/swiftly/)), the literal `swift_version`
161+
pinned on `swift.toolchain(...)` in the root `MODULE.bazel` (the hermetic
162+
swift.org **Linux** Bazel toolchain), and the `swift-syntax` release in
163+
`swift/Package.swift`. On **macOS** the version is *not* pinned by the Bazel
164+
build: `rules_swift` auto-registers the host `xcode_swift_toolchain`, which uses
165+
whichever Swift ships with the installed Xcode. So the pin governs Linux (and
166+
local) builds, while the macOS compiler version depends on the host Xcode.
167+
168+
(The Bazel toolchain pins a literal rather than reading `.swift-version` via
169+
`swift_version_file`, because the latter makes the module extension read a
170+
`//unified/...` label, which fails when this repo is consumed as a dependency
171+
module.)
167172

168173
## Usage
169174

0 commit comments

Comments
 (0)