From 19bb8fe22dcb9d41bc5421e38e7d810bf132657b Mon Sep 17 00:00:00 2001 From: Paolo Tranquilli Date: Mon, 12 Feb 2024 10:50:05 +0100 Subject: [PATCH] Bazel: use bzlmod --- .bazelrc | 2 +- MODULE.bazel | 33 ++++++++++++++ WORKSPACE.bazel | 8 ---- misc/bazel/workspace.bzl | 45 ------------------- misc/bazel/workspace_deps.bzl | 11 ----- .../{requirements.txt => requirements_in.txt} | 0 misc/codegen/requirements_lock.txt | 22 +++++++++ .../remapping/SwiftFileInterception.cpp | 1 + swift/third_party/load.bzl | 41 +++++------------ 9 files changed, 67 insertions(+), 96 deletions(-) create mode 100644 MODULE.bazel delete mode 100644 misc/bazel/workspace.bzl delete mode 100644 misc/bazel/workspace_deps.bzl rename misc/codegen/{requirements.txt => requirements_in.txt} (100%) create mode 100644 misc/codegen/requirements_lock.txt diff --git a/.bazelrc b/.bazelrc index 214258e775a..dcb73e90697 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1,4 +1,4 @@ -common --enable_platform_specific_config +common --enable_platform_specific_config --experimental_enable_bzlmod build --repo_env=CC=clang --repo_env=CXX=clang++ diff --git a/MODULE.bazel b/MODULE.bazel new file mode 100644 index 00000000000..e6ec421acbf --- /dev/null +++ b/MODULE.bazel @@ -0,0 +1,33 @@ +module( + name = "codeql", + version = "0.0", +) + +# see https://registry.bazel.build/ for a list of available packages + +bazel_dep(name = "platforms", version = "0.0.8") +bazel_dep(name = "rules_pkg", version = "0.9.1") +bazel_dep(name = "rules_python", version = "0.29.0") +bazel_dep(name = "bazel_skylib", version = "1.5.0") +bazel_dep(name = "abseil-cpp", version = "20240116.0", repo_name = "absl") +bazel_dep(name = "nlohmann_json", version = "3.11.3", repo_name = "json") +bazel_dep(name = "fmt", version = "10.0.0") + +pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip") +pip.parse( + hub_name = "codegen_deps", + python_version = "3.11", + requirements_lock = "//misc/codegen:requirements_lock.txt", +) +use_repo(pip, "codegen_deps") + +swift_deps = use_extension("//swift/third_party:load.bzl", "swift_deps") +use_repo( + swift_deps, + "binlog", + "picosha2", + "swift_prebuilt_darwin_x86_64", + "swift_prebuilt_linux", + "swift_toolchain_linux", + "swift_toolchain_macos", +) diff --git a/WORKSPACE.bazel b/WORKSPACE.bazel index 42b7f54c24c..12e40472055 100644 --- a/WORKSPACE.bazel +++ b/WORKSPACE.bazel @@ -2,11 +2,3 @@ # and for internal use only. workspace(name = "codeql") - -load("//misc/bazel:workspace.bzl", "codeql_workspace") - -codeql_workspace() - -load("//misc/bazel:workspace_deps.bzl", "codeql_workspace_deps") - -codeql_workspace_deps() diff --git a/misc/bazel/workspace.bzl b/misc/bazel/workspace.bzl deleted file mode 100644 index 428ca93fa2c..00000000000 --- a/misc/bazel/workspace.bzl +++ /dev/null @@ -1,45 +0,0 @@ -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) - 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", - ], - ) diff --git a/misc/bazel/workspace_deps.bzl b/misc/bazel/workspace_deps.bzl deleted file mode 100644 index ce91ee3959d..00000000000 --- a/misc/bazel/workspace_deps.bzl +++ /dev/null @@ -1,11 +0,0 @@ -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.txt" % repository_name, - ) - bazel_skylib_workspace() - rules_pkg_dependencies() diff --git a/misc/codegen/requirements.txt b/misc/codegen/requirements_in.txt similarity index 100% rename from misc/codegen/requirements.txt rename to misc/codegen/requirements_in.txt diff --git a/misc/codegen/requirements_lock.txt b/misc/codegen/requirements_lock.txt new file mode 100644 index 00000000000..f0ae5d82ba7 --- /dev/null +++ b/misc/codegen/requirements_lock.txt @@ -0,0 +1,22 @@ +# +# This file is autogenerated by pip-compile with Python 3.11 +# by the following command: +# +# pip-compile --output-file=misc/codegen/requirements_lock.txt misc/codegen/requirements_in.txt +# +inflection==0.5.1 + # via -r misc/codegen/requirements_in.txt +iniconfig==2.0.0 + # via pytest +packaging==23.2 + # via pytest +pluggy==1.4.0 + # via pytest +pystache==0.6.5 + # via -r misc/codegen/requirements_in.txt +pytest==8.0.0 + # via -r misc/codegen/requirements_in.txt +pyyaml==6.0.1 + # via -r misc/codegen/requirements_in.txt +toposort==1.10 + # via -r misc/codegen/requirements_in.txt diff --git a/swift/extractor/remapping/SwiftFileInterception.cpp b/swift/extractor/remapping/SwiftFileInterception.cpp index c83049bcbcc..168132941ad 100644 --- a/swift/extractor/remapping/SwiftFileInterception.cpp +++ b/swift/extractor/remapping/SwiftFileInterception.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include diff --git a/swift/third_party/load.bzl b/swift/third_party/load.bzl index 6e2eb6075fe..b32262e2b9f 100644 --- a/swift/third_party/load.bzl +++ b/swift/third_party/load.bzl @@ -40,7 +40,7 @@ def _get_toolchain_url(info): info.extension, ) -def _toolchains(workspace_name): +def _toolchains(): rules = { "tar.gz": http_archive, "pkg": _pkg_archive, @@ -51,7 +51,7 @@ def _toolchains(workspace_name): name = "swift_toolchain_%s" % arch, url = _get_toolchain_url(info), sha256 = info.sha, - build_file = _build(workspace_name, "swift-toolchain-%s" % arch), + build_file = _build % ("swift-toolchain-%s" % arch), strip_prefix = "%s-%s" % (_swift_version, info.suffix), ) @@ -109,10 +109,9 @@ def _github_archive(*, name, repository, commit, build_file = None, sha256 = Non sha256 = sha256, ) -def _build(workspace_name, package): - return "@%s//swift/third_party:BUILD.%s.bazel" % (workspace_name, package) +_build = "@codeql//swift/third_party:BUILD.%s.bazel" -def load_dependencies(workspace_name): +def _load_dependencies(_): for repo_arch, arch in _swift_arch_map.items(): sha256 = _swift_sha_map[repo_arch] @@ -122,11 +121,11 @@ def load_dependencies(workspace_name): _swift_prebuilt_version, repo_arch, ), - build_file = _build(workspace_name, "swift-llvm-support"), + build_file = _build % "swift-llvm-support", sha256 = sha256, patch_args = ["-p1"], patches = [ - "@%s//swift/third_party/swift-llvm-support:patches/%s.patch" % (workspace_name, patch_name) + "@codeql//swift/third_party/swift-llvm-support:patches/%s.patch" % patch_name for patch_name in ( "remove-redundant-operators", "add-constructor-to-Compilation", @@ -134,11 +133,11 @@ def load_dependencies(workspace_name): ], ) - _toolchains(workspace_name) + _toolchains() _github_archive( name = "picosha2", - build_file = _build(workspace_name, "picosha2"), + build_file = _build % "picosha2", repository = "okdshin/PicoSHA2", commit = "27fcf6979298949e8a462e16d09a0351c18fcaf2", sha256 = "d6647ca45a8b7bdaf027ecb68d041b22a899a0218b7206dee755c558a2725abb", @@ -146,30 +145,10 @@ def load_dependencies(workspace_name): _github_archive( name = "binlog", - build_file = _build(workspace_name, "binlog"), + build_file = _build % "binlog", repository = "morganstanley/binlog", commit = "3fef8846f5ef98e64211e7982c2ead67e0b185a6", sha256 = "f5c61d90a6eff341bf91771f2f465be391fd85397023e1b391c17214f9cbd045", ) - _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(workspace_name, "fmt"), - commit = "a0b8a92e3d1532361c2f7feb63babc5c18d00ef2", - sha256 = "ccf872fd4aa9ab3d030d62cffcb258ca27f021b2023a0244b2cf476f984be955", - ) +swift_deps = module_extension(_load_dependencies)