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 Dec 11, 2024
1 parent e018dfa commit 67750f1
Show file tree
Hide file tree
Showing 16 changed files with 72 additions and 485 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 @@ -8,3 +8,4 @@ user.bazelrc
.vscode
.cache
docs/
MODULE.bazel.lock
40 changes: 40 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
module(
name = "xls",
repo_name = "com_google_xls",
)

# Compiler toolchain
bazel_dep(name = "toolchains_llvm", version = "1.1.2")

# Configure and register the toolchain.
llvm = use_extension("@toolchains_llvm//toolchain/extensions:llvm.bzl", "llvm")
llvm.toolchain(
llvm_version = "17.0.6",
)
use_repo(llvm, "llvm_toolchain")

register_toolchains("@llvm_toolchain//:all")

#
bazel_dep(name = "abseil-cpp", version = "20240722.0.bcr.2", repo_name = "com_google_absl")
bazel_dep(name = "abseil-py", version = "2.1.0", repo_name = "com_google_absl_py")
bazel_dep(name = "bazel_skylib", version = "1.7.1")
bazel_dep(name = "boringssl", version = "0.20241209.0")
bazel_dep(name = "cppitertools", version = "2.1")
bazel_dep(name = "google_benchmark", version = "1.8.5", repo_name = "com_google_benchmark")
bazel_dep(name = "googleapis", version = "0.0.0-20240819-fe8ba054a", repo_name = "com_google_googleapis")
bazel_dep(name = "googletest", version = "1.15.2", repo_name = "com_google_googletest")
bazel_dep(name = "grpc", version = "1.68.0", repo_name = "com_github_grpc_grpc")
bazel_dep(name = "nlohmann_json", version = "3.11.3.bcr.1", repo_name="jsonhpp")
bazel_dep(name = "platforms", version = "0.0.10")
bazel_dep(name = "protobuf", version = "29.1", repo_name = "com_google_protobuf")
bazel_dep(name = "re2", version = "2024-07-02.bcr.1", repo_name = "com_googlesource_code_re2")
bazel_dep(name = "riegeli", version = "0.0.0-20240927-cdfb25a", repo_name = "com_google_riegeli")
bazel_dep(name = "rules_cc", version = "0.1.0")
bazel_dep(name = "rules_license", version = "1.0.0")
bazel_dep(name = "rules_pkg", version = "1.0.1")

# Not all external projects we directly need are available yet.
# This how to find what we use for further work on this file:
# find xls -name BUILD -o -name "*.bzl" | xargs sed 's/.*"\(@[_a-z0-9]*\).*/\1/p;d' | sort -u
# Once added here, remove from the {load,initialize}_external.bzl.
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 @@ -33,8 +32,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 @@ -51,6 +48,4 @@ def initialize_external_repositories():
)
initialize_boost()
initialize_llvm()
bazel_compdb_deps()
benchmark_deps()
rules_pkg_dependencies()
Loading

0 comments on commit 67750f1

Please sign in to comment.