-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathrepositories.bzl
More file actions
89 lines (76 loc) · 3.03 KB
/
Copy pathrepositories.bzl
File metadata and controls
89 lines (76 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
"""Definitions for handling Bazel repositories used by the swift-index-store."""
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
def _maybe(repo_rule, name, **kwargs):
"""
Executes the given repository rule if it hasn't been executed already.
Args:
repo_rule: The repository rule to be executed (e.g., `http_archive`.)
name: The name of the repository to be defined by the rule.
**kwargs: Additional arguments passed directly to the repository rule.
"""
if not native.existing_rule(name):
repo_rule(name = name, **kwargs)
def swift_index_store_dependencies(bzlmod = False):
if not bzlmod:
_maybe(
http_archive,
name = "build_bazel_rules_swift",
sha256 = "28a66ff5d97500f0304f4e8945d936fe0584e0d5b7a6f83258298007a93190ba",
url = "https://github.com/bazelbuild/rules_swift/releases/download/1.13.0/rules_swift.1.13.0.tar.gz",
)
_maybe(
http_archive,
name = "build_bazel_rules_apple",
sha256 = "34c41bfb59cdaea29ac2df5a2fa79e5add609c71bb303b2ebb10985f93fa20e7",
url = "https://github.com/bazelbuild/rules_apple/releases/download/3.1.1/rules_apple.3.1.1.tar.gz",
)
_maybe(
http_archive,
name = "StaticIndexStore",
url = "https://github.com/keith/StaticIndexStore/releases/download/5.7/libIndexStore.xcframework.zip",
sha256 = "da69bab932357a817aa0756e400be86d7156040bfbea8eded7a3acc529320731",
build_file_content = """
load("@build_bazel_rules_apple//apple:apple.bzl", "apple_static_xcframework_import")
apple_static_xcframework_import(
name = "libIndexStore",
visibility = ["//visibility:public"],
xcframework_imports = glob(["libIndexStore.xcframework/**"]),
)
""",
)
_EMPTY_LIBRARY = """\
load("@rules_cc//cc:defs.bzl", "cc_library")
cc_library(
name = "libIndexStore",
visibility = ["//visibility:public"],
)
"""
def _linux_indexstore_impl(repository_ctx):
os_name = repository_ctx.os.name
if "linux" not in os_name.lower():
repository_ctx.file("BUILD.bazel", _EMPTY_LIBRARY)
return
swiftc = repository_ctx.which("swiftc")
if swiftc == None:
repository_ctx.file("BUILD.bazel", _EMPTY_LIBRARY)
return
lib_dir = repository_ctx.path(str(swiftc.realpath.dirname.dirname) + "/lib")
indexstore = lib_dir.get_child("libIndexStore.so")
if not indexstore.exists:
fail("libIndexStore.so not found at %s" % indexstore)
repository_ctx.symlink(indexstore, "libIndexStore.so")
repository_ctx.file("BUILD.bazel", """\
load("@rules_cc//cc:defs.bzl", "cc_import")
cc_import(
name = "libIndexStore",
shared_library = "libIndexStore.so",
visibility = ["//visibility:public"],
)
""")
_linux_indexstore = repository_rule(
implementation = _linux_indexstore_impl,
)
def _bzlmod_deps(_):
swift_index_store_dependencies(bzlmod = True)
_linux_indexstore(name = "LinuxIndexStore")
bzlmod_deps = module_extension(implementation = _bzlmod_deps)