Skip to content

Commit df2cc18

Browse files
authored
Merge pull request #8726 from redsun82/swift-prebuilt-fetching
Swift: fetch prebuilt swift and link against it
2 parents 058ac5b + aaf9e7d commit df2cc18

File tree

4 files changed

+67
-2
lines changed

4 files changed

+67
-2
lines changed

misc/bazel/workspace.bzl

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,31 @@
11
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
22
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
33

4-
def codeql_workspace():
4+
_swift_prebuilt_version = "swift-5.6-RELEASE.42271.54"
5+
_swift_sha_map = {
6+
"linux": "92b26fbbc45f812b0581385cc81470ab636fed9cff460052aa2173de765ddef4",
7+
"macos-x86_64": "b24f609c7868c1709e1e552e3b394664014e6a7f1e097522db80deb359bbcd2f",
8+
}
9+
10+
_swift_arch_map = {
11+
"linux": "linux",
12+
"macos-x86_64": "darwin_x86_64",
13+
}
14+
15+
def codeql_workspace(repository_name = "codeql"):
16+
for repo_arch, arch in _swift_arch_map.items():
17+
sha256 = _swift_sha_map[repo_arch]
18+
19+
http_archive(
20+
name = "swift_prebuilt_%s" % arch,
21+
url = "https://github.com/dsp-testing/codeql-swift-artifacts/releases/download/%s/swift-prebuilt-%s.zip" % (
22+
_swift_prebuilt_version,
23+
repo_arch,
24+
),
25+
build_file = "@%s//swift/extractor:BUILD.swift-prebuilt.bazel" % repository_name,
26+
sha256 = sha256,
27+
)
28+
529
maybe(
630
repo_rule = http_archive,
731
name = "rules_pkg",

swift/extractor/BUILD.bazel

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
alias(
2+
name = "swift-llvm-support",
3+
actual = select({
4+
"@bazel_tools//src/conditions:%s" % arch: "@swift_prebuilt_%s//:swift-llvm-support" % arch
5+
for arch in ("linux", "darwin_x86_64", "darwin_arm64")
6+
}),
7+
)
8+
19
cc_binary(
210
name = "extractor",
311
srcs = ["main.cpp"],
@@ -7,4 +15,6 @@ cc_binary(
715
"//conditions:default": ["@platforms//:incompatible"],
816
}),
917
visibility = ["//swift:__pkg__"],
18+
deps = [":swift-llvm-support"],
19+
features = ["-universal_binaries"],
1020
)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
cc_library(
2+
name = "swift-llvm-support",
3+
srcs = [
4+
"libCodeQLSwiftFrontendTool.a",
5+
] + select({
6+
"@platforms//os:linux": [
7+
"libCodeQLSwiftFrontendTool.so",
8+
],
9+
"@platforms//os:macos": [
10+
"libCodeQLSwiftFrontendTool.dylib",
11+
],
12+
}),
13+
hdrs = glob(["include/**/*"]),
14+
linkopts = [
15+
"-lm",
16+
"-lz",
17+
] + select({
18+
"@platforms//os:linux": [
19+
"-luuid",
20+
"-lrt",
21+
"-lpthread",
22+
"-ldl",
23+
],
24+
"//conditions:default": [],
25+
}),
26+
strip_include_prefix = "include",
27+
visibility = ["//visibility:public"],
28+
)

swift/extractor/main.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
#include <iomanip>
33
#include <stdlib.h>
44

5-
int main() {
5+
#include <swift/Basic/LLVMInitialize.h>
6+
7+
int main(int argc, char** argv) {
8+
PROGRAM_START(argc, argv);
69
if (auto trapDir = getenv("CODEQL_EXTRACTOR_SWIFT_TRAP_DIR")) {
710
std::string file = trapDir;
811
file += "/my_first.trap";

0 commit comments

Comments
 (0)