|
1 | 1 | 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") |
| 4 | +load(":runtime.bzl", "swift_runtime_libs") |
2 | 5 | load(":xcode_transition.bzl", "xcode_transition_swift_library") |
3 | 6 |
|
4 | 7 | package(default_visibility = ["//visibility:public"]) |
@@ -54,22 +57,58 @@ rust_library( |
54 | 57 | ], |
55 | 58 | ) |
56 | 59 |
|
| 60 | +# The Swift front-end parser. We ship it like `//swift/extractor`: a small shell |
| 61 | +# wrapper (`swift-syntax-parse`) sets `LD_LIBRARY_PATH`/`DYLD_LIBRARY_PATH` to its |
| 62 | +# own directory and execs the real binary (`swift-syntax-parse.real`); the Swift |
| 63 | +# runtime shared libraries are packaged alongside them. `parse.rs` resolves the |
| 64 | +# wrapper as a sibling of the extractor executable. |
57 | 65 | rust_binary( |
58 | | - name = "swift-syntax-parse", |
| 66 | + name = "swift-syntax-parse.real", |
59 | 67 | srcs = ["src/main.rs"], |
60 | | - # `rust_binary` doesn't copy the Swift runtime into runfiles the way |
61 | | - # `swift_binary` does. On Linux, ship the standalone toolchain's runtime; |
62 | | - # on macOS the OS provides it at `/usr/lib/swift` (rpath'd by |
63 | | - # `xcode_swift_toolchain`). |
| 68 | + # Target name carries `.real` (invalid in a crate name), so set it explicitly. |
| 69 | + crate_name = "swift_syntax_parse", |
| 70 | + # On Linux, carry the toolchain's runtime shared libraries as runfiles so |
| 71 | + # they get packaged next to the binary. On macOS the OS provides the Swift |
| 72 | + # runtime, so nothing extra is bundled. |
64 | 73 | data = select({ |
65 | | - "@platforms//os:macos": [], |
66 | | - "@platforms//os:linux": ["@swift_toolchain_ubuntu24.04//:files"], |
| 74 | + "@platforms//os:linux": [":swift_runtime_libs"], |
| 75 | + "//conditions:default": [], |
67 | 76 | }), |
68 | 77 | edition = "2024", |
69 | 78 | target_compatible_with = _SWIFT_SUPPORTED_PLATFORMS, |
70 | 79 | deps = [":swift_syntax_rs"], |
71 | 80 | ) |
72 | 81 |
|
| 82 | +# The Linux runtime shared libraries (`libswiftCore.so`, …) filtered out of the |
| 83 | +# full toolchain, so only they (not the whole toolchain) travel with the binary. |
| 84 | +swift_runtime_libs( |
| 85 | + name = "swift_runtime_libs", |
| 86 | + toolchain = "@swift_toolchain_ubuntu24.04//:files", |
| 87 | + target_compatible_with = ["@platforms//os:linux"], |
| 88 | +) |
| 89 | + |
| 90 | +# `swift-syntax-parse` wrapper (see `swift-syntax-parse.sh`). Its runfiles carry |
| 91 | +# the real binary and the runtime libraries; packaging flattens them into one |
| 92 | +# directory. |
| 93 | +sh_binary( |
| 94 | + name = "swift-syntax-parse", |
| 95 | + srcs = ["swift-syntax-parse.sh"], |
| 96 | + data = [":swift-syntax-parse.real"], |
| 97 | + target_compatible_with = _SWIFT_SUPPORTED_PLATFORMS, |
| 98 | +) |
| 99 | + |
| 100 | +# Packaged form for the extractor pack: the wrapper (as `swift-syntax-parse`), |
| 101 | +# the real binary, and the runtime libraries, flattened into one directory. |
| 102 | +codeql_pkg_runfiles( |
| 103 | + name = "swift-syntax-parse-pkg", |
| 104 | + exes = [":swift-syntax-parse"], |
| 105 | + # The `.sh` source is shipped as `swift-syntax-parse` (the wrapper); drop the |
| 106 | + # original filename. |
| 107 | + excludes = ["swift-syntax-parse.sh"], |
| 108 | + target_compatible_with = _SWIFT_SUPPORTED_PLATFORMS, |
| 109 | + visibility = ["//unified:__pkg__"], |
| 110 | +) |
| 111 | + |
73 | 112 | rust_test( |
74 | 113 | name = "swift_syntax_rs_test", |
75 | 114 | size = "small", |
|
0 commit comments