From be0be496bfcc4ac17fc61d555ed00b52f25920ff Mon Sep 17 00:00:00 2001 From: smolkaj Date: Wed, 18 Dec 2024 18:57:07 +0000 Subject: [PATCH] Migrate to Bzlmod. Signed-off-by: smolkaj --- .bazelrc | 6 +-- .gitignore | 1 + MODULE.bazel | 25 ++++++++++++ WORKSPACE.bazel | 3 ++ WORKSPACE.bzlmod | 83 ++++++++++++++++++++++++++++++++++++++ p4_constraints/BUILD.bazel | 5 +-- 6 files changed, 117 insertions(+), 6 deletions(-) create mode 100644 MODULE.bazel create mode 100644 WORKSPACE.bzlmod diff --git a/.bazelrc b/.bazelrc index f097dde..fbc101e 100644 --- a/.bazelrc +++ b/.bazelrc @@ -9,7 +9,7 @@ build --host_cxxopt=-std=c++17 build --action_env=CC=clang build --action_env=CXX=clang++ -# Use `WORKSPACE.bazel` instead of Bzlmod (`MODULE.bazel`). -# TODO - migrate to Bzlmod. -common --noenable_bzlmod +# Use Bzlmod (`MODULE.bazel`) and `WORKSPACE.bzlmod`. +# TODO - Disable workspace once all dependencies are migrated to bzlmod. +common --enable_bzlmod common --enable_workspace diff --git a/.gitignore b/.gitignore index 515bf0c..d7dce35 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ bazel-* user.bazelrc buildifier +*.lock diff --git a/MODULE.bazel b/MODULE.bazel new file mode 100644 index 0000000..d18cce2 --- /dev/null +++ b/MODULE.bazel @@ -0,0 +1,25 @@ +module( + name = "p4-constraints", + bazel_compatibility = [">=7.4.1"], + repo_name = "com_github_p4lang_p4_constraints", +) + +bazel_dep(name = "protobuf", version = "28.2", repo_name = "com_google_protobuf") +bazel_dep(name = "abseil-cpp", version = "20240116.2", repo_name = "com_google_absl") +bazel_dep(name = "re2", version = "2024-02-01", repo_name = "com_googlesource_code_re2") +bazel_dep(name = "p4runtime", version = "1.4.1", repo_name = "com_github_p4lang_p4runtime") +git_override( + module_name = "p4runtime", + commit = "da2e3441e1774112ecf44905ba8ef57d1b33c3e0", + remote = "https://github.com/p4lang/p4runtime.git", + strip_prefix = "proto", +) + +# Dev Depdencies. +bazel_dep( + name = "googletest", + version = "1.15.2", + dev_dependency = True, + repo_name = "com_google_googletest", +) +bazel_dep(name = "rules_license", version = "1.0.0", dev_dependency = True) diff --git a/WORKSPACE.bazel b/WORKSPACE.bazel index 041e5ab..da4c929 100644 --- a/WORKSPACE.bazel +++ b/WORKSPACE.bazel @@ -1,4 +1,7 @@ # Bazel workspace file. +# +# NOTE: This file is ignored when bzlmod is enabled. It is provided for users +# who have not yet migrated to bzlmod, and will be removed in the future. workspace(name = "com_github_p4lang_p4_constraints") diff --git a/WORKSPACE.bzlmod b/WORKSPACE.bzlmod new file mode 100644 index 0000000..ad81e1a --- /dev/null +++ b/WORKSPACE.bzlmod @@ -0,0 +1,83 @@ +# https://bazel.build/external/migration#workspace.bzlmod +# +# When bzlmod is enabled and this file exists, the contents of WORKSPACE.bazel +# is ignored. This file will become empty once all dependencies have been +# migrated to bzlmod (`MODULE.bazel`). + +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +# -- P4{C, Runtime} + transitive dependencies ---------------------------------- + +http_archive( + name = "com_github_p4lang_p4c", + # Newest commit on main on 2021-12-07. + url = "https://github.com/p4lang/p4c/archive/80629201abb61d9172639fefc7bb5b9d6007db08.zip", + strip_prefix = "p4c-80629201abb61d9172639fefc7bb5b9d6007db08", +) + +load("@com_github_p4lang_p4c//:bazel/p4c_deps.bzl", "p4c_deps") + +p4c_deps() + +load("@com_github_nelhage_rules_boost//:boost/boost.bzl", "boost_deps") + +boost_deps() + + +# load("@com_google_googleapis//:repository_rules.bzl", "switched_rules_by_language") + +# switched_rules_by_language( +# name = "com_google_googleapis_imports", +# cc = True, +# grpc = True, +# ) + +# load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps") + +# grpc_deps() + +# load("@com_github_grpc_grpc//bazel:grpc_extra_deps.bzl", "grpc_extra_deps") + +# grpc_extra_deps() + +# -- Load Buildifier ----------------------------------------------------- +# buildifier is written in Go and hence needs rules_go to be built. +# See https://github.com/bazelbuild/rules_go for the up to date setup instructions. +http_archive( + name = "io_bazel_rules_go", + sha256 = "6dc2da7ab4cf5d7bfc7c949776b1b7c733f05e56edc4bcd9022bb249d2e2a996", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.39.1/rules_go-v0.39.1.zip", + "https://github.com/bazelbuild/rules_go/releases/download/v0.39.1/rules_go-v0.39.1.zip", + ], +) +load("@io_bazel_rules_go//go:deps.bzl", "go_rules_dependencies") +go_rules_dependencies() +http_archive( + name = "com_github_bazelbuild_buildtools", + sha256 = "ae34c344514e08c23e90da0e2d6cb700fcd28e80c02e23e4d5715dddcb42f7b3", + strip_prefix = "buildtools-4.2.2", + urls = [ + "https://github.com/bazelbuild/buildtools/archive/refs/tags/4.2.2.tar.gz", + ], +) + +# -- Z3 & Load Rules Foreign CC ------------------------------------------------- + +http_archive( + name = "com_github_z3prover_z3", + url = "https://github.com/Z3Prover/z3/archive/z3-4.8.12.tar.gz", + strip_prefix = "z3-z3-4.8.12", + sha256 = "e3aaefde68b839299cbc988178529535e66048398f7d083b40c69fe0da55f8b7", + build_file = "@//:bazel/BUILD.z3.bazel", +) +http_archive( + name = "rules_foreign_cc", + sha256 = "d54742ffbdc6924f222d2179f0e10e911c5c659c4ae74158e9fe827aad862ac6", + strip_prefix = "rules_foreign_cc-0.2.0", + url = "https://github.com/bazelbuild/rules_foreign_cc/archive/0.2.0.tar.gz", +) + +load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies") + +rules_foreign_cc_dependencies() diff --git a/p4_constraints/BUILD.bazel b/p4_constraints/BUILD.bazel index bb22274..3a84594 100644 --- a/p4_constraints/BUILD.bazel +++ b/p4_constraints/BUILD.bazel @@ -1,6 +1,5 @@ -# GOOGLE ONLY (DO NOT REMOVE): load("//third_party/protobuf/bazel:proto_library.bzl", "proto_library") -load("@rules_cc//cc:defs.bzl", "cc_proto_library") -load("@rules_proto//proto:defs.bzl", "proto_library") +load("@com_google_protobuf//bazel:cc_proto_library.bzl", "cc_proto_library") +load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") package( default_visibility = ["//visibility:public"],