diff --git a/utils/bazel/WORKSPACE b/utils/bazel/WORKSPACE --- a/utils/bazel/WORKSPACE +++ b/utils/bazel/WORKSPACE @@ -2,133 +2,31 @@ # See https://llvm.org/LICENSE.txt for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") -load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") -load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository", "new_git_repository") - -SKYLIB_VERSION = "1.3.0" - -http_archive( - name = "bazel_skylib", - sha256 = "74d544d96f4a5bb630d465ca8bbcfe231e3594e5aae57e1edbf17a6eb3ca2506", - urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/{version}/bazel-skylib-{version}.tar.gz".format(version=SKYLIB_VERSION), - "https://github.com/bazelbuild/bazel-skylib/releases/download/{version}/bazel-skylib-{version}.tar.gz".format(version=SKYLIB_VERSION), - ], -) - new_local_repository( name = "llvm-raw", build_file_content = "# empty", path = "../../", ) -load("@llvm-raw//utils/bazel:configure.bzl", "llvm_configure") - -llvm_configure(name = "llvm-project") - -load("@llvm-raw//utils/bazel:terminfo.bzl", "llvm_terminfo_from_env") - -maybe( - llvm_terminfo_from_env, - name = "llvm_terminfo", -) - -maybe( - http_archive, - name = "zlib", - build_file = "@llvm-raw//utils/bazel/third_party_build:zlib.BUILD", - sha256 = "91844808532e5ce316b3c010929493c0244f3d37593afd6de04f71821d5136d9", - strip_prefix = "zlib-1.2.12", - urls = [ - "https://storage.googleapis.com/mirror.tensorflow.org/zlib.net/zlib-1.2.12.tar.gz", - "https://zlib.net/zlib-1.2.12.tar.gz", - ], -) - -load("@llvm-raw//utils/bazel:zlib.bzl", "llvm_zlib_from_env") - -maybe( - llvm_zlib_from_env, - name = "llvm_zlib", - external_zlib = "@zlib", -) - -maybe( - http_archive, - name = "vulkan_headers", - build_file = "@llvm-raw//utils/bazel/third_party_build:vulkan_headers.BUILD", - sha256 = "19f491784ef0bc73caff877d11c96a48b946b5a1c805079d9006e3fbaa5c1895", - strip_prefix = "Vulkan-Headers-9bd3f561bcee3f01d22912de10bb07ce4e23d378", - urls = [ - "https://github.com/KhronosGroup/Vulkan-Headers/archive/9bd3f561bcee3f01d22912de10bb07ce4e23d378.tar.gz", - ], -) - -load("@llvm-raw//utils/bazel:vulkan_sdk.bzl", "vulkan_sdk_setup") - -maybe( - vulkan_sdk_setup, - name = "vulkan_sdk", -) - -# llvm libc math tests reply on `mpfr`. -# The availability of `mpfr` is controlled by a flag and can be either `disable`, `system` or `external`. -# Continuous integration uses `system` to speed up the build process (see .bazelrc). -# Otherwise by default it is set to `external`: `mpfr` and `gmp` are built from source by using `rules_foreign_cc`. -# Note: that building from source requires `m4` to be installed on the host machine. -# This is a known issue: https://github.com/bazelbuild/rules_foreign_cc/issues/755. +# Try to avoid adding anything to this file. In order to support bzlmod, we +# split our dependencies based on whether they exist in the BCR. +# https://github.com/bazelbuild/bazel-central-registry/tree/main/modules +# When using bzlmod, we will need to call non_bcr_deps and llvm_repos, but we +# won't need to call bcr_deps, since we can just use the BCR directly. +load("//repos:bcr_deps.bzl", "bcr_deps") -git_repository( - name = "rules_foreign_cc", - remote = "https://github.com/bazelbuild/rules_foreign_cc.git", - tag = "0.9.0", -) +bcr_deps() +# This cannot be placed in the bcr_deps file, because it relies on the +# rules_foreign_cc repo rule already being executed. load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies") rules_foreign_cc_dependencies() -maybe( - http_archive, - name = "gmp", - build_file = "@llvm-raw//utils/bazel/third_party_build:gmp.BUILD", - sha256 = "fd4829912cddd12f84181c3451cc752be224643e87fac497b69edddadc49b4f2", - strip_prefix = "gmp-6.2.1", - urls = [ - "https://gmplib.org/download/gmp/gmp-6.2.1.tar.xz", - "https://ftp.gnu.org/gnu/gmp/gmp-6.2.1.tar.xz", - ], -) +load("//repos:non_bcr_deps.bzl", "non_bcr_deps") -# https://www.mpfr.org/mpfr-current/ -# -# When updating to a newer version, don't use URLs with "mpfr-current" in them. -# Instead, find a stable URL like the one used currently. -maybe( - http_archive, - name = "mpfr", - build_file = "@llvm-raw//utils/bazel/third_party_build:mpfr.BUILD", - sha256 = "9cbed5d0af0d9ed5e9f8dd013e17838eb15e1db9a6ae0d371d55d35f93a782a7", - strip_prefix = "mpfr-4.1.1", - urls = ["https://www.mpfr.org/mpfr-4.1.1/mpfr-4.1.1.tar.gz"], -) +non_bcr_deps() -maybe( - new_git_repository, - name = "pfm", - build_file = "@llvm-raw//utils/bazel/third_party_build:pfm.BUILD", - remote = "https://git.code.sf.net/p/perfmon2/libpfm4", - tag = "v4.12.1", -) +load("//repos:llvm_repos.bzl", "llvm_repos") -maybe( - http_archive, - name = "llvm_zstd", - build_file = "@llvm-raw//utils/bazel/third_party_build:zstd.BUILD", - sha256 = "7c42d56fac126929a6a85dbc73ff1db2411d04f104fae9bdea51305663a83fd0", - strip_prefix = "zstd-1.5.2", - urls = [ - "https://github.com/facebook/zstd/releases/download/v1.5.2/zstd-1.5.2.tar.gz" - ], -) +llvm_repos(name = "llvm-project") diff --git a/utils/bazel/repos/BUILD.bazel b/utils/bazel/repos/BUILD.bazel new file mode 100644 diff --git a/utils/bazel/repos/bcr_deps.bzl b/utils/bazel/repos/bcr_deps.bzl new file mode 100644 --- /dev/null +++ b/utils/bazel/repos/bcr_deps.bzl @@ -0,0 +1,41 @@ +# This file is licensed under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +"""Dependencies that also exist in the bcr +(https://github.com/bazelbuild/bazel-central-registry/tree/main/modules).""" + +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") +load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") + +SKYLIB_VERSION = "1.3.0" + +def bcr_deps(): + http_archive( + name = "bazel_skylib", + sha256 = "74d544d96f4a5bb630d465ca8bbcfe231e3594e5aae57e1edbf17a6eb3ca2506", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/{version}/bazel-skylib-{version}.tar.gz".format(version = SKYLIB_VERSION), + "https://github.com/bazelbuild/bazel-skylib/releases/download/{version}/bazel-skylib-{version}.tar.gz".format(version = SKYLIB_VERSION), + ], + ) + + maybe( + http_archive, + name = "zlib", + build_file = "@llvm-raw//utils/bazel/third_party_build:zlib.BUILD", + sha256 = "91844808532e5ce316b3c010929493c0244f3d37593afd6de04f71821d5136d9", + strip_prefix = "zlib-1.2.12", + urls = [ + "https://storage.googleapis.com/mirror.tensorflow.org/zlib.net/zlib-1.2.12.tar.gz", + "https://zlib.net/zlib-1.2.12.tar.gz", + ], + ) + + git_repository( + name = "rules_foreign_cc", + remote = "https://github.com/bazelbuild/rules_foreign_cc.git", + # Canonical for tag "0.9.0". + commit = "8d540605805fb69e24c6bf5dc885b0403d74746a", + ) diff --git a/utils/bazel/repos/llvm_repos.bzl b/utils/bazel/repos/llvm_repos.bzl new file mode 100644 --- /dev/null +++ b/utils/bazel/repos/llvm_repos.bzl @@ -0,0 +1,30 @@ +# This file is licensed under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +"""Repositories that depend on LLVM content.""" + +load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") +load("@llvm-raw//utils/bazel:configure.bzl", "llvm_configure") +load("@llvm-raw//utils/bazel:terminfo.bzl", "llvm_terminfo_from_env") +load("@llvm-raw//utils/bazel:vulkan_sdk.bzl", "vulkan_sdk_setup") +load("@llvm-raw//utils/bazel:zlib.bzl", "llvm_zlib_from_env") + +def llvm_repos(name): + llvm_configure(name = "llvm-project") + + maybe( + llvm_terminfo_from_env, + name = "llvm_terminfo", + ) + + maybe( + llvm_zlib_from_env, + name = "llvm_zlib", + external_zlib = "@zlib", + ) + + maybe( + vulkan_sdk_setup, + name = "vulkan_sdk", + ) diff --git a/utils/bazel/repos/non_bcr_deps.bzl b/utils/bazel/repos/non_bcr_deps.bzl new file mode 100644 --- /dev/null +++ b/utils/bazel/repos/non_bcr_deps.bzl @@ -0,0 +1,74 @@ +# This file is licensed under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +"""Dependencies that don't exist in the BCR +(https://github.com/bazelbuild/bazel-central-registry/tree/main/modules)""" + +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") +load("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository") + +def non_bcr_deps(): + maybe( + http_archive, + name = "vulkan_headers", + build_file = "@llvm-raw//utils/bazel/third_party_build:vulkan_headers.BUILD", + sha256 = "19f491784ef0bc73caff877d11c96a48b946b5a1c805079d9006e3fbaa5c1895", + strip_prefix = "Vulkan-Headers-9bd3f561bcee3f01d22912de10bb07ce4e23d378", + urls = [ + "https://github.com/KhronosGroup/Vulkan-Headers/archive/9bd3f561bcee3f01d22912de10bb07ce4e23d378.tar.gz", + ], + ) + + # llvm libc math tests reply on `mpfr`. + # The availability of `mpfr` is controlled by a flag and can be either `disable`, `system` or `external`. + # Continuous integration uses `system` to speed up the build process (see .bazelrc). + # Otherwise by default it is set to `external`: `mpfr` and `gmp` are built from source by using `rules_foreign_cc`. + # Note: that building from source requires `m4` to be installed on the host machine. + # This is a known issue: https://github.com/bazelbuild/rules_foreign_cc/issues/755. + + maybe( + http_archive, + name = "gmp", + build_file = "@llvm-raw//utils/bazel/third_party_build:gmp.BUILD", + sha256 = "fd4829912cddd12f84181c3451cc752be224643e87fac497b69edddadc49b4f2", + strip_prefix = "gmp-6.2.1", + urls = [ + "https://gmplib.org/download/gmp/gmp-6.2.1.tar.xz", + "https://ftp.gnu.org/gnu/gmp/gmp-6.2.1.tar.xz", + ], + ) + + # https://www.mpfr.org/mpfr-current/ + # + # When updating to a newer version, don't use URLs with "mpfr-current" in them. + # Instead, find a stable URL like the one used currently. + maybe( + http_archive, + name = "mpfr", + build_file = "@llvm-raw//utils/bazel/third_party_build:mpfr.BUILD", + sha256 = "9cbed5d0af0d9ed5e9f8dd013e17838eb15e1db9a6ae0d371d55d35f93a782a7", + strip_prefix = "mpfr-4.1.1", + urls = ["https://www.mpfr.org/mpfr-4.1.1/mpfr-4.1.1.tar.gz"], + ) + + maybe( + new_git_repository, + name = "pfm", + build_file = "@llvm-raw//utils/bazel/third_party_build:pfm.BUILD", + remote = "https://git.code.sf.net/p/perfmon2/libpfm4", + # Canonical for tag "v4.12.1". + commit = "56f6a05d46b7592ddf81d77f4714dfc9b4c975e5", + ) + + maybe( + http_archive, + name = "llvm_zstd", + build_file = "@llvm-raw//utils/bazel/third_party_build:zstd.BUILD", + sha256 = "7c42d56fac126929a6a85dbc73ff1db2411d04f104fae9bdea51305663a83fd0", + strip_prefix = "zstd-1.5.2", + urls = [ + "https://github.com/facebook/zstd/releases/download/v1.5.2/zstd-1.5.2.tar.gz", + ], + )