Skip to content

Commit

Permalink
Bazel: make codeql compatible with workspace setup
Browse files Browse the repository at this point in the history
  • Loading branch information
redsun82 committed Feb 22, 2024
1 parent b1e0287 commit b7df26e
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 10 deletions.
45 changes: 45 additions & 0 deletions misc/bazel/workspace.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load("//swift/third_party:load.bzl", load_swift_dependencies = "load_dependencies")

def codeql_workspace(repository_name = "codeql"):
load_swift_dependencies(repository_name = repository_name)
maybe(
repo_rule = http_archive,
name = "rules_pkg",
sha256 = "8f9ee2dc10c1ae514ee599a8b42ed99fa262b757058f65ad3c384289ff70c4b8",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.9.1/rules_pkg-0.9.1.tar.gz",
"https://github.com/bazelbuild/rules_pkg/releases/download/0.9.1/rules_pkg-0.9.1.tar.gz",
],
)

maybe(
repo_rule = http_archive,
name = "platforms",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/platforms/releases/download/0.0.8/platforms-0.0.8.tar.gz",
"https://github.com/bazelbuild/platforms/releases/download/0.0.8/platforms-0.0.8.tar.gz",
],
sha256 = "8150406605389ececb6da07cbcb509d5637a3ab9a24bc69b1101531367d89d74",
)

maybe(
repo_rule = http_archive,
name = "rules_python",
sha256 = "cdf6b84084aad8f10bf20b46b77cb48d83c319ebe6458a18e9d2cebf57807cdd",
strip_prefix = "rules_python-0.8.1",
urls = [
"https://github.com/bazelbuild/rules_python/archive/refs/tags/0.8.1.tar.gz",
],
)

maybe(
repo_rule = http_archive,
name = "bazel_skylib",
sha256 = "b8a1527901774180afc798aeb28c4634bdccf19c4d98e7bdd1ce79d1fe9aaad7",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.4.1/bazel-skylib-1.4.1.tar.gz",
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.4.1/bazel-skylib-1.4.1.tar.gz",
],
)
11 changes: 11 additions & 0 deletions misc/bazel/workspace_deps.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")
load("@rules_python//python:pip.bzl", "pip_install")
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

def codeql_workspace_deps(repository_name = "codeql"):
pip_install(
name = "codegen_deps",
requirements = "@%s//misc/codegen:requirements_lock.txt" % repository_name,
)
bazel_skylib_workspace()
rules_pkg_dependencies()
45 changes: 35 additions & 10 deletions swift/third_party/load.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def _get_toolchain_url(info):
info.extension,
)

def _toolchains():
def _toolchains(repository_name):
rules = {
"tar.gz": http_archive,
"pkg": _pkg_archive,
Expand All @@ -51,7 +51,7 @@ def _toolchains():
name = "swift_toolchain_%s" % arch,
url = _get_toolchain_url(info),
sha256 = info.sha,
build_file = _build % ("swift-toolchain-%s" % arch),
build_file = _build(repository_name, "swift-toolchain-%s" % arch),
strip_prefix = "%s-%s" % (_swift_version, info.suffix),
)

Expand Down Expand Up @@ -109,9 +109,10 @@ def _github_archive(*, name, repository, commit, build_file = None, sha256 = Non
sha256 = sha256,
)

_build = "@codeql//swift/third_party:BUILD.%s.bazel"
def _build(repository_name, package):
return "@%s//swift/third_party:BUILD.%s.bazel" % (repository_name, package)

def _load_dependencies(_):
def load_dependencies(module_ctx = None, repository_name = "codeql"):
for repo_arch, arch in _swift_arch_map.items():
sha256 = _swift_sha_map[repo_arch]

Expand All @@ -121,34 +122,58 @@ def _load_dependencies(_):
_swift_prebuilt_version,
repo_arch,
),
build_file = _build % "swift-llvm-support",
build_file = _build(repository_name, "swift-llvm-support"),
sha256 = sha256,
patch_args = ["-p1"],
patches = [
"@codeql//swift/third_party/swift-llvm-support:patches/%s.patch" % patch_name
"@%s//swift/third_party/swift-llvm-support:patches/%s.patch" % (repository_name, patch_name)
for patch_name in (
"remove-redundant-operators",
"add-constructor-to-Compilation",
)
],
)

_toolchains()
_toolchains(repository_name)

_github_archive(
name = "picosha2",
build_file = _build % "picosha2",
build_file = _build(repository_name, "picosha2"),
repository = "okdshin/PicoSHA2",
commit = "27fcf6979298949e8a462e16d09a0351c18fcaf2",
sha256 = "d6647ca45a8b7bdaf027ecb68d041b22a899a0218b7206dee755c558a2725abb",
)

_github_archive(
name = "binlog",
build_file = _build % "binlog",
build_file = _build(repository_name, "binlog"),
repository = "morganstanley/binlog",
commit = "3fef8846f5ef98e64211e7982c2ead67e0b185a6",
sha256 = "f5c61d90a6eff341bf91771f2f465be391fd85397023e1b391c17214f9cbd045",
)

swift_deps = module_extension(_load_dependencies)
if module_ctx == None:
# legacy workspace loading, remove when transition is complete
_github_archive(
name = "absl",
repository = "abseil/abseil-cpp",
commit = "d2c5297a3c3948de765100cb7e5cccca1210d23c",
sha256 = "735a9efc673f30b3212bfd57f38d5deb152b543e35cd58b412d1363b15242049",
)

_github_archive(
name = "json",
repository = "nlohmann/json",
commit = "6af826d0bdb55e4b69e3ad817576745335f243ca",
sha256 = "702bb0231a5e21c0374230fed86c8ae3d07ee50f34ffd420e7f8249854b7d85b",
)

_github_archive(
name = "fmt",
repository = "fmtlib/fmt",
build_file = _build(repository_name, "fmt"),
commit = "a0b8a92e3d1532361c2f7feb63babc5c18d00ef2",
sha256 = "ccf872fd4aa9ab3d030d62cffcb258ca27f021b2023a0244b2cf476f984be955",
)

swift_deps = module_extension(load_dependencies)

0 comments on commit b7df26e

Please sign in to comment.