Skip to content

Commit e3a0822

Browse files
tausbnCopilot
andcommitted
unified: Package the swift-syntax parser in the extractor pack
The extractor shells out to a separate `swift-syntax-parse` binary, but nothing placed it in the extractor pack, so a shipped Swift extraction failed at the first spawn. Package it next to the extractor, the same way `//swift/extractor` ships its Swift-linked binary: a small wrapper points the dynamic loader at its own directory and execs the real binary, whose Swift runtime libraries travel alongside it. - `swift-syntax-parse.sh`: wrapper that sets `LD_LIBRARY_PATH` / `DYLD_LIBRARY_PATH` to its directory and execs `swift-syntax-parse.real` (mirrors `swift/extractor/extractor.sh`). - `runtime.bzl`: a `swift_runtime_libs` rule that selects just the Linux Swift runtime shared objects (`usr/lib/swift/linux/*.so`) out of the full toolchain, so only they — not the whole toolchain — travel with the binary. - `swift-syntax-rs/BUILD.bazel`: the `rust_binary` becomes `swift-syntax-parse.real` and carries the runtime libraries as runfiles on Linux; a `sh_binary` (`swift-syntax-parse`) is the wrapper; `codeql_pkg_runfiles` flattens the three (wrapper, real binary, runtime) into one directory. - `BUILD.bazel`: ship that group under `tools/{CODEQL_PLATFORM}` next to the extractor, on the platforms where swift-syntax builds (Linux/macOS). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 7721ce2 commit e3a0822

3 files changed

Lines changed: 62 additions & 5 deletions

File tree

‎unified/BUILD.bazel‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
load("@rules_pkg//pkg:mappings.bzl", "pkg_filegroup")
22
load("//misc/bazel:pkg.bzl", "codeql_pack", "codeql_pkg_files")
3+
load("//misc/bazel:utils.bzl", "select_os")
34

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

@@ -46,12 +47,26 @@ codeql_pkg_files(
4647
prefix = "tools/{CODEQL_PLATFORM}",
4748
)
4849

50+
# The Swift front-end parser (wrapper + real binary + bundled Swift runtime),
51+
# shipped next to the extractor. Only on platforms where swift-syntax builds
52+
# (Linux/macOS); elsewhere the group is empty so the pack still builds (Swift
53+
# extraction is simply unavailable there).
54+
pkg_filegroup(
55+
name = "swift-syntax-parse-arch",
56+
srcs = select_os(
57+
posix = ["//unified/swift-syntax-rs:swift-syntax-parse-pkg"],
58+
otherwise = [],
59+
),
60+
prefix = "tools/{CODEQL_PLATFORM}",
61+
)
62+
4963
codeql_pack(
5064
name = "unified",
5165
srcs = [
5266
":codeql-extractor-yml",
5367
":dbscheme-group",
5468
":extractor-arch",
69+
":swift-syntax-parse-arch",
5570
"//unified/tools",
5671
],
5772
)

‎unified/swift-syntax-rs/BUILD.bazel‎

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_library", "rust_test")
2+
load("@rules_shell//shell:sh_binary.bzl", "sh_binary")
3+
load("//misc/bazel:pkg.bzl", "codeql_pkg_runfiles")
24
load(":swift_runtime.bzl", "swift_runtime_libs")
35
load(":xcode_transition.bzl", "xcode_transition_swift_library")
46

@@ -48,13 +50,19 @@ rust_library(
4850
],
4951
)
5052

53+
# The Swift front-end parser. We ship it like `//swift/extractor`: a small shell
54+
# wrapper (`swift-syntax-parse`) sets `LD_LIBRARY_PATH`/`DYLD_LIBRARY_PATH` to its
55+
# own directory and execs the real binary (`swift-syntax-parse.real`); the Swift
56+
# runtime shared libraries are packaged alongside them. `parse.rs` resolves the
57+
# wrapper as a sibling of the extractor executable.
5158
rust_binary(
52-
name = "swift-syntax-parse",
59+
name = "swift-syntax-parse.real",
5360
srcs = ["src/main.rs"],
54-
# `rust_binary` doesn't copy the Swift runtime into runfiles the way
55-
# `swift_binary` does. On Linux, ship the standalone toolchain's runtime;
56-
# on macOS the OS provides it at `/usr/lib/swift` (rpath'd by
57-
# `xcode_swift_toolchain`).
61+
# Target name carries `.real` (invalid in a crate name), so set it explicitly.
62+
crate_name = "swift_syntax_parse",
63+
# On Linux, carry the toolchain's runtime shared libraries as runfiles so
64+
# they get packaged next to the binary. On macOS the OS provides the Swift
65+
# runtime, so nothing extra is bundled.
5866
data = select({
5967
"@platforms//os:macos": [],
6068
"@platforms//os:linux": [":swift_runtime_libs"],
@@ -64,6 +72,28 @@ rust_binary(
6472
deps = [":swift_syntax_rs"],
6573
)
6674

75+
# `swift-syntax-parse` wrapper (see `swift-syntax-parse.sh`). Its runfiles carry
76+
# the real binary and the runtime libraries; packaging flattens them into one
77+
# directory.
78+
sh_binary(
79+
name = "swift-syntax-parse",
80+
srcs = ["swift-syntax-parse.sh"],
81+
data = [":swift-syntax-parse.real"],
82+
target_compatible_with = _SWIFT_SUPPORTED_PLATFORMS,
83+
)
84+
85+
# Packaged form for the extractor pack: the wrapper (as `swift-syntax-parse`),
86+
# the real binary, and the runtime libraries, flattened into one directory.
87+
codeql_pkg_runfiles(
88+
name = "swift-syntax-parse-pkg",
89+
exes = [":swift-syntax-parse"],
90+
# The `.sh` source is shipped as `swift-syntax-parse` (the wrapper); drop the
91+
# original filename.
92+
excludes = ["swift-syntax-parse.sh"],
93+
target_compatible_with = _SWIFT_SUPPORTED_PLATFORMS,
94+
visibility = ["//unified:__pkg__"],
95+
)
96+
6797
rust_test(
6898
name = "swift_syntax_rs_test",
6999
size = "small",
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
# Wrapper that lets the shipped `swift-syntax-parse` find its Swift runtime
4+
# libraries, which are packaged in the same directory as this script (and the
5+
# real binary). Mirrors `swift/extractor/extractor.sh`.
6+
if [[ "$(uname)" == Darwin ]]; then
7+
export DYLD_LIBRARY_PATH=$(dirname "$0")
8+
else
9+
export LD_LIBRARY_PATH=$(dirname "$0")
10+
fi
11+
12+
exec -a "$0" "$0.real" "$@"

0 commit comments

Comments
 (0)