iTranslated by AI
Solving External Module Version Update Issues in Bazel
First draft: 2023-04-30
Hiroyuki Komatsu (@komatsuh)
Article Content
In the Bazel build system, I will introduce the cause and solution for the problem where configurations set in the WORKSPACE.bazel file are not reflected as expected.
Terminology
- Bazel: A build system. It serves the same role as Make or CMake. This article is intended for those who already have a basic understanding of Bazel.
- WORKSPACE.bazel: A configuration file used in Bazel. It describes settings for external module dependencies.
About WORKSPACE.bazel
To use external modules in the Bazel build system, you write configurations in WORKSPACE.bazel.
For example, to use Bazel skylib version 1.0.2, you would do as follows:
# Bazel Skylib
http_archive(
name = "bazel_skylib",
sha256 = "97e70364e9249702246c0e9444bccdc4b847bed1eb03c5a3ece4f83dfe6abc44",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz",
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz",
],
)
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
bazel_skylib_workspace()
Problem with Versions Not Updating and Its Solution
To update this to 1.4.1, you should rewrite sha256 and urls appropriately, but I encountered an issue where it was not updated as expected.
Upon investigation, I found that the cause was another module had already loaded the same module before this configuration.
# Protocol buffers
# This configuration was internally setting Bazel Skylib 1.0.2
local_repository(
name = "com_google_protobuf",
path = "third_party/protobuf",
)
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
protobuf_deps()
# Bazel Skylib
# Since Bazel Skylib 1.0.2 is already configured, this does nothing
http_archive(
name = "bazel_skylib",
sha256 = "b8a1527901774180afc798aeb28c4634bdccf19c4d98e7bdd1ce79d1fe9aaad7",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.4.1/bazel-skylib-1.4.1.tar.gz",
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.4.1/bazel-skylib-1.4.1.tar.gz",
],
)
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
bazel_skylib_workspace()
By changing the loading order, the expected version is now loaded.
# Bazel Skylib
# Configure version 1.4.1
http_archive(
name = "bazel_skylib",
sha256 = "b8a1527901774180afc798aeb28c4634bdccf19c4d98e7bdd1ce79d1fe9aaad7",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.4.1/bazel-skylib-1.4.1.tar.gz",
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.4.1/bazel-skylib-1.4.1.tar.gz",
],
)
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
bazel_skylib_workspace()
# Protocol buffers
# Use Bazel Skylib 1.4.1 which is already configured
local_repository(
name = "com_google_protobuf",
path = "third_party/protobuf",
)
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
protobuf_deps()
Once you understand it, it's a simple case of "I see," but it was a problem that took me a while to identify the cause.
Discussion