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 Aug 28, 2024
1 parent 02f5fd9 commit 5fd46c1
Show file tree
Hide file tree
Showing 16 changed files with 77 additions and 460 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
38 changes: 38 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
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 = "20240116.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.0.0-20240530-2db0eb3")
bazel_dep(name = "google_benchmark", version = "1.8.5", repo_name = "com_google_benchmark")
bazel_dep(name = "googleapis", version = "0.0.0-20240326-1c8d509c5", repo_name = "com_google_googleapis")
bazel_dep(name = "googletest", version = "1.15.2", repo_name = "com_google_googletest")
bazel_dep(name = "grpc", version = "1.66.0", repo_name = "com_github_grpc_grpc")
bazel_dep(name = "nlohmann_json", version = "3.11.3", repo_name = "jsonhpp")
bazel_dep(name = "protobuf", version = "28.0-rc2", repo_name = "com_google_protobuf")
bazel_dep(name = "re2", version = "2024-07-02", repo_name = "com_googlesource_code_re2")
bazel_dep(name = "riegeli", version = "0.0.0-20240606-973b6f0", repo_name = "com_google_riegeli")
bazel_dep(name = "rules_cc", version = "0.0.9")
bazel_dep(name = "rules_license", version = "0.0.8")
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.
50 changes: 2 additions & 48 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -12,46 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# TODO(#931): Everything here should go away and migrate to MODULE.bazel

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")

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

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

llvm_register_toolchains()

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

load_external_repositories()
Expand All @@ -75,22 +41,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.

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

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

# TODO(#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("@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")
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 +31,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 +46,4 @@ def initialize_external_repositories():
)
initialize_boost()
initialize_llvm()
bazel_compdb_deps()
benchmark_deps()
rules_pkg_dependencies()
Loading

0 comments on commit 5fd46c1

Please sign in to comment.