From 45ea6b552f2e8888282ef4acc4525d890606e830 Mon Sep 17 00:00:00 2001 From: Jeroen Ketema <93738568+jketema@users.noreply.github.com> Date: Wed, 12 Aug 2026 11:39:50 +0000 Subject: [PATCH 1/2] Bazel: Update to latest `rules_cc`, `rules_swift`, and `apple_support` Note that `rules_swift` requires the versions of `apple_support` and `rules_cc` we're updating to. Also update the Swift version we use in the build to 6.3.3, which is supported out-of-the-box by the new `rules_swift` version. --- .bazelrc | 3 +++ MODULE.bazel | 8 ++++---- unified/swift-syntax-rs/.swift-version | 2 +- unified/swift-syntax-rs/BUILD.bazel | 17 +++++++++++++---- unified/swift-syntax-rs/README.md | 2 +- .../swift-syntax-rs/swift_runtime_linking.bzl | 11 +++++++++++ 6 files changed, 33 insertions(+), 10 deletions(-) create mode 100644 unified/swift-syntax-rs/swift_runtime_linking.bzl diff --git a/.bazelrc b/.bazelrc index 8687f4406cb9..e34a363a16fc 100644 --- a/.bazelrc +++ b/.bazelrc @@ -11,6 +11,9 @@ build --compilation_mode opt common --override_module=semmle_code=%workspace%/misc/bazel/semmle_code_stub build --repo_env=CC=clang --repo_env=CXX=clang++ +# The standalone Linux toolchain uses gold, which does not support the +# LLD-specific -z nostart-stop-gc workaround enabled by rules_swift. +build:linux --features=-swift.lld_gc_workaround # Disable Android SDK auto-detection (we don't use it, and rules_android has Bazel 9 compatibility issues) build --repo_env=ANDROID_HOME= diff --git a/MODULE.bazel b/MODULE.bazel index e8d49c11bcb4..0584af40dc69 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -15,7 +15,7 @@ local_path_override( # see https://registry.bazel.build/ for a list of available packages bazel_dep(name = "platforms", version = "1.0.0") -bazel_dep(name = "rules_cc", version = "0.2.17") +bazel_dep(name = "rules_cc", version = "0.2.20") bazel_dep(name = "rules_go", version = "0.60.0") bazel_dep(name = "rules_java", version = "9.6.1") bazel_dep(name = "rules_pkg", version = "1.2.0") @@ -31,13 +31,13 @@ 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.69.0") -bazel_dep(name = "rules_swift", version = "4.0.0-rc4") +bazel_dep(name = "rules_swift", version = "4.0.0-rc5") bazel_dep(name = "swift-syntax", version = "603.0.2") # Needed so we can `use_repo` `local_config_xcode` and # `local_config_apple_cc_toolchains` below (referenced by the per-target # Xcode-config transition in `unified/swift-syntax-rs/xcode_transition.bzl`). -bazel_dep(name = "apple_support", version = "2.6.1") +bazel_dep(name = "apple_support", version = "2.8.0") bazel_dep(name = "zstd", version = "1.5.7.bcr.1") bazel_dep(name = "buildifier_prebuilt", version = "6.4.0", dev_dependency = True) @@ -238,7 +238,7 @@ use_repo( swift = use_extension("@rules_swift//swift:extensions.bzl", "swift") swift.toolchain( name = "swift_toolchain", - swift_version = "6.3.2", + swift_version = "6.3.3", ) use_repo( swift, diff --git a/unified/swift-syntax-rs/.swift-version b/unified/swift-syntax-rs/.swift-version index 91e4a9f26224..7849b73dc743 100644 --- a/unified/swift-syntax-rs/.swift-version +++ b/unified/swift-syntax-rs/.swift-version @@ -1 +1 @@ -6.3.2 +6.3.3 diff --git a/unified/swift-syntax-rs/BUILD.bazel b/unified/swift-syntax-rs/BUILD.bazel index 0f04f3e9182c..b1d0d40207f7 100644 --- a/unified/swift-syntax-rs/BUILD.bazel +++ b/unified/swift-syntax-rs/BUILD.bazel @@ -2,6 +2,7 @@ load("@rules_cc//cc:defs.bzl", "cc_library") load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_library", "rust_test") load("//unified:platforms.bzl", "UNIFIED_SUPPORTED_PLATFORMS") load(":swift_runtime.bzl", "swift_runtime_libs") +load(":swift_runtime_linking.bzl", "swift_runtime_linking") load(":xcode_transition.bzl", "xcode_transition_swift_library") package(default_visibility = ["//visibility:public"]) @@ -11,15 +12,23 @@ swift_runtime_libs( toolchain = "@swift_toolchain_ubuntu22.04//:files", ) -# The `$ORIGIN` runpath makes an executable look beside itself instead, so -# we find the Swift runtime libraries we bundle with the extractor. +swift_runtime_linking( + name = "_swift_runtime_cc_info", +) + +# On Linux, provide the downloaded Swift runtime at link time and look beside +# the executable for the copies bundled with the extractor at runtime. cc_library( - name = "swift_runtime_rpath", + name = "swift_runtime_linking", linkopts = select({ "@platforms//os:linux": ["-Wl,-rpath,$$ORIGIN"], "//conditions:default": [], }), target_compatible_with = UNIFIED_SUPPORTED_PLATFORMS, + deps = select({ + "@platforms//os:linux": [":_swift_runtime_cc_info"], + "//conditions:default": [], + }), ) # Swift FFI shim: wraps swift-syntax and exposes a small C ABI. @@ -46,7 +55,7 @@ rust_library( edition = "2024", target_compatible_with = UNIFIED_SUPPORTED_PLATFORMS, deps = [ - ":swift_runtime_rpath", + ":swift_runtime_linking", ":swift_syntax_ffi", ], ) diff --git a/unified/swift-syntax-rs/README.md b/unified/swift-syntax-rs/README.md index 8a93e4739d9d..f4e84e18f361 100644 --- a/unified/swift-syntax-rs/README.md +++ b/unified/swift-syntax-rs/README.md @@ -129,7 +129,7 @@ The build does not depend on any particular version manager. You need: - **Rust** — pinned to `1.88` by the repo-root [`rust-toolchain.toml`](../../rust-toolchain.toml), which `rustup` picks up automatically. - **Swift** — pinned to the version in [`.swift-version`](.swift-version) - (currently `6.3.2`), used to build `swift-syntax` `603.0.2`. Install it any way + (currently `6.3.3`), used to build `swift-syntax` `603.0.2`. Install it any way you like — [swift.org](https://www.swift.org/install/) or [swiftly](https://www.swift.org/swiftly/) (which reads `.swift-version`), or a system package. Just make sure `swift` (and `swiftc`) are on your `PATH` — diff --git a/unified/swift-syntax-rs/swift_runtime_linking.bzl b/unified/swift-syntax-rs/swift_runtime_linking.bzl new file mode 100644 index 000000000000..ec2577d2e3df --- /dev/null +++ b/unified/swift-syntax-rs/swift_runtime_linking.bzl @@ -0,0 +1,11 @@ +"""Expose the selected Swift toolchain's dynamic runtime to native dependents.""" + +load("@rules_swift//swift:swift.bzl", "swift_common") + +def _swift_runtime_linking_impl(ctx): + return [swift_common.get_toolchain(ctx).dynamic_runtime_cc_info] + +swift_runtime_linking = rule( + implementation = _swift_runtime_linking_impl, + toolchains = swift_common.use_toolchain(), +) From 8ebd3bc6cc4899c066fc992d9169fd8905dfbbf9 Mon Sep 17 00:00:00 2001 From: Jeroen Ketema <93738568+jketema@users.noreply.github.com> Date: Wed, 12 Aug 2026 13:48:25 +0000 Subject: [PATCH 2/2] Bazel: Address Copilot review comment --- unified/swift-syntax-rs/BUILD.bazel | 2 ++ 1 file changed, 2 insertions(+) diff --git a/unified/swift-syntax-rs/BUILD.bazel b/unified/swift-syntax-rs/BUILD.bazel index b1d0d40207f7..95f644b200f4 100644 --- a/unified/swift-syntax-rs/BUILD.bazel +++ b/unified/swift-syntax-rs/BUILD.bazel @@ -14,6 +14,8 @@ swift_runtime_libs( swift_runtime_linking( name = "_swift_runtime_cc_info", + target_compatible_with = ["@platforms//os:linux"], + visibility = ["//visibility:private"], ) # On Linux, provide the downloaded Swift runtime at link time and look beside