Skip to content

Commit cbd91ca

Browse files
authored
Adds support for bazel (#4)
Adds bazel support and gets all executable targets running.
1 parent e7d2ba4 commit cbd91ca

File tree

43 files changed

+248
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+248
-0
lines changed

.bazelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
build --incompatible_disallow_empty_glob
2+
build --macos_minimum_os=12.0
3+
build --host_macos_minimum_os=12.0

.bazelversion

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
6.1.0

.github/workflows/bazel.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: Bazel
2+
on:
3+
pull_request:
4+
types: [opened]
5+
push:
6+
jobs:
7+
TestMac:
8+
runs-on: macos-latest
9+
steps:
10+
- uses: actions/checkout@v3
11+
- uses: swift-actions/setup-swift@v1
12+
- run: bazelisk test //Tests/... --test_output=errors

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
/*.xcodeproj/
44
/DerivedData/
55
/.swiftpm/
6+
bazel-*

BUILD

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
2+
3+
cc_library(
4+
name = "CIndexStore",
5+
hdrs = ["Sources/CIndexStore/include/indexstore.h"],
6+
linkstatic = True,
7+
tags = ["swift_module=CIndexStore"],
8+
)
9+
10+
swift_library(
11+
name = "IndexStore",
12+
srcs = glob(["Sources/IndexStore/*.swift"]),
13+
linkopts = select({
14+
"@platforms//os:linux": ["-lIndexStore"],
15+
"//conditions:default": [],
16+
}),
17+
visibility = [
18+
"//visibility:public",
19+
],
20+
deps = [
21+
":CIndexStore",
22+
] + select({
23+
"@platforms//os:linux": [],
24+
"//conditions:default": [
25+
"@StaticIndexStore//:libIndexStore",
26+
],
27+
}),
28+
)
29+
30+
swift_library(
31+
name = "SwiftDemangle",
32+
srcs = glob(["Sources/SwiftDemangle/*.swift"]),
33+
module_name = "SwiftDemangle",
34+
visibility = [
35+
"//visibility:public",
36+
],
37+
deps = [
38+
"//Sources/CSwiftDemangle",
39+
],
40+
)

Sources/CSwiftDemangle/BUILD

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
cc_library(
2+
name = "CSwiftDemangle",
3+
srcs = glob([
4+
"PrivateHeaders/**/*.h",
5+
]) + [
6+
"CSwiftDemangle.cpp",
7+
],
8+
hdrs = glob([
9+
"include/**/*.h",
10+
]),
11+
includes = [
12+
"PrivateHeaders/include",
13+
"include",
14+
],
15+
linkopts = [
16+
"-lswiftDemangle",
17+
],
18+
tags = ["swift_module=CSwiftDemangle"],
19+
textual_hdrs = glob([
20+
"**/*.def",
21+
]),
22+
visibility = [
23+
"//:__pkg__",
24+
],
25+
)

Sources/indexutil-annotate/BUILD

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_binary")
2+
3+
swift_binary(
4+
name = "indexutil-annotate",
5+
srcs = [
6+
"Annotation.swift",
7+
"main.swift",
8+
],
9+
deps = [
10+
"//:IndexStore",
11+
],
12+
)

Sources/indexutil-export/BUILD

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_binary")
2+
3+
swift_binary(
4+
name = "indexutil-export",
5+
srcs = [
6+
"TSVWriter.swift",
7+
"main.swift",
8+
],
9+
deps = [
10+
"//:IndexStore",
11+
],
12+
)

Sources/tycat/BUILD

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_binary")
2+
3+
swift_binary(
4+
name = "tycat",
5+
srcs = [
6+
"TypeGraph.swift",
7+
"Xcode.swift",
8+
"main.swift",
9+
],
10+
deps = [
11+
"//:IndexStore",
12+
],
13+
)

Sources/unnecessary-testable/BUILD

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_binary")
2+
3+
swift_binary(
4+
name = "unnecessary-testable",
5+
srcs = [
6+
"main.swift",
7+
],
8+
deps = [
9+
"//:IndexStore",
10+
],
11+
)

Tests/IndexStoreTests/BUILD

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_test")
2+
3+
swift_test(
4+
name = "IndexStoreTests",
5+
srcs = [
6+
"DetermineIndexStorePath.swift",
7+
"IndexStoreTests.swift",
8+
],
9+
data = glob([
10+
"Data/**",
11+
]),
12+
deps = [
13+
"//:IndexStore",
14+
],
15+
)
Binary file not shown.
Binary file not shown.

Tests/IndexStoreTests/DetermineIndexStorePath.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import Foundation
99
///
1010
/// - Returns: Index store path for the current test environment
1111
func determineIndexStorePath() -> String {
12+
if let testSrcDir: String = ProcessInfo.processInfo.environment["TEST_SRCDIR"] {
13+
return testSrcDir + "/__main__/Tests/IndexStoreTests/Data/main.indexstore"
14+
}
1215
guard let service = ProcessInfo.processInfo.environment["XPC_SERVICE_NAME"] else {
1316
preconditionFailure("Expected XPC_SERVICE_NAME environment variable")
1417
}

Tests/SwiftDemangleTests/BUILD

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_test")
2+
3+
swift_test(
4+
name = "SwiftDemangleTests",
5+
srcs = [
6+
"SwiftDemangleTests.swift",
7+
],
8+
deps = [
9+
"//:SwiftDemangle",
10+
],
11+
)

WORKSPACE

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
load(
2+
":repositories.bzl",
3+
"swift_index_store_dependencies",
4+
)
5+
6+
swift_index_store_dependencies()
7+
8+
load(
9+
"@build_bazel_rules_apple//apple:repositories.bzl",
10+
"apple_rules_dependencies",
11+
)
12+
13+
apple_rules_dependencies()
14+
15+
load(
16+
"@build_bazel_rules_swift//swift:repositories.bzl",
17+
"swift_rules_dependencies",
18+
)
19+
20+
swift_rules_dependencies()
21+
22+
load(
23+
"@build_bazel_rules_swift//swift:extras.bzl",
24+
"swift_rules_extra_dependencies",
25+
)
26+
27+
swift_rules_extra_dependencies()
28+
29+
load(
30+
"@build_bazel_apple_support//lib:repositories.bzl",
31+
"apple_support_dependencies",
32+
)
33+
34+
apple_support_dependencies()

repositories.bzl

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
"""Definitions for handling Bazel repositories used by the swift-index-store."""
2+
3+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
4+
5+
def _maybe(repo_rule, name, **kwargs):
6+
"""
7+
Executes the given repository rule if it hasn't been executed already.
8+
9+
Args:
10+
repo_rule: The repository rule to be executed (e.g., `http_archive`.)
11+
name: The name of the repository to be defined by the rule.
12+
**kwargs: Additional arguments passed directly to the repository rule.
13+
"""
14+
if not native.existing_rule(name):
15+
repo_rule(name = name, **kwargs)
16+
17+
def swift_index_store_dependencies():
18+
build_bazel_rules_swift_sha = "40c36c936c9c80b4aefa3f008ecf99dbe002be2c"
19+
_maybe(
20+
http_archive,
21+
name = "build_bazel_rules_swift",
22+
sha256 = "dd08813524deb0b449b0bcbde193caa284f45dd8fd624f9ed4ef1fcbfa78b8a8",
23+
url = "https://github.com/bazelbuild/rules_swift/archive/%s.zip" % build_bazel_rules_swift_sha,
24+
strip_prefix = "rules_swift-%s" % build_bazel_rules_swift_sha,
25+
)
26+
27+
build_bazel_rules_apple_sha = "5f036277bd2e1e357fd8502bf0ade9d293cf91b3"
28+
_maybe(
29+
http_archive,
30+
name = "build_bazel_rules_apple",
31+
sha256 = "635de45a7c07daed728962a9be983503221da22b6c6759e2f67f283cbb6cbe37",
32+
url = "https://github.com/bazelbuild/rules_apple/archive/%s.zip" % build_bazel_rules_apple_sha,
33+
strip_prefix = "rules_apple-%s" % build_bazel_rules_apple_sha,
34+
)
35+
36+
_maybe(
37+
http_archive,
38+
name = "StaticIndexStore",
39+
url = "https://github.com/keith/StaticIndexStore/releases/download/5.7/libIndexStore.xcframework.zip",
40+
sha256 = "da69bab932357a817aa0756e400be86d7156040bfbea8eded7a3acc529320731",
41+
build_file_content = """
42+
load(
43+
"@build_bazel_rules_apple//apple:apple.bzl",
44+
"apple_static_xcframework_import",
45+
)
46+
47+
apple_static_xcframework_import(
48+
name = "libIndexStore",
49+
visibility = [
50+
"//visibility:public",
51+
],
52+
xcframework_imports = glob(["libIndexStore.xcframework/**"]),
53+
)
54+
""",
55+
)

0 commit comments

Comments
 (0)