Skip to content

Commit

Permalink
Convert to bzlmod, first steps.
Browse files Browse the repository at this point in the history
First steps towards exclusively using MODULE.bazel, for now
a subset of changes already improving the state a lot.

  * Add MODULE.bazel and add dependencies already provided by
    the Bazel Central Registry.
  * Remove the above from WORKSPACE and
    dependency_support/{load,initialize}_external.bzl.
  * Add some patches, as some external dependencies used
    @rules_cc// to get cc_proto_library and cc_library, which is
    not available anymore in latest rules_cc (but provided by
    bazel itself)
  * Fallout: the compilation db currently can't be built anymore
    due to the compdb not compatible anymore with bzlmod.
    I have a plan to replace that, but not in this first CL; for
    now, it is just disabled.

Things for follow-up PRs
  * move the remaining load_exernal.bzl also to MODULE.bazel, but
    use the repo rules to fetch projects.
  * Upstream more tools we use to Bazel Central Registry; e.g.
    low hanging fruit would be to get a later version of protoc-gen-validate
    in there or add lineoise.
  * Rules python and its toolchain can probably be simplified.
  * fix compilation db.

Issues: #931
  • Loading branch information
hzeller committed Jan 30, 2025
1 parent ba13486 commit 1cc9620
Show file tree
Hide file tree
Showing 24 changed files with 399 additions and 654 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
13 changes: 7 additions & 6 deletions .github/workflows/nightly-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
# See also: https://github.com/marketplace/actions/bazel-action

name: Nightly MacOS
on:
schedule:
# Nightly at midnight PDT -- uses UTC, so 7am.
- cron: '0 7 * * *'
# This lets us trigger manually from the UI.
workflow_dispatch:
# Temporary, while in #1893, disable schedule
#on:
# schedule:
# # Nightly at midnight PDT -- uses UTC, so 7am.
# - cron: '0 7 * * *'
# # This lets us trigger manually from the UI.
# workflow_dispatch:

jobs:
build:
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
53 changes: 53 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
module(
name = "xls",
repo_name = "com_google_xls",
)

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

# 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.1", repo_name = "com_google_absl")
bazel_dep(name = "abseil-py", version = "2.1.0", repo_name = "com_google_absl_py")
bazel_dep(name = "bazel_features", version = "1.25.0")
bazel_dep(name = "bazel_skylib", version = "1.7.1")
bazel_dep(name = "boringssl", version = "0.20250114.0")
bazel_dep(name = "googleapis", version = "0.0.0-20240819-fe8ba054a", repo_name = "com_google_googleapis")
bazel_dep(name = "grpc", version = "1.69.0", repo_name = "com_github_grpc_grpc")
bazel_dep(name = "nlohmann_json", version = "3.11.3.bcr.1")
bazel_dep(name = "platforms", version = "0.0.11")
bazel_dep(name = "protobuf", version = "29.3", 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-20241218-3385e3c", repo_name = "com_google_riegeli")
bazel_dep(name = "rules_license", version = "1.0.0")
bazel_dep(name = "rules_pkg", version = "1.0.1")
bazel_dep(name = "rules_proto", version = "7.1.0")
bazel_dep(name = "verible", version = "0.0.3933")

# Dev dependencies
bazel_dep(name = "fuzztest", version = "20241028.0", dev_dependency = True, repo_name = "com_google_fuzztest")
bazel_dep(name = "google_benchmark", version = "1.9.1", dev_dependency = True, repo_name = "com_google_benchmark")
bazel_dep(name = "googletest", version = "1.15.2", dev_dependency = True, repo_name = "com_google_googletest")

# Repositories we don't really depend on directly, but we need to provide
# for other dependencies as they are using old versions that are not
# compatible with current bazel.
bazel_dep(name = "rules_bison", version = "0.3")
bazel_dep(name = "rules_flex", version = "0.3")
bazel_dep(name = "rules_java", version = "8.7.2")
bazel_dep(name = "protoc-gen-validate", version = "1.0.4.bcr.2")
single_version_override(
module_name = "protoc-gen-validate",
patch_strip = 1,
patches = ["//dependency_support:protoc-gen-validate/no-rulescc.patch"],
version = "1.0.4.bcr.2",
)
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_google_fuzztest/BUILD.bazel

This file was deleted.

This file was deleted.

Loading

0 comments on commit 1cc9620

Please sign in to comment.