Skip to content

Commit

Permalink
Start adapting to bzlmod configurations. (carbon-language#3505)
Browse files Browse the repository at this point in the history
Some background information is at https://bazel.build/external/migration

Trying to handle the simple cases first. This adds a requirement for
bazel 7 due to differences in bzlmod handling between 6 and 7 (also
discussed on
[#infra](https://discord.com/channels/655572317891461132/707150492370862090/1184942191412510720)).
Bazel seems to be okay with a partial migration such as ths.

The python import behavior has subtly shifted, so `carbon.` is no longer
part of import paths. There's a version-incompatible change for `@@`.
bzlmod makes repos sometimes show as `name~version`.

`target-determinator` seems to be okay with `@@` after a version update.

Things not moved here are things that basically need more dep work:

- clang_register_toolchains because I need to dive into its format.
- llvm-project because we need something slightly atypical, I need to
make sure patching and the repo work carries over.
- com_google_libprotobuf_mutator is sufficiently atypical that it
doesn't have a module already, but should be one of the easier things to
fix.
- brotli/woff2: I think we should actually consider removing these. But
again, they're not trivial moves.
- treesitter due to toolchain registration, which has shifted a bit.
- rules_nodejs because treesitter depends on it in an awkward way to
migrate.
  • Loading branch information
jonmeow committed Dec 15, 2023
1 parent 0a1abe9 commit 6204a27
Show file tree
Hide file tree
Showing 12 changed files with 3,221 additions and 233 deletions.
2 changes: 1 addition & 1 deletion .bazeliskrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

# Keep pinned to a recent release, listed at
# https://github.com/bazelbuild/bazel.
USE_BAZEL_VERSION=6.0.0
USE_BAZEL_VERSION=7.0.0
23 changes: 0 additions & 23 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
# Exceptions. See /LICENSE for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

# TODO: https://bazel.build/external/migration for
# https://github.com/bazelbuild/bazel/issues/18958
build --noenable_bzlmod

# Default to using a disk cache to minimize re-building LLVM and Clang which we
# try to avoid updating too frequently to minimize rebuild cost. The location
# here can be overridden in the user configuration where needed.
Expand All @@ -19,25 +15,6 @@ build --disk_cache=~/.cache/carbon-lang-build-cache
# future Bazel releases.
build --experimental_guard_against_concurrent_changes

# Allow the toolchain to configure itself differently in the host build from
# the target build. Even when the host and target platforms are ostensibly the
# same (and use identical toolchains), it is beneficial to be able to configure
# the specific toolchain features enabled for the target separately from the
# host. For example, sanitizers make sense for the target significantly more
# than for the host.
#
# Bazel bug tracking undoing the default here:
# https://github.com/bazelbuild/bazel/issues/13315
#
# TODO: Remove this once we require at least Bazel version 7, where
# --incompatible_use_host_features is the default.
build --incompatible_dont_enable_host_nonhost_crosstool_features=false

# Opt into the new Bazel toolchain resolution mechanism.
# TODO: Remove this once we require at least Bazel version 7, where it is the
# default.
build --incompatible_enable_cc_toolchain_resolution

# Disable warnings for all external compilations. These involve code that isn't
# developed as part of Carbon and may be difficult or impossible to patch, so
# warnings aren't likely to be actionable.
Expand Down
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ repos:
# This excludes third-party code, and patches to third-party code.
exclude: |
(?x)^(
MODULE.bazel.lock|
bazel/patches/.*\.patch|
third_party/examples/.*/carbon/.*|
third_party/llvm-project/.*|
Expand Down
64 changes: 64 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# 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

"""Bazel modules."""

module(name = "carbon")

bazel_dep(name = "bazel_skylib", version = "1.5.0")
bazel_dep(
name = "abseil-cpp",
version = "20230802.0",
repo_name = "com_google_absl",
)
bazel_dep(
name = "re2",
version = "2023-11-01",
repo_name = "com_googlesource_code_re2",
)
bazel_dep(
name = "googletest",
version = "1.14.0.bcr.1",
repo_name = "com_google_googletest",
)
bazel_dep(
name = "google_benchmark",
version = "1.8.3",
repo_name = "com_github_google_benchmark",
)
bazel_dep(name = "rules_bison", version = "0.2.2")
bazel_dep(name = "rules_flex", version = "0.2.1")
bazel_dep(name = "rules_m4", version = "0.2.3")
bazel_dep(name = "rules_cc", version = "0.0.9")
bazel_dep(name = "rules_proto", version = "6.0.0-rc1")
bazel_dep(
name = "protobuf",
version = "21.7",
repo_name = "com_google_protobuf",
)

###############################################################################
# Python
###############################################################################

bazel_dep(name = "rules_python", version = "0.27.1")

python = use_extension("@rules_python//python/extensions:python.bzl", "python")
python.toolchain(
python_version = "3.11",
)
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.parse(
hub_name = "py_deps",
python_version = "3.11",
requirements_lock = "//github_tools:requirements.txt",
)
use_repo(pip, "py_deps")

0 comments on commit 6204a27

Please sign in to comment.