Skip to content

Commit

Permalink
First step towards using bzlmod
Browse files Browse the repository at this point in the history
 * Move projects that are available already in https://registry.bazel.build/
   from from load_external to MODULE.bazel.
 * This is not complete: there are probably more steps to simplify and
   clean-up after the first submit.
 * Switching to bzlmod broke making the compilation-db as the action hooks
   don't seem to work anymore ( xls/dev_tools//make-compilation-db.sh ).
   The used com_grail_bazel_compdb is not maintained anymore, so this needs
   to be updated to something more modern (hedronvision?).
   Since this is not actively needed in daily development (and I am the only
   one really using it), postponed for later.
 * Clean out things not needed anymore in dependency_support/$(various-dirs)

Issues: google#931

Also, needed to make Python rules to work well with
--incompatible_default_to_explicit_init_py (bazelbuild/bazel#10076)
  • Loading branch information
hzeller committed Sep 13, 2024
1 parent cfa9a33 commit 54fd925
Show file tree
Hide file tree
Showing 15 changed files with 38 additions and 463 deletions.
8 changes: 6 additions & 2 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# We use bazel >= 6, but no bzlmod yet.
common --noenable_bzlmod
common --enable_bzlmod

# Disable rules_python Starlark rules for Bazel 7+.
# See https://github.com/bazelbuild/rules_python/issues/1069#issuecomment-1942053014.
build --action_env=RULES_PYTHON_ENABLE_PYSTAR=0

# Disable automatic generation of __init__.py files. This allows
# namespace packages (such as `google`) to work correctly.
# https://github.com/bazelbuild/bazel/issues/10076
build --incompatible_default_to_explicit_init_py=true

# Minimium c++ standard used.
build --cxxopt "-std=c++20" --host_cxxopt "-std=c++20"
build --action_env=BAZEL_CXXOPTS=-std=c++20
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ xls_clang-tidy.out
user.bazelrc
.vscode
.cache
MODULE.bazel.lock
52 changes: 2 additions & 50 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -12,45 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

workspace(name = "com_google_xls")

# Load and configure a hermetic LLVM based C/C++ toolchain. This is done here
# and not in load_external.bzl because it requires several sequential steps of
# declaring archives and using things in them, which is awkward to do in .bzl
# files because it's not allowed to use `load` inside of a function.
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

# Released 2023-09-20, current as of 2024-06-26 (but there is already a 0.0.10rc1)
# Needs to be loaded first, as llvm toolchain has an ancient version of this.
http_archive(
name = "rules_cc",
urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.0.9/rules_cc-0.0.9.tar.gz"],
sha256 = "2037875b9a4456dce4a79d112a8ae885bbc4aad968e6587dca6e64f3a0900cdf",
strip_prefix = "rules_cc-0.0.9",
)

# Commit on 2024-07-19, current as of 2024-07-21.
http_archive(
name = "toolchains_llvm",
integrity = "sha256-RVp0bZsDrelQAtxswWOLB4j8zCXQy/cSe1m3wL/E2PU=",
strip_prefix = "toolchains_llvm-01132cfdae7d7187a885cf79d5a3ac1ed8a02e5a",
url = "https://github.com/bazel-contrib/toolchains_llvm/archive/01132cfdae7d7187a885cf79d5a3ac1ed8a02e5a.tar.gz",
)

load("@toolchains_llvm//toolchain:deps.bzl", "bazel_toolchain_dependencies")

bazel_toolchain_dependencies()

load("@toolchains_llvm//toolchain:rules.bzl", "llvm_toolchain")
# TODO(https://github.com/google/xls/issues/931): Everything here should go away and migrate to MODULE.bazel

llvm_toolchain(
name = "llvm_toolchain",
llvm_version = "17.0.6",
)

load("@llvm_toolchain//:toolchains.bzl", "llvm_register_toolchains")

llvm_register_toolchains()
workspace(name = "com_google_xls")

load("//dependency_support:load_external.bzl", "load_external_repositories")

Expand All @@ -75,22 +39,10 @@ python_register_toolchains(
ignore_root_user_error = True,
)

# gRPC deps should be loaded before initializing other repos. Otherwise, various
# errors occur during repo loading and initialization.
load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps")

grpc_deps()

load("//dependency_support:initialize_external.bzl", "initialize_external_repositories")

initialize_external_repositories()

load("@xls_pip_deps//:requirements.bzl", xls_pip_install_deps = "install_deps")

xls_pip_install_deps()

# Loading the extra deps must be called after initialize_eternal_repositories or
# the call to pip_parse fails.
load("@com_github_grpc_grpc//bazel:grpc_extra_deps.bzl", "grpc_extra_deps")

grpc_extra_deps()

This file was deleted.

15 changes: 0 additions & 15 deletions dependency_support/com_github_grpc_grpc/BUILD.bazel

This file was deleted.

15 changes: 0 additions & 15 deletions dependency_support/com_google_absl/BUILD.bazel

This file was deleted.

15 changes: 0 additions & 15 deletions dependency_support/com_google_benchmark/BUILD.bazel

This file was deleted.

15 changes: 0 additions & 15 deletions dependency_support/com_grail_bazel_toolchain/BUILD.bazel

This file was deleted.

11 changes: 3 additions & 8 deletions dependency_support/initialize_external.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@

"""Provides helper that initializes external repositories with third-party code."""

load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
load("@com_google_benchmark//:bazel/benchmark_deps.bzl", "benchmark_deps")
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
load("@com_grail_bazel_compdb//:deps.bzl", "bazel_compdb_deps")
# TODO(https://github.com/google/xls/issues/931): with MODULE.bazel, probably some of these can be removed now, with the
# eventual goal that none of this is needed anymore and the file can be removed.

load("@io_bazel_rules_closure//closure:repositories.bzl", "rules_closure_dependencies", "rules_closure_toolchains")
load("@project_python//:defs.bzl", python_interpreter_target = "interpreter")
load("@rules_7zip//:setup.bzl", "setup_7zip") # needed by rules_hdl
Expand All @@ -31,8 +30,6 @@ load("//dependency_support/llvm:initialize.bzl", initialize_llvm = "initialize")

def initialize_external_repositories():
"""Calls set-up methods for external repositories that require that."""
bazel_skylib_workspace()
protobuf_deps()
rules_hdl_init(python_interpreter_target = python_interpreter_target)
rules_hdl_dependency_support()
setup_7zip()
Expand All @@ -48,6 +45,4 @@ def initialize_external_repositories():
)
initialize_boost()
initialize_llvm()
bazel_compdb_deps()
benchmark_deps()
rules_pkg_dependencies()
Loading

0 comments on commit 54fd925

Please sign in to comment.