|
| 1 | +# This file is licensed under the Apache License v2.0 with LLVM Exceptions. |
| 2 | +# See https://llvm.org/LICENSE.txt for license information. |
| 3 | +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 4 | + |
| 5 | +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") |
| 6 | +load("@bazel_tools//tools/build_defs/repo:local.bzl", "new_local_repository") |
| 7 | +load(":vulkan_sdk.bzl", "vulkan_sdk_setup") |
| 8 | +load(":configure.bzl", "llvm_configure", "DEFAULT_TARGETS") |
| 9 | + |
| 10 | +def _llvm_configure_extension_impl(ctx): |
| 11 | + targets = [] |
| 12 | + |
| 13 | + # Aggregate targets across imports. |
| 14 | + targets.extend([ |
| 15 | + target |
| 16 | + for module in ctx.modules |
| 17 | + for config in module.tags.configure |
| 18 | + for target in config.targets |
| 19 | + if target not in targets |
| 20 | + ]) |
| 21 | + |
| 22 | + # Fall back to the default targets if all configurations of this extension |
| 23 | + # omit the `target` attribute. |
| 24 | + if targets == []: |
| 25 | + targets = DEFAULT_TARGETS |
| 26 | + |
| 27 | + llvm_configure(name = "llvm-project", targets = targets) |
| 28 | + |
| 29 | + # Deliberately omit the "llvm-raw" directory if we're not in the utils/bazel |
| 30 | + # directory. |
| 31 | + # |
| 32 | + # In downstream repos this intentionally causes the extension to immediately |
| 33 | + # error out if "llvm-raw" wasn't injected explicitly. |
| 34 | + # |
| 35 | + # We can't add this repo to the utils/bazel/MODULE.bazel as it would cause |
| 36 | + # submodule imports to resolve the new_local_repository at wrong paths. |
| 37 | + [ |
| 38 | + new_local_repository( |
| 39 | + name = "llvm-raw", |
| 40 | + path = "../..", |
| 41 | + build_file_content = "# Empty." |
| 42 | + ) |
| 43 | + for module in ctx.modules |
| 44 | + if module.name == "llvm-project-overlay" and module.is_root |
| 45 | + ] |
| 46 | + |
| 47 | + print(ctx.path(Label("@llvm-raw//:BUILD.bazel"))) |
| 48 | + |
| 49 | + http_archive( |
| 50 | + name = "vulkan_headers", |
| 51 | + build_file = "@llvm-raw//utils/bazel/third_party_build:vulkan_headers.BUILD", |
| 52 | + sha256 = "19f491784ef0bc73caff877d11c96a48b946b5a1c805079d9006e3fbaa5c1895", |
| 53 | + strip_prefix = "Vulkan-Headers-9bd3f561bcee3f01d22912de10bb07ce4e23d378", |
| 54 | + urls = [ |
| 55 | + "https://github.com/KhronosGroup/Vulkan-Headers/archive/9bd3f561bcee3f01d22912de10bb07ce4e23d378.tar.gz", |
| 56 | + ], |
| 57 | + ) |
| 58 | + |
| 59 | + vulkan_sdk_setup(name = "vulkan_sdk") |
| 60 | + |
| 61 | + http_archive( |
| 62 | + name = "gmp", |
| 63 | + build_file = "@llvm-raw//utils/bazel/third_party_build:gmp.BUILD", |
| 64 | + sha256 = "fd4829912cddd12f84181c3451cc752be224643e87fac497b69edddadc49b4f2", |
| 65 | + strip_prefix = "gmp-6.2.1", |
| 66 | + urls = [ |
| 67 | + "https://gmplib.org/download/gmp/gmp-6.2.1.tar.xz", |
| 68 | + "https://ftp.gnu.org/gnu/gmp/gmp-6.2.1.tar.xz", |
| 69 | + ], |
| 70 | + ) |
| 71 | + |
| 72 | + # https://www.mpfr.org/mpfr-current/ |
| 73 | + # |
| 74 | + # When updating to a newer version, don't use URLs with "mpfr-current" in them. |
| 75 | + # Instead, find a stable URL like the one used currently. |
| 76 | + http_archive( |
| 77 | + name = "mpfr", |
| 78 | + build_file = "@llvm-raw//utils/bazel/third_party_build:mpfr.BUILD", |
| 79 | + sha256 = "9cbed5d0af0d9ed5e9f8dd013e17838eb15e1db9a6ae0d371d55d35f93a782a7", |
| 80 | + strip_prefix = "mpfr-4.1.1", |
| 81 | + urls = ["https://www.mpfr.org/mpfr-4.1.1/mpfr-4.1.1.tar.gz"], |
| 82 | + ) |
| 83 | + |
| 84 | + http_archive( |
| 85 | + name = "pfm", |
| 86 | + build_file = "@llvm-raw//utils/bazel/third_party_build:pfm.BUILD", |
| 87 | + sha256 = "d18b97764c755528c1051d376e33545d0eb60c6ebf85680436813fa5b04cc3d1", |
| 88 | + strip_prefix = "libpfm-4.13.0", |
| 89 | + urls = ["https://versaweb.dl.sourceforge.net/project/perfmon2/libpfm4/libpfm-4.13.0.tar.gz"], |
| 90 | + ) |
| 91 | + |
| 92 | + http_archive( |
| 93 | + name = "pybind11", |
| 94 | + build_file = "@llvm-raw//utils/bazel/third_party_build:pybind.BUILD", |
| 95 | + sha256 = "201966a61dc826f1b1879a24a3317a1ec9214a918c8eb035be2f30c3e9cfbdcb", |
| 96 | + strip_prefix = "pybind11-2.10.3", |
| 97 | + url = "https://github.com/pybind/pybind11/archive/v2.10.3.zip", |
| 98 | + ) |
| 99 | + |
| 100 | + # TODO: Make `NB_BUILD=1` and `NB_SHARED=1` configurable in the BCR variant |
| 101 | + # and import this via `MODULE.bazel`. |
| 102 | + http_archive( |
| 103 | + name = "nanobind", |
| 104 | + build_file = "@llvm-raw//utils/bazel/third_party_build:nanobind.BUILD", |
| 105 | + sha256 = "bb35deaed7efac5029ed1e33880a415638352f757d49207a8e6013fefb6c49a7", |
| 106 | + strip_prefix = "nanobind-2.4.0", |
| 107 | + url = "https://github.com/wjakob/nanobind/archive/refs/tags/v2.4.0.tar.gz", |
| 108 | + ) |
| 109 | + |
| 110 | + |
| 111 | +llvm_project_overlay = module_extension( |
| 112 | + doc = """Configure the llvm-project. |
| 113 | +
|
| 114 | + Tags: |
| 115 | + targets: List of targets which Clang should support. |
| 116 | + """, |
| 117 | + implementation = _llvm_configure_extension_impl, |
| 118 | + tag_classes = { |
| 119 | + "configure": tag_class( |
| 120 | + attrs = { |
| 121 | + "targets": attr.string_list(), |
| 122 | + }, |
| 123 | + ), |
| 124 | + }, |
| 125 | +) |
0 commit comments