Skip to content

Commit 3b6d48e

Browse files
Abseil Teamcopybara-github
Abseil Team
authored andcommitted
Reland 9756ee7
Since Fuchsia engineers rarely work within this repo, initialize a lightweight fake @fuchsia_sdk repo rather than distributing the Fuchsia SDK here. Tested locally via `bazel query --[no]enable_bzlmod "deps(set(//googletest/test:gtest_all_test))"` (#4472) PiperOrigin-RevId: 610826859 Change-Id: I7d41b1dbe9e7f133fe535d7337dc5bff5bf97d3a
1 parent 814ba36 commit 3b6d48e

File tree

4 files changed

+60
-0
lines changed

4 files changed

+60
-0
lines changed

BUILD.bazel

+17
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ config_setting(
5656
constraint_values = ["@platforms//os:openbsd"],
5757
)
5858

59+
# NOTE: Fuchsia is not an officially supported platform.
60+
config_setting(
61+
name = "fuchsia",
62+
constraint_values = ["@platforms//os:fuchsia"],
63+
)
64+
5965
config_setting(
6066
name = "msvc_compiler",
6167
flag_values = {
@@ -147,6 +153,17 @@ cc_library(
147153
"@com_googlesource_code_re2//:re2",
148154
],
149155
"//conditions:default": [],
156+
}) + select({
157+
# `gtest-death-test.cc` has `EXPECT_DEATH` that spawns a process,
158+
# expects it to crash and inspects its logs with the given matcher,
159+
# so that's why these libraries are needed.
160+
# Otherwise, builds targeting Fuchsia would fail to compile.
161+
":fuchsia": [
162+
"@fuchsia_sdk//pkg/fdio",
163+
"@fuchsia_sdk//pkg/syslog",
164+
"@fuchsia_sdk//pkg/zx",
165+
],
166+
"//conditions:default": [],
150167
}),
151168
)
152169

MODULE.bazel

+4
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,9 @@ bazel_dep(name = "re2",
5353
bazel_dep(name = "rules_python",
5454
version = "0.29.0")
5555

56+
57+
fake_fuchsia_sdk = use_repo_rule("//:fake_fuchsia_sdk.bzl", "fake_fuchsia_sdk")
58+
fake_fuchsia_sdk(name = "fuchsia_sdk")
59+
5660
# https://github.com/bazelbuild/rules_python/blob/main/BZLMOD_SUPPORT.md#default-toolchain-is-not-the-local-system-python
5761
register_toolchains("@bazel_tools//tools/python:autodetecting_toolchain")

fake_fuchsia_sdk.bzl

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""Provides a fake @fuchsia_sdk implementation that's used when the real one isn't available.
2+
3+
This is needed since bazel queries on targets that depend on //:gtest (eg:
4+
`bazel query "deps(set(//googletest/test:gtest_all_test))"`) will fail if @fuchsia_sdk is not
5+
defined when bazel is evaluating the transitive closure of the query target.
6+
7+
See https://github.com/google/googletest/issues/4472.
8+
"""
9+
10+
def _fake_fuchsia_sdk_impl(repo_ctx):
11+
for stub_target in repo_ctx.attr._stub_build_targets:
12+
stub_package = stub_target
13+
stub_target_name = stub_target.split("/")[-1]
14+
repo_ctx.file("%s/BUILD.bazel" % stub_package, """
15+
filegroup(
16+
name = "%s",
17+
)
18+
""" % stub_target_name)
19+
20+
fake_fuchsia_sdk = repository_rule(
21+
doc = "Used to create a fake @fuchsia_sdk repository with stub build targets.",
22+
implementation = _fake_fuchsia_sdk_impl,
23+
attrs = {
24+
"_stub_build_targets": attr.string_list(
25+
doc = "The stub build targets to initialize.",
26+
default = [
27+
"pkg/fdio",
28+
"pkg/syslog",
29+
"pkg/zx",
30+
],
31+
),
32+
},
33+
)

googletest_deps.bzl

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Load dependencies needed to use the googletest library as a 3rd-party consumer."""
22

33
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
4+
load("//:fake_fuchsia_sdk.bzl", "fake_fuchsia_sdk")
45

56
def googletest_deps():
67
"""Loads common dependencies needed to use the googletest library."""
@@ -20,3 +21,8 @@ def googletest_deps():
2021
strip_prefix = "abseil-cpp-20240116.0",
2122
urls = ["https://github.com/abseil/abseil-cpp/releases/download/20240116.0/abseil-cpp-20240116.0.tar.gz"],
2223
)
24+
25+
if not native.existing_rule("fuchsia_sdk"):
26+
fake_fuchsia_sdk(
27+
name = "fuchsia_sdk",
28+
)

0 commit comments

Comments
 (0)