Skip to content

Commit

Permalink
Add support for Bzlmod for the next release
Browse files Browse the repository at this point in the history
https://bazel.build/external/overview#bzlmod

Bzlmod will be the default in a future Bazel release.
By default it requires projects to be registered with the
Bazel Central Registry (https://registry.bazel.build/) and
thus uses regular releases by default.

Users that want to "live-at-head" can still do this through
with overrides (https://bazel.build/external/module#overrides).

This change updates Abseil dependencies to use released versions.
CI uses Bzlmod except in the case of linux_gcc-floor, which will
keep testing the old WORKSPACE-based dependency system.

PiperOrigin-RevId: 597676666
Change-Id: I8d33facc432477c6dc7daa06fd00bb4ae8c4adba
  • Loading branch information
derekmauro authored and copybara-github committed Jan 11, 2024
1 parent 3acbe29 commit 41a2a25
Show file tree
Hide file tree
Showing 16 changed files with 88 additions and 31 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Bzlmod lockfile
MODULE.bazel.lock
# Ignore all bazel-* symlinks.
/bazel-*
# Ignore Bazel verbose explanations
Expand Down
39 changes: 39 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright 2024 The Abseil Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# https://bazel.build/external/overview#bzlmod

module(
name = "abseil-cpp",
version = "head",
compatibility_level = 1,
)

# Only direct dependencies need to be listed below.
# Please keep the versions in sync with the versions in the WORKSPACE file.

bazel_dep(name = "bazel_skylib",
version = "1.5.0")

bazel_dep(name = "google_benchmark",
version = "1.8.3",
repo_name = "com_github_google_benchmark",
dev_dependency = True)

bazel_dep(name = "googletest",
version = "1.14.0.bcr.1",
repo_name = "com_google_googletest")

bazel_dep(name = "platforms",
version = "0.0.8")
38 changes: 18 additions & 20 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -20,42 +20,40 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

# GoogleTest/GoogleMock framework. Used by most unit-tests.
http_archive(
name = "com_google_googletest", # 2023-10-05T21:13:04Z
sha256 = "ba96972e0aa8a1428596570ac573958c1c879483bd148a2b72994453f9dfa7c2",
strip_prefix = "googletest-2dd1c131950043a8ad5ab0d2dda0e0970596586a",
name = "com_google_googletest",
sha256 = "8ad598c73ad796e0d8280b082cebd82a630d73e73cd3c70057938a6501bba5d7",
strip_prefix = "googletest-1.14.0",
# Keep this URL in sync with ABSL_GOOGLETEST_COMMIT in ci/cmake_common.sh and
# ci/windows_msvc_cmake.bat.
urls = ["/~https://github.com/google/googletest/archive/2dd1c131950043a8ad5ab0d2dda0e0970596586a.zip"],
urls = ["/~https://github.com/google/googletest/archive/refs/tags/v1.14.0.tar.gz"],
)

# RE2 (the regular expression library used by GoogleTest)
http_archive(
name = "com_googlesource_code_re2", # 2023-03-17T11:36:51Z
sha256 = "cb8b5312a65f2598954545a76e8bce913f35fbb3a21a5c88797a4448e9f9b9d9",
strip_prefix = "re2-578843a516fd1da7084ae46209a75f3613b6065e",
urls = ["/~https://github.com/google/re2/archive/578843a516fd1da7084ae46209a75f3613b6065e.zip"],
name = "com_googlesource_code_re2",
sha256 = "828341ad08524618a626167bd320b0c2acc97bd1c28eff693a9ea33a7ed2a85f",
strip_prefix = "re2-2023-11-01",
urls = ["/~https://github.com/google/re2/releases/download/2023-11-01/re2-2023-11-01.zip"],
)

# Google benchmark.
http_archive(
name = "com_github_google_benchmark", # 2023-08-01T07:47:09Z
sha256 = "db1e39ee71dc38aa7e57ed007f2c8b3bb59e13656435974781a9dc0617d75cc9",
strip_prefix = "benchmark-02a354f3f323ae8256948e1dc77ddcb1dfc297da",
urls = ["/~https://github.com/google/benchmark/archive/02a354f3f323ae8256948e1dc77ddcb1dfc297da.zip"],
name = "com_github_google_benchmark",
sha256 = "6bc180a57d23d4d9515519f92b0c83d61b05b5bab188961f36ac7b06b0d9e9ce",
strip_prefix = "benchmark-1.8.3",
urls = ["/~https://github.com/google/benchmark/archive/refs/tags/v1.8.3.tar.gz"],
)

# Bazel Skylib.
http_archive(
name = "bazel_skylib", # 2023-05-31T19:24:07Z
sha256 = "08c0386f45821ce246bbbf77503c973246ed6ee5c3463e41efc197fa9bc3a7f4",
strip_prefix = "bazel-skylib-288731ef9f7f688932bd50e704a91a45ec185f9b",
urls = ["/~https://github.com/bazelbuild/bazel-skylib/archive/288731ef9f7f688932bd50e704a91a45ec185f9b.zip"],
name = "bazel_skylib",
sha256 = "cd55a062e763b9349921f0f5db8c3933288dc8ba4f76dd9416aac68acee3cb94",
urls = ["/~https://github.com/bazelbuild/bazel-skylib/releases/download/1.5.0/bazel-skylib-1.5.0.tar.gz"],
)

# Bazel platform rules.
http_archive(
name = "platforms", # 2023-07-28T19:44:27Z
sha256 = "40eb313613ff00a5c03eed20aba58890046f4d38dec7344f00bb9a8867853526",
strip_prefix = "platforms-4ad40ef271da8176d4fc0194d2089b8a76e19d7b",
urls = ["/~https://github.com/bazelbuild/platforms/archive/4ad40ef271da8176d4fc0194d2089b8a76e19d7b.zip"],
name = "platforms",
sha256 = "8150406605389ececb6da07cbcb509d5637a3ab9a24bc69b1101531367d89d74",
urls = ["/~https://github.com/bazelbuild/platforms/releases/download/0.0.8/platforms-0.0.8.tar.gz"],
)
6 changes: 5 additions & 1 deletion ci/cmake_common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@

# The commit of GoogleTest to be used in the CMake tests in this directory.
# Keep this in sync with the commit in the WORKSPACE file.
readonly ABSL_GOOGLETEST_COMMIT="2dd1c131950043a8ad5ab0d2dda0e0970596586a"
# TODO(dmauro): After the next GoogleTest release, use the stable file required
# by Bzlmod. This means downloading a copy of the file and reuploading it to
# avoid changing checksums if the compression is changed by GitHub. It also
# means stop referring to it as a commit and instead use the uploaded filename.
readonly ABSL_GOOGLETEST_COMMIT="f8d7d77c06936315286eb55f8de22cd23c188571"

# Avoid depending on GitHub by looking for a cached copy of the commit first.
if [[ -r "${KOKORO_GFILE_DIR:-}/distdir/${ABSL_GOOGLETEST_COMMIT}.zip" ]]; then
Expand Down
2 changes: 1 addition & 1 deletion ci/linux_arm_clang-latest_libcxx_bazel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ for std in ${STD}; do
--copt=\"-DGTEST_REMOVE_LEGACY_TEST_CASEAPI_=1\" \
--copt=-Werror \
--define=\"absl=1\" \
--enable_bzlmod=false \
--enable_bzlmod=true \
--features=external_include_paths \
--keep_going \
--show_timestamps \
Expand Down
2 changes: 1 addition & 1 deletion ci/linux_clang-latest_libcxx_asan_bazel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ for std in ${STD}; do
--copt="-fsanitize=undefined" \
--copt="-fno-sanitize-blacklist" \
--copt=-Werror \
--enable_bzlmod=false \
--enable_bzlmod=true \
--features=external_include_paths \
--keep_going \
--linkopt="-fsanitize=address" \
Expand Down
2 changes: 1 addition & 1 deletion ci/linux_clang-latest_libcxx_bazel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ for std in ${STD}; do
--copt=\"-DGTEST_REMOVE_LEGACY_TEST_CASEAPI_=1\" \
--copt=-Werror \
--define=\"absl=1\" \
--enable_bzlmod=false \
--enable_bzlmod=true \
--features=external_include_paths \
--keep_going \
--show_timestamps \
Expand Down
2 changes: 1 addition & 1 deletion ci/linux_clang-latest_libcxx_tsan_bazel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ for std in ${STD}; do
--copt="-fsanitize=thread" \
--copt="-fno-sanitize-blacklist" \
--copt=-Werror \
--enable_bzlmod=false \
--enable_bzlmod=true \
--features=external_include_paths \
--keep_going \
--linkopt="-fsanitize=thread" \
Expand Down
2 changes: 1 addition & 1 deletion ci/linux_clang-latest_libstdcxx_bazel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ for std in ${STD}; do
--copt="-march=haswell" \
--copt=-Werror \
--define="absl=1" \
--enable_bzlmod=false \
--enable_bzlmod=true \
--features=external_include_paths \
--keep_going \
--linkopt="--gcc-toolchain=/usr/local" \
Expand Down
3 changes: 3 additions & 0 deletions ci/linux_gcc-floor_libstdcxx_bazel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ if [[ ${KOKORO_GFILE_DIR:-} ]] && [[ -d "${KOKORO_GFILE_DIR}/distdir" ]]; then
BAZEL_EXTRA_ARGS="--distdir=/distdir ${BAZEL_EXTRA_ARGS:-}"
fi

# TODO(absl-team): This currently uses Bazel 5. When upgrading to a version
# of Bazel that supports Bzlmod, add --enable_bzlmod=false to keep test
# coverage for the old WORKSPACE dependency management.
for std in ${STD}; do
for compilation_mode in ${COMPILATION_MODE}; do
for exceptions_mode in ${EXCEPTIONS_MODE}; do
Expand Down
2 changes: 1 addition & 1 deletion ci/linux_gcc-latest_libstdcxx_bazel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ for std in ${STD}; do
--copt=\"-DGTEST_REMOVE_LEGACY_TEST_CASEAPI_=1\" \
--copt=-Werror \
--define=\"absl=1\" \
--enable_bzlmod=false \
--enable_bzlmod=true \
--features=external_include_paths \
--keep_going \
--show_timestamps \
Expand Down
2 changes: 1 addition & 1 deletion ci/macos_xcode_bazel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ ${BAZEL_BIN} test ... \
--copt="-DGTEST_REMOVE_LEGACY_TEST_CASEAPI_=1" \
--copt="-Werror" \
--cxxopt="-std=c++14" \
--enable_bzlmod=false \
--enable_bzlmod=true \
--features=external_include_paths \
--keep_going \
--show_timestamps \
Expand Down
2 changes: 1 addition & 1 deletion ci/windows_clangcl_bazel.bat
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ IF NOT "%ALTERNATE_OPTIONS%"=="" copy %ALTERNATE_OPTIONS% absl\base\options.h
--copt=-Wno-microsoft-cast ^
--define=absl=1 ^
--distdir=%KOKORO_GFILE_DIR%\distdir ^
--enable_bzlmod=false ^
--enable_bzlmod=true ^
--extra_execution_platforms=//absl:x64_windows-clang-cl ^
--extra_toolchains=@local_config_cc//:cc-toolchain-x64_windows-clang-cl ^
--keep_going ^
Expand Down
2 changes: 1 addition & 1 deletion ci/windows_msvc_bazel.bat
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ IF NOT "%ALTERNATE_OPTIONS%"=="" copy %ALTERNATE_OPTIONS% absl\base\options.h
--copt=/std:%STD% ^
--define=absl=1 ^
--distdir=%KOKORO_GFILE_DIR%\distdir ^
--enable_bzlmod=false ^
--enable_bzlmod=true ^
--keep_going ^
--test_env="GTEST_INSTALL_FAILURE_SIGNAL_HANDLER=1" ^
--test_env=TZDIR="%CD%\absl\time\internal\cctz\testdata\zoneinfo" ^
Expand Down
8 changes: 7 additions & 1 deletion ci/windows_msvc_cmake.bat
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@

SETLOCAL ENABLEDELAYEDEXPANSION

SET ABSL_GOOGLETEST_COMMIT=2dd1c131950043a8ad5ab0d2dda0e0970596586a
:: The commit of GoogleTest to be used in the CMake tests in this directory.
:: Keep this in sync with the commit in the WORKSPACE file.
:: TODO(dmauro): After the next GoogleTest release, use the stable file required
:: by Bzlmod. This means downloading a copy of the file and reuploading it to
:: avoid changing checksums if the compression is changed by GitHub. It also
:: means stop referring to it as a commit and instead use the uploaded filename.
SET ABSL_GOOGLETEST_COMMIT=f8d7d77c06936315286eb55f8de22cd23c188571

IF EXIST %KOKORO_GFILE_DIR%\distdir\%ABSL_GOOGLETEST_COMMIT%.zip (
SET ABSL_GOOGLETEST_DOWNLOAD_URL=file://%KOKORO_GFILE_DIR%\distdir\%ABSL_GOOGLETEST_COMMIT%.zip
Expand Down
5 changes: 5 additions & 0 deletions create_lts.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ def main(argv):
'datestamp={} is not in the YYYYMMDD format'.format(datestamp))

# Replacement directives go here.
ReplaceStringsInFile(
'MODULE.bazel', {
'version = "head"':
'version = "{}.0"'.format(datestamp)
})
ReplaceStringsInFile(
'absl/base/config.h', {
'#undef ABSL_LTS_RELEASE_VERSION':
Expand Down

0 comments on commit 41a2a25

Please sign in to comment.