Skip to content

Commit 67d73d7

Browse files
authored
Bzlmod examples - Fix errors with glog for Bazel@HEAD (#654)
Fixes #644. `Glog` repo needed patches in multiple places since it's missing load rules statements for Bazel@HEAD. Still, since glog is archived (https://github.com/google/glog), I've just switched to logging from absl.
1 parent c680436 commit 67d73d7

File tree

10 files changed

+26
-32
lines changed

10 files changed

+26
-32
lines changed

bzlmod/01-depend_on_bazel_module/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
33
cc_binary(
44
name = "main",
55
srcs = ["main.cc"],
6-
deps = ["@com_github_google_glog//:glog"],
6+
deps = ["@com_google_absl//absl/log"],
77
)

bzlmod/01-depend_on_bazel_module/MODULE.bazel

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ module(
55

66
bazel_dep(name = "rules_cc", version = "0.0.17")
77

8-
# 1. The metadata of glog is fetched from the BCR, including its dependencies (gflags).
9-
# 2. The `repo_name` attribute allows users to reference this dependency via the `com_github_google_glog` repo name.
10-
bazel_dep(name = "glog", version = "0.5.0", repo_name = "com_github_google_glog")
8+
# 1. The metadata of abseil-cpp is fetched from the BCR, including its dependencies (platforms).
9+
# 2. The `repo_name` attribute allows users to reference this dependency via the `com_google_absl` repo name.
10+
bazel_dep(name = "abseil-cpp", version = "20250814.1", repo_name = "com_google_absl")
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
#include <glog/logging.h>
1+
#include "absl/log/log.h"
22

33
int main(int argc, char* argv[]) {
4-
// Initialize Google’s logging library.
5-
google::InitGoogleLogging(argv[0]);
6-
74
int num_cookies = 42;
85
LOG(INFO) << "Found " << num_cookies << " cookies";
96
}

bzlmod/02-override_bazel_module/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ cc_binary(
88
name = "main",
99
srcs = ["main.cc"],
1010
deps = [
11-
"@com_github_google_glog//:glog",
11+
"@com_google_absl//absl/log",
1212
"@lib_a",
1313
],
1414
)

bzlmod/02-override_bazel_module/MODULE.bazel

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,32 @@ module(
33
version = "0.0.1",
44
)
55

6-
bazel_dep(name = "rules_cc", version = "0.0.17")
7-
bazel_dep(name = "glog", version = "0.5.0", repo_name = "com_github_google_glog")
6+
bazel_dep(name = "rules_cc", version = "0.2.16")
7+
bazel_dep(name = "abseil-cpp", version = "20250814.1", repo_name = "com_google_absl")
88

9-
# Override glog to a fork version with archive_override.
9+
# # Override abseil-cpp to a fork version with archive_override.
1010
archive_override(
11-
module_name = "glog",
12-
integrity = "sha256-EH4o3n+qkfcsEFODkkRzs1/XAH9ej2V77gv05eplB5k=",
13-
strip_prefix = "glog-9401faa19e0424791243827b8e95efd3d0d8db23",
14-
urls = ["https://github.com/meteorcloudy/glog/archive/9401faa19e0424791243827b8e95efd3d0d8db23.tar.gz"],
11+
module_name = "abseil-cpp",
12+
integrity = "sha256-nfNEp86X1YI48kp7nyCFbubyFrtzDw+8dwBl0PACXrc=",
13+
strip_prefix = "abseil-cpp-7599e36e7cbad38ec77cadd959d3a45d2124800a",
14+
urls = ["https://github.com/abseil/abseil-cpp/archive/7599e36e7cbad38ec77cadd959d3a45d2124800a.tar.gz"],
1515
)
1616

17-
# Override gflag to a fork version with git_override.
18-
# gflag is still an indirect dependency, the override itself doesn't give the root module visibility on gflags.
17+
# Override platforms to a fork version with git_override.
18+
# platforms is still an indirect dependency, the override itself doesn't give the root module visibility on platforms.
1919
git_override(
20-
module_name = "gflags",
21-
commit = "95995169e86f3fedd19696df5b1811d441c462a2",
22-
remote = "https://github.com/meteorcloudy/gflags.git",
20+
module_name = "platforms",
21+
commit = "5cf94563e35494b0dab15435868dd7f9e3cab2c8",
22+
remote = "https://github.com/bazelbuild/platforms.git",
2323
)
2424

25-
# Patch bazel skylib 1.7.1 with a local patch file.
26-
bazel_dep(name = "bazel_skylib", version = "1.7.1")
25+
# Patch bazel skylib 1.9.0 with a local patch file.
26+
bazel_dep(name = "bazel_skylib", version = "1.9.0")
2727
single_version_override(
2828
module_name = "bazel_skylib",
2929
patch_strip = 1,
3030
patches = ["//:bazel_skylib.patch"],
31-
version = "1.7.1",
31+
version = "1.9.0",
3232
)
3333

3434
# Depend on module lib_a at a local path.

bzlmod/02-override_bazel_module/bazel_skylib.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ index dc7f0ef..47768d8 100644
55
@@ -14,3 +14,4 @@
66

77
# Keep in sync with MODULE.bazel and @bazel_skylib_gazelle_plugin//:MODULE.bazel
8-
version = "1.7.1"
8+
version = "1.9.0"
99
+hello_msg = "Hello skylib"

bzlmod/02-override_bazel_module/lib_a/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ cc_library(
66
name = "lib_a",
77
srcs = ["lib_a.cc"],
88
hdrs = ["lib_a.h"],
9-
deps = ["@com_github_google_glog//:glog"],
9+
deps = ["@com_google_absl//absl/log"],
1010
)

bzlmod/02-override_bazel_module/lib_a/MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ module(
44
)
55

66
bazel_dep(name = "rules_cc", version = "0.0.17")
7-
bazel_dep(name = "glog", version = "0.5.0", repo_name = "com_github_google_glog")
7+
bazel_dep(name = "abseil-cpp", version = "20250814.1", repo_name = "com_google_absl")

bzlmod/02-override_bazel_module/lib_a/lib_a.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include <glog/logging.h>
1+
#include "absl/log/log.h"
22

33
void lib_a() {
44
LOG(INFO) << "Hello from module A!";
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
#include <glog/logging.h>
1+
#include "absl/log/log.h"
22

33
#include "lib_a.h"
44

55
int main(int argc, char* argv[]) {
6-
// Initialize Google’s logging library.
7-
google::InitGoogleLogging(argv[0]);
8-
96
LOG(INFO) << "Hello from the main module!";
107
lib_a();
118
}

0 commit comments

Comments
 (0)