Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bzlmod/01-depend_on_bazel_module/.bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8.3.1
9.*
2 changes: 1 addition & 1 deletion bzlmod/01-depend_on_bazel_module/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
cc_binary(
name = "main",
srcs = ["main.cc"],
deps = ["@com_github_google_glog//:glog"],
deps = ["@abseil-cpp//absl/strings"],
)
2 changes: 1 addition & 1 deletion bzlmod/01-depend_on_bazel_module/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ bazel_dep(name = "rules_cc", version = "0.0.17")

# 1. The metadata of glog is fetched from the BCR, including its dependencies (gflags).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please update this comment (s/glog/abseil-cpp/; no repo_name; also I'm not sure if abseil-cpp has transitive deps?)

# 2. The `repo_name` attribute allows users to reference this dependency via the `com_github_google_glog` repo name.
bazel_dep(name = "glog", version = "0.5.0", repo_name = "com_github_google_glog")
bazel_dep(name = "abseil-cpp", version = "20240722.0")
9 changes: 4 additions & 5 deletions bzlmod/01-depend_on_bazel_module/main.cc
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#include <glog/logging.h>
#include <iostream>
#include "absl/strings/str_cat.h"

int main(int argc, char* argv[]) {
// Initialize Google’s logging library.
google::InitGoogleLogging(argv[0]);

int num_cookies = 42;
LOG(INFO) << "Found " << num_cookies << " cookies";
std::string s = absl::StrCat("Found ", num_cookies, " cookies");
std::cout << s << std::endl;
}
2 changes: 1 addition & 1 deletion bzlmod/02-override_bazel_module/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ cc_binary(
name = "main",
srcs = ["main.cc"],
deps = [
"@com_github_google_glog//:glog",
"@lib_a",
"@com_googlesource_re2//:re2",
],
)
31 changes: 19 additions & 12 deletions bzlmod/02-override_bazel_module/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,30 @@ module(
version = "0.0.1",
)

bazel_dep(name = "rules_cc", version = "0.0.17")
bazel_dep(name = "glog", version = "0.5.0", repo_name = "com_github_google_glog")

# Override glog to a fork version with archive_override.
# Override abseil-cpp to the 20250814.1 LTS version with archive_override.
# This demonstrates how to use archive_override to point to a specific tarball.
bazel_dep(name = "abseil-cpp", version = "20240722.0")
archive_override(
module_name = "glog",
integrity = "sha256-EH4o3n+qkfcsEFODkkRzs1/XAH9ej2V77gv05eplB5k=",
strip_prefix = "glog-9401faa19e0424791243827b8e95efd3d0d8db23",
urls = ["https://github.com/meteorcloudy/glog/archive/9401faa19e0424791243827b8e95efd3d0d8db23.tar.gz"],
module_name = "abseil-cpp",
integrity = "sha256-FpL3fRc5us8/lDNxiLeFg88JurfkINLcbFYFpPhnhaE=",
strip_prefix = "abseil-cpp-20250814.1",
urls = ["https://github.com/abseil/abseil-cpp/releases/download/20250814.1/abseil-cpp-20250814.1.tar.gz"],
)

# Override gflag to a fork version with git_override.
# gflag is still an indirect dependency, the override itself doesn't give the root module visibility on gflags.
# Override re2 to a specific commit with git_override.
# This demonstrates how to use git_override to depend on a specific commit.
bazel_dep(name = "re2", version = "2024-07-02", repo_name = "com_googlesource_re2")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

restore the previous comment, and also remove this bazel_dep

git_override(
module_name = "gflags",
commit = "95995169e86f3fedd19696df5b1811d441c462a2",
remote = "https://github.com/meteorcloudy/gflags.git",
module_name = "re2",
commit = "e7aec5985072c1dbe735add802653ef4b36c231a",
remote = "https://github.com/google/re2.git",
)


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


# Patch bazel skylib 1.7.1 with a local patch file.
bazel_dep(name = "bazel_skylib", version = "1.7.1")
single_version_override(
Expand All @@ -38,3 +43,5 @@ local_path_override(
module_name = "lib_a",
path = "./lib_a",
)


2 changes: 1 addition & 1 deletion bzlmod/02-override_bazel_module/lib_a/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ cc_library(
name = "lib_a",
srcs = ["lib_a.cc"],
hdrs = ["lib_a.h"],
deps = ["@com_github_google_glog//:glog"],
visibility = ["//visibility:public"],
)
2 changes: 1 addition & 1 deletion bzlmod/02-override_bazel_module/lib_a/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ module(
)

bazel_dep(name = "rules_cc", version = "0.0.17")
bazel_dep(name = "glog", version = "0.5.0", repo_name = "com_github_google_glog")

4 changes: 2 additions & 2 deletions bzlmod/02-override_bazel_module/lib_a/lib_a.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <glog/logging.h>
#include <iostream>

void lib_a() {
LOG(INFO) << "Hello from module A!";
std::cout << "Hello from module A!" << std::endl;
}
13 changes: 7 additions & 6 deletions bzlmod/02-override_bazel_module/main.cc
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#include <glog/logging.h>

#include <iostream>
#include "lib_a.h"
#include "re2/re2.h"

int main(int argc, char* argv[]) {
// Initialize Google’s logging library.
google::InitGoogleLogging(argv[0]);

LOG(INFO) << "Hello from the main module!";
std::cout << "Hello from the main module!" << std::endl;
lib_a();

if (RE2::FullMatch("bazel", "b.*l")) {
std::cout << "RE2 match!" << std::endl;
}
}