Skip to content

Commit cf8eeb8

Browse files
committed
Only depend on the runtime libraries from the Swift toolchain
1 parent bf57586 commit cf8eeb8

2 files changed

Lines changed: 27 additions & 2 deletions

File tree

unified/swift-syntax-rs/BUILD.bazel

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_library", "rust_test")
2+
load(":swift_runtime.bzl", "swift_runtime_libs")
23
load(":xcode_transition.bzl", "xcode_transition_swift_library")
34

45
package(default_visibility = ["//visibility:public"])
56

7+
swift_runtime_libs(
8+
name = "swift_runtime_libs",
9+
toolchain = "@swift_toolchain_ubuntu24.04//:files",
10+
)
11+
612
# Targets in this package require a Swift toolchain (Linux or macOS).
713
# `select()` gives us OR-of-OSes; other platforms get marked incompatible
814
# so `bazel build/test //...` skips them cleanly.
@@ -50,7 +56,7 @@ rust_binary(
5056
# `xcode_swift_toolchain`).
5157
data = select({
5258
"@platforms//os:macos": [],
53-
"@platforms//os:linux": ["@swift_toolchain_ubuntu24.04//:files"],
59+
"@platforms//os:linux": [":swift_runtime_libs"],
5460
}),
5561
edition = "2024",
5662
target_compatible_with = _SWIFT_SUPPORTED_PLATFORMS,
@@ -63,7 +69,7 @@ rust_test(
6369
crate = ":swift_syntax_rs",
6470
data = select({
6571
"@platforms//os:macos": [],
66-
"@platforms//os:linux": ["@swift_toolchain_ubuntu24.04//:files"],
72+
"@platforms//os:linux": [":swift_runtime_libs"],
6773
}),
6874
edition = "2024",
6975
target_compatible_with = _SWIFT_SUPPORTED_PLATFORMS,
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""Filter the Swift toolchain down to just its Linux runtime shared objects.
2+
3+
The standalone toolchain's `:files` bundles the compiler, host libraries, clang
4+
runtime, plugins, etc. For running a Swift-linked binary we only need the
5+
runtime shared objects in `usr/lib/swift/linux/`.
6+
"""
7+
8+
def _swift_runtime_libs_impl(ctx):
9+
libs = [
10+
f
11+
for f in ctx.files.toolchain
12+
if "/usr/lib/swift/linux/" in f.path and f.path.endswith(".so")
13+
]
14+
return [DefaultInfo(files = depset(libs))]
15+
16+
swift_runtime_libs = rule(
17+
implementation = _swift_runtime_libs_impl,
18+
attrs = {"toolchain": attr.label(allow_files = True)},
19+
)

0 commit comments

Comments
 (0)