mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 21:00:13 +01:00
Move toolchain and llvm WORKSPACE rules to bzlmod (#3514)
Building on #3505, the toolchain and llvm rules require a little more special-casing to get them to work well. This also moves libprotobuffer_mutator, but that one's more minor. The migration encounters more quirks in repo naming as seen by various queries. This changes some of the toolchain work that was recently done for bazel 7 in #3496, dropping a bzl file I'd suggested to add, instead using `:all` for toolchain registration. (somewhat as an improvement, somewhat just to avoid a `load`) Remaining in the WORKSPACE are example code repos and tree sitter rules. Neither of these are part of the main toolchain builds, and so will probably be lower impact if there's a good solution for them.
This commit is contained in:
@@ -220,8 +220,6 @@ repos:
|
||||
exclude: |
|
||||
(?x)^(
|
||||
MODULE.bazel.lock|
|
||||
bazel/patches/.*\.patch|
|
||||
bazel/llvm_project/.*\.patch|
|
||||
third_party/examples/.*/carbon/.*|
|
||||
third_party/llvm-project/.*|
|
||||
third_party/clangd/.*|
|
||||
)$
|
||||
|
||||
+71
-5
@@ -6,6 +6,11 @@
|
||||
|
||||
module(name = "carbon")
|
||||
|
||||
http_archive = use_repo_rule(
|
||||
"@bazel_tools//tools/build_defs/repo:http.bzl",
|
||||
"http_archive",
|
||||
)
|
||||
|
||||
bazel_dep(name = "bazel_skylib", version = "1.5.0")
|
||||
bazel_dep(
|
||||
name = "abseil-cpp",
|
||||
@@ -38,6 +43,71 @@ bazel_dep(
|
||||
repo_name = "com_google_protobuf",
|
||||
)
|
||||
|
||||
libprotobuf_mutator_version = "1.1"
|
||||
|
||||
http_archive(
|
||||
name = "com_google_libprotobuf_mutator",
|
||||
build_file = "@//:third_party/libprotobuf_mutator/BUILD.txt",
|
||||
sha256 = "fd299fd72c5cf664259d9bd43a72cb74dc6a8b9604d107fe2d2e90885aeb7c16",
|
||||
strip_prefix = "libprotobuf-mutator-{0}".format(libprotobuf_mutator_version),
|
||||
urls = ["https://github.com/google/libprotobuf-mutator/archive/v{0}.tar.gz".format(libprotobuf_mutator_version)],
|
||||
)
|
||||
|
||||
bazel_cc_toolchain = use_extension(
|
||||
"//bazel/cc_toolchains:clang_configuration.bzl",
|
||||
"clang_toolchain_extension",
|
||||
)
|
||||
use_repo(bazel_cc_toolchain, "bazel_cc_toolchain")
|
||||
|
||||
register_toolchains("@bazel_cc_toolchain//:all")
|
||||
|
||||
###############################################################################
|
||||
# llvm-project
|
||||
###############################################################################
|
||||
|
||||
# We pin to specific upstream commits and try to track top-of-tree reasonably
|
||||
# closely rather than pinning to a specific release.
|
||||
llvm_project_version = "3d51010a3350660160981c6b8e624dcc87c208a3"
|
||||
|
||||
# Required for llvm-project.
|
||||
bazel_dep(name = "platforms", version = "0.0.8")
|
||||
|
||||
# zlib and zstd dependencies are copied from
|
||||
# https://github.com/llvm/llvm-project/blob/main/utils/bazel/WORKSPACE.
|
||||
http_archive(
|
||||
name = "llvm_zlib",
|
||||
build_file = "@llvm-raw//utils/bazel/third_party_build:zlib-ng.BUILD",
|
||||
sha256 = "e36bb346c00472a1f9ff2a0a4643e590a254be6379da7cddd9daeb9a7f296731",
|
||||
strip_prefix = "zlib-ng-2.0.7",
|
||||
urls = [
|
||||
"https://github.com/zlib-ng/zlib-ng/archive/refs/tags/2.0.7.zip",
|
||||
],
|
||||
)
|
||||
|
||||
bazel_dep(name = "zstd", version = "1.5.5", repo_name = "llvm_zstd")
|
||||
|
||||
# Load a repository for the raw llvm-project, pre-overlay.
|
||||
http_archive(
|
||||
name = "llvm-raw",
|
||||
build_file_content = "# empty",
|
||||
patch_args = ["-p1"],
|
||||
patches = [
|
||||
"@carbon//bazel/llvm_project:0001_Patch_for_mallinfo2_when_using_Bazel_build_system.patch",
|
||||
"@carbon//bazel/llvm_project:0002_Added_Bazel_build_for_compiler_rt_fuzzer.patch",
|
||||
"@carbon//bazel/llvm_project:0003_Add_library_for_clangd.patch",
|
||||
],
|
||||
sha256 = "efbca707a6eb1c714b849de120309070eef282660c0f4be5b68efef62cc95cf5",
|
||||
strip_prefix = "llvm-project-{0}".format(llvm_project_version),
|
||||
urls = ["https://github.com/llvm/llvm-project/archive/{0}.tar.gz".format(llvm_project_version)],
|
||||
)
|
||||
|
||||
# Apply the overlay to produce llvm-project.
|
||||
llvm_project = use_extension(
|
||||
"//bazel/llvm_project:llvm_project.bzl",
|
||||
"llvm_project",
|
||||
)
|
||||
use_repo(llvm_project, "llvm-project")
|
||||
|
||||
###############################################################################
|
||||
# Python
|
||||
###############################################################################
|
||||
@@ -50,12 +120,8 @@ python.toolchain(
|
||||
)
|
||||
use_repo(python, "python_versions")
|
||||
|
||||
pip = use_extension(
|
||||
"@rules_python//python/extensions:pip.bzl",
|
||||
"pip",
|
||||
)
|
||||
|
||||
# Create a central repo that knows about the pip dependencies.
|
||||
pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
|
||||
pip.parse(
|
||||
hub_name = "py_deps",
|
||||
python_version = "3.11",
|
||||
|
||||
Generated
+1460
-34
File diff suppressed because it is too large
Load Diff
@@ -5,89 +5,6 @@
|
||||
workspace(name = "carbon")
|
||||
|
||||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
|
||||
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
|
||||
|
||||
###############################################################################
|
||||
# C++ rules
|
||||
###############################################################################
|
||||
|
||||
# Configure the bootstrapped Clang and LLVM toolchain for Bazel.
|
||||
load(
|
||||
"//bazel/cc_toolchains:clang_configuration.bzl",
|
||||
"clang_register_toolchains",
|
||||
)
|
||||
|
||||
clang_register_toolchains(name = "bazel_cc_toolchain")
|
||||
|
||||
###############################################################################
|
||||
# LLVM libraries
|
||||
###############################################################################
|
||||
|
||||
# We pin to specific upstream commits and try to track top-of-tree reasonably
|
||||
# closely rather than pinning to a specific release.
|
||||
llvm_version = "3d51010a3350660160981c6b8e624dcc87c208a3"
|
||||
|
||||
http_archive(
|
||||
name = "llvm-raw",
|
||||
build_file_content = "# empty",
|
||||
patch_args = ["-p1"],
|
||||
patches = [
|
||||
"@carbon//bazel/patches/llvm:0001_Patch_for_mallinfo2_when_using_Bazel_build_system.patch",
|
||||
"@carbon//bazel/patches/llvm:0002_Added_Bazel_build_for_compiler_rt_fuzzer.patch",
|
||||
"@carbon//bazel/patches/llvm:0003_Add_library_for_clangd.patch",
|
||||
],
|
||||
sha256 = "efbca707a6eb1c714b849de120309070eef282660c0f4be5b68efef62cc95cf5",
|
||||
strip_prefix = "llvm-project-{0}".format(llvm_version),
|
||||
urls = ["https://github.com/llvm/llvm-project/archive/{0}.tar.gz".format(llvm_version)],
|
||||
)
|
||||
|
||||
load("@llvm-raw//utils/bazel:configure.bzl", "llvm_configure")
|
||||
|
||||
llvm_configure(
|
||||
name = "llvm-project",
|
||||
targets = [
|
||||
"AArch64",
|
||||
"X86",
|
||||
],
|
||||
)
|
||||
|
||||
# Dependencies copied from
|
||||
# https://github.com/llvm/llvm-project/blob/main/utils/bazel/WORKSPACE.
|
||||
maybe(
|
||||
http_archive,
|
||||
name = "llvm_zlib",
|
||||
build_file = "@llvm-raw//utils/bazel/third_party_build:zlib-ng.BUILD",
|
||||
sha256 = "e36bb346c00472a1f9ff2a0a4643e590a254be6379da7cddd9daeb9a7f296731",
|
||||
strip_prefix = "zlib-ng-2.0.7",
|
||||
urls = [
|
||||
"https://github.com/zlib-ng/zlib-ng/archive/refs/tags/2.0.7.zip",
|
||||
],
|
||||
)
|
||||
|
||||
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",
|
||||
],
|
||||
)
|
||||
|
||||
###############################################################################
|
||||
# libprotobuf_mutator - for structured fuzzer testing.
|
||||
###############################################################################
|
||||
|
||||
libprotobuf_mutator_version = "1.1"
|
||||
|
||||
http_archive(
|
||||
name = "com_google_libprotobuf_mutator",
|
||||
build_file = "@//:third_party/libprotobuf_mutator/BUILD.txt",
|
||||
sha256 = "fd299fd72c5cf664259d9bd43a72cb74dc6a8b9604d107fe2d2e90885aeb7c16",
|
||||
strip_prefix = "libprotobuf-mutator-{0}".format(libprotobuf_mutator_version),
|
||||
urls = ["https://github.com/google/libprotobuf-mutator/archive/v{0}.tar.gz".format(libprotobuf_mutator_version)],
|
||||
)
|
||||
|
||||
###############################################################################
|
||||
# Example conversion repositories
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
# Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
||||
# Exceptions. See /LICENSE for license information.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
"""Lists (os, cpu) combinations supported by the Carbon build system."""
|
||||
|
||||
clang_configs = [
|
||||
("linux", "aarch64"),
|
||||
("linux", "x86_64"),
|
||||
("freebsd", "x86_64"),
|
||||
("macos", "arm64"),
|
||||
("macos", "x86_64"),
|
||||
("windows", "x86_64"),
|
||||
]
|
||||
@@ -9,8 +9,6 @@ configured values into a `clang_detected_variables.bzl` file that can be used
|
||||
by the actual toolchain configuration.
|
||||
"""
|
||||
|
||||
load(":clang_configs.bzl", "clang_configs")
|
||||
|
||||
def _run(repository_ctx, cmd):
|
||||
"""Runs the provided `cmd`, checks for failure, and returns the result."""
|
||||
exec_result = repository_ctx.execute(cmd)
|
||||
@@ -170,10 +168,6 @@ def _configure_clang_toolchain_impl(repository_ctx):
|
||||
repository_ctx.attr._clang_cc_toolchain_config,
|
||||
"cc_toolchain_config.bzl",
|
||||
)
|
||||
repository_ctx.symlink(
|
||||
repository_ctx.attr._clang_configs,
|
||||
"clang_configs.bzl",
|
||||
)
|
||||
|
||||
# Find a Clang C++ compiler, and where it lives. We need to walk symlinks
|
||||
# here as the other LLVM tools may not be symlinked into the PATH even if
|
||||
@@ -243,10 +237,6 @@ configure_clang_toolchain = repository_rule(
|
||||
),
|
||||
allow_single_file = True,
|
||||
),
|
||||
"_clang_configs": attr.label(
|
||||
default = Label("//bazel/cc_toolchains:clang_configs.bzl"),
|
||||
allow_single_file = True,
|
||||
),
|
||||
"_clang_detected_variables_template": attr.label(
|
||||
default = Label(
|
||||
"//bazel/cc_toolchains:clang_detected_variables.tpl.bzl",
|
||||
@@ -261,10 +251,6 @@ configure_clang_toolchain = repository_rule(
|
||||
environ = ["CC"],
|
||||
)
|
||||
|
||||
def clang_register_toolchains(name):
|
||||
configure_clang_toolchain(name = name)
|
||||
|
||||
for os, cpu in clang_configs:
|
||||
native.register_toolchains(
|
||||
"@{0}//:bazel_cc_toolchain_{1}_{2}".format(name, os, cpu),
|
||||
)
|
||||
clang_toolchain_extension = module_extension(
|
||||
implementation = lambda ctx: configure_clang_toolchain(name = "bazel_cc_toolchain"),
|
||||
)
|
||||
|
||||
@@ -6,9 +6,15 @@
|
||||
# root `BUILD` file for that repository.
|
||||
|
||||
load(":cc_toolchain_config.bzl", "cc_local_toolchain_suite")
|
||||
load(":clang_configs.bzl", "clang_configs")
|
||||
|
||||
cc_local_toolchain_suite(
|
||||
name = "bazel_cc_toolchain",
|
||||
configs = clang_configs,
|
||||
configs = [
|
||||
("linux", "aarch64"),
|
||||
("linux", "x86_64"),
|
||||
("freebsd", "x86_64"),
|
||||
("macos", "arm64"),
|
||||
("macos", "x86_64"),
|
||||
("windows", "x86_64"),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -29,15 +29,22 @@ try:
|
||||
except FileNotFoundError:
|
||||
sys.exit("ERROR: unable to find deps file: %s" % deps_path)
|
||||
|
||||
# bazel_dep repos can have a `name~version` format, whereas use_repo and
|
||||
# use_repo_rule have a `@@_main~rule_name~repo_name` format. We process the
|
||||
# latter case first because we only have a couple; once done, we can assume
|
||||
# anything after the ~ is a version.
|
||||
for dep in deps:
|
||||
print("Checking dependency: " + dep)
|
||||
repo, _, rule = dep.partition("//")
|
||||
# Ignore the version, just use the repo name.
|
||||
repo = repo.split("~")[0]
|
||||
if repo == "" and not rule.startswith("third_party"):
|
||||
# Carbon code is always allowed.
|
||||
|
||||
# These are stubs wrapping system libraries for LLVM. They aren't
|
||||
# distributed and so should be fine.
|
||||
if repo in (
|
||||
"@@_main~_repo_rules~llvm_zlib",
|
||||
"@@_main~_repo_rules~llvm_zstd",
|
||||
):
|
||||
continue
|
||||
if repo == "@@llvm-project":
|
||||
if repo == "@@_main~llvm_project~llvm-project":
|
||||
package, _, rule = rule.partition(":")
|
||||
|
||||
# Other packages in the LLVM project shouldn't be accidentally used
|
||||
@@ -56,14 +63,16 @@ for dep in deps:
|
||||
|
||||
# The rest of LLVM, LLD, and Clang themselves are safe to depend on.
|
||||
continue
|
||||
|
||||
# Ignore the version, just use the repo name.
|
||||
repo = repo.split("~")[0]
|
||||
if repo == "" and not rule.startswith("third_party"):
|
||||
# Carbon code is always allowed.
|
||||
continue
|
||||
if repo == "@@rules_cc" and rule == ":link_extra_lib":
|
||||
# An empty stub library added by rules_cc:
|
||||
# https://github.com/bazelbuild/rules_cc/blob/main/BUILD
|
||||
continue
|
||||
if repo in ("@llvm_terminfo", "@@llvm_zlib", "@@llvm_zstd"):
|
||||
# These are stubs wrapping system libraries for LLVM. They aren't
|
||||
# distributed and so should be fine.
|
||||
continue
|
||||
if repo in (
|
||||
"@com_github_google_benchmark",
|
||||
"@com_github_protocolbuffers_protobuf",
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
# Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
||||
# Exceptions. See /LICENSE for license information.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
"""Apply llvm_configure to produce a llvm-project repo."""
|
||||
|
||||
load("@llvm-raw//utils/bazel:configure.bzl", "llvm_configure")
|
||||
|
||||
llvm_project = module_extension(
|
||||
implementation = lambda ctx: llvm_configure(
|
||||
name = "llvm-project",
|
||||
targets = [
|
||||
"AArch64",
|
||||
"X86",
|
||||
],
|
||||
),
|
||||
)
|
||||
@@ -1,9 +0,0 @@
|
||||
# Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
||||
# Exceptions. See /LICENSE for license information.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
exports_files(glob([
|
||||
"*.patch",
|
||||
]))
|
||||
@@ -1,9 +0,0 @@
|
||||
# Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
||||
# Exceptions. See /LICENSE for license information.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
exports_files(glob([
|
||||
"*.patch",
|
||||
]))
|
||||
Reference in New Issue
Block a user