mirror of
https://github.com/github/codeql.git
synced 2026-07-23 04:02:07 +02:00
Add macOS (xcode) support to swift-syntax-rs build
This commit is contained in:
committed by
GitHub
parent
a8edbcf1dc
commit
29dcff8ff3
17
MODULE.bazel
17
MODULE.bazel
@@ -227,12 +227,17 @@ use_repo(
|
||||
# patched prebuilt toolchain wired up via `swift_deps` above.
|
||||
#
|
||||
# Bazel cannot auto-select between Linux distributions, so the toolchain is
|
||||
# registered explicitly for the distribution our CI runs on (ubuntu24.04,
|
||||
# x86_64). Add further platforms here if CI grows to cover them.
|
||||
# registered explicitly for the distributions/platforms our CI runs on:
|
||||
# - ubuntu24.04 / x86_64 (Linux CI)
|
||||
# - xcode (macOS CI — covers both Apple Silicon and Intel)
|
||||
#
|
||||
# We register the `exec` toolchain (normal host compilation, targeting
|
||||
# linux/x86_64) rather than the `embedded` one, which targets `os:none`
|
||||
# (Embedded Swift) and would not match a normal host build.
|
||||
# NOTE: The macOS toolchain is distributed as a `.pkg` archive that can only
|
||||
# be extracted on a macOS host. Do not build the `xcode` toolchain on Linux.
|
||||
#
|
||||
# We register the `exec` toolchains (normal host compilation) rather than the
|
||||
# `embedded` ones, which target `os:none` (Embedded Swift) and would not
|
||||
# match a normal host build. Bazel selects the toolchain matching the host
|
||||
# platform automatically.
|
||||
#
|
||||
# The Swift version is read from `unified/swift-syntax-rs/.swift-version`, which
|
||||
# is the single source of truth shared with the local `cargo` build (via
|
||||
@@ -246,10 +251,12 @@ use_repo(
|
||||
swift,
|
||||
"swift_toolchain",
|
||||
"swift_toolchain_ubuntu24.04",
|
||||
"swift_toolchain_xcode",
|
||||
)
|
||||
|
||||
register_toolchains(
|
||||
"@swift_toolchain//:swift_toolchain_exec_ubuntu24.04",
|
||||
"@swift_toolchain//:swift_toolchain_exec_xcode",
|
||||
)
|
||||
|
||||
node = use_extension("@rules_nodejs//nodejs:extensions.bzl", "node")
|
||||
|
||||
@@ -42,11 +42,16 @@ rust_binary(
|
||||
name = "swift-syntax-parse",
|
||||
srcs = ["src/main.rs"],
|
||||
# The Swift toolchain propagates a runfiles-relative RPATH to its runtime
|
||||
# `.so`s via `swift_syntax_ffi`'s `CcInfo`, but (unlike `swift_binary`)
|
||||
# `rust_binary` does not copy those libraries into runfiles. Add the
|
||||
# toolchain files as `data` so the runtime is found at execution time.
|
||||
# (rules_swift does not yet support statically linking the runtime.)
|
||||
data = ["@swift_toolchain_ubuntu24.04//:files"],
|
||||
# `.so`s/`.dylib`s via `swift_syntax_ffi`'s `CcInfo`, but (unlike
|
||||
# `swift_binary`) `rust_binary` does not copy those libraries into runfiles.
|
||||
# Add the toolchain files as `data` so the runtime is found at execution
|
||||
# time. (rules_swift does not yet support statically linking the runtime.)
|
||||
# Select the correct per-platform toolchain repo: `xcode` on macOS,
|
||||
# `ubuntu24.04` on Linux.
|
||||
data = select({
|
||||
"@platforms//os:macos": ["@swift_toolchain_xcode//:files"],
|
||||
"//conditions:default": ["@swift_toolchain_ubuntu24.04//:files"],
|
||||
}),
|
||||
edition = "2024",
|
||||
deps = [":swift_syntax_rs"],
|
||||
)
|
||||
@@ -55,6 +60,9 @@ rust_test(
|
||||
name = "swift_syntax_rs_test",
|
||||
size = "small",
|
||||
crate = ":swift_syntax_rs",
|
||||
data = ["@swift_toolchain_ubuntu24.04//:files"],
|
||||
data = select({
|
||||
"@platforms//os:macos": ["@swift_toolchain_xcode//:files"],
|
||||
"//conditions:default": ["@swift_toolchain_ubuntu24.04//:files"],
|
||||
}),
|
||||
edition = "2024",
|
||||
)
|
||||
|
||||
@@ -144,10 +144,12 @@ Requirements:
|
||||
- **`clang`** must be installed on the runner. `rules_swift` requires the Bazel
|
||||
CC toolchain to use clang; the repo's `.bazelrc` already sets
|
||||
`--repo_env=CC=clang`, so no extra flags are needed.
|
||||
- The registered Swift toolchain currently targets **ubuntu24.04 / x86_64**
|
||||
only (Bazel cannot auto-select between Linux distributions). Add more
|
||||
platforms in `MODULE.bazel` (`swift.toolchain` + `register_toolchains`) if CI
|
||||
grows to cover them.
|
||||
- The registered Swift toolchains cover **ubuntu24.04 / x86_64** and
|
||||
**macOS / `xcode`** (both Apple Silicon and Intel). Bazel automatically
|
||||
selects the toolchain matching the host platform.
|
||||
- **macOS only:** the macOS toolchain is distributed as a `.pkg` archive that
|
||||
can only be fetched and extracted on a macOS host. Building the `xcode`
|
||||
toolchain on Linux is not supported.
|
||||
|
||||
The Swift compiler version is read from [`.swift-version`](.swift-version) by
|
||||
both the Bazel toolchain (`swift.toolchain(swift_version_file = …)`) and the
|
||||
|
||||
@@ -73,7 +73,7 @@ fn swift_runtime_dir() -> Option<PathBuf> {
|
||||
let close = value_start.find('"')?;
|
||||
let resource_path = &value_start[..close];
|
||||
|
||||
Some(PathBuf::from(resource_path).join("linux"))
|
||||
Some(PathBuf::from(resource_path).join(if cfg!(target_os = "macos") { "macosx" } else { "linux" }))
|
||||
}
|
||||
|
||||
/// The `swift` driver to invoke: `$SWIFT` if set, otherwise `swift` from `PATH`.
|
||||
|
||||
Reference in New Issue
Block a user