Skip to content

Commit

Permalink
Swift: add resource dir updater
Browse files Browse the repository at this point in the history
  • Loading branch information
redsun82 committed May 24, 2024
1 parent e8b857b commit 1529b58
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 7 deletions.
12 changes: 9 additions & 3 deletions swift/third_party/BUILD.swift-toolchain-linux.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("@rules_pkg//pkg:mappings.bzl", "pkg_filegroup", "pkg_files")
load("@rules_pkg//pkg:mappings.bzl", "pkg_files")
load("@rules_pkg//pkg:pkg.bzl", "pkg_zip")

_strip_prefix = "usr/lib/swift"

Expand Down Expand Up @@ -42,8 +43,13 @@ _pm_interface_files = [
for dir, interface, module in _pm_interface_files
]

pkg_filegroup(
name = "resource-dir",
pkg_zip(
name = "resource-dir-linux",
srcs = [":resource-dir-original"] + [":pkg-%s" % module for _, _, module in _pm_interface_files],
)

alias(
name = "swift_toolchain_linux",
actual = ":resource-dir-linux",
visibility = ["//visibility:public"],
)
13 changes: 12 additions & 1 deletion swift/third_party/BUILD.swift-toolchain-macos.bazel
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
load("@rules_pkg//pkg:mappings.bzl", "pkg_files")
load("@rules_pkg//pkg:pkg.bzl", "pkg_zip")

_strip_prefix = "usr/lib/swift"

pkg_files(
name = "resource-dir",
name = "resource-dir-files",
srcs = glob(
["usr/lib/swift/**/*"],
),
strip_prefix = _strip_prefix,
)

pkg_zip(
name = "resource-dir-macos",
srcs = [":resource-dir-files"],
)

alias(
name = "swift_toolchain_macos",
actual = ":resource-dir-macos",
visibility = ["//visibility:public"],
)
27 changes: 24 additions & 3 deletions swift/third_party/resource-dir/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,9 +1,30 @@
load("//misc/bazel:pkg.bzl", "codeql_pkg_zip")
load("//misc/bazel:pkg.bzl", "codeql_pkg_zip_import")

codeql_pkg_zip(
codeql_pkg_zip_import(
name = "resource-dir",
src = select({"@platforms//os:" + os: "@swift-resource-dir-" + os for os in ("linux", "macos")}),
arch_specific = True,
target_compatible_with = select({"@platforms//os:windows": ["@platforms//:incompatible"]}),
target_compatible_with = select({
"@platforms//os:windows": ["@platforms//:incompatible"],
"//conditions:default": [],
}),
visibility = ["//swift:__pkg__"],
)

[
sh_binary(
name = "update-" + os,
srcs = ["update.sh"],
args = [
"$(rlocationpath @swift_toolchain_%s)" % os,
"$(rlocationpath resource-dir-%s.zip)" % os,
],
data = [
"resource-dir-%s.zip" % os,
"@swift_toolchain_" + os,
],
target_compatible_with = ["@platforms//os:" + os],
deps = ["@bazel_tools//tools/bash/runfiles"],
)
for os in ("linux", "macos")
]
12 changes: 12 additions & 0 deletions swift/third_party/resource-dir/update.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# --- begin runfiles.bash initialization v3 ---
# Copy-pasted from the Bazel Bash runfiles library v3.
set -uo pipefail; set +e; f=bazel_tools/tools/bash/runfiles/runfiles.bash
source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \
source "$0.runfiles/$f" 2>/dev/null || \
source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
# --- end runfiles.bash initialization v3 ---

cp "$(rlocation "$1")" "$(rlocation "$2")"

0 comments on commit 1529b58

Please sign in to comment.