Skip to content

Commit

Permalink
Reland 9756ee7
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Abseil Team authored and Copybara-Service committed Feb 27, 2024
1 parent 814ba36 commit 3b6d48e
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
17 changes: 17 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ config_setting(
constraint_values = ["@platforms//os:openbsd"],
)

# NOTE: Fuchsia is not an officially supported platform.
config_setting(
name = "fuchsia",
constraint_values = ["@platforms//os:fuchsia"],
)

config_setting(
name = "msvc_compiler",
flag_values = {
Expand Down Expand Up @@ -147,6 +153,17 @@ cc_library(
"@com_googlesource_code_re2//:re2",
],
"//conditions:default": [],
}) + select({
# `gtest-death-test.cc` has `EXPECT_DEATH` that spawns a process,
# expects it to crash and inspects its logs with the given matcher,
# so that's why these libraries are needed.
# Otherwise, builds targeting Fuchsia would fail to compile.
":fuchsia": [
"@fuchsia_sdk//pkg/fdio",
"@fuchsia_sdk//pkg/syslog",
"@fuchsia_sdk//pkg/zx",
],
"//conditions:default": [],
}),
)

Expand Down
4 changes: 4 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,9 @@ bazel_dep(name = "re2",
bazel_dep(name = "rules_python",
version = "0.29.0")


fake_fuchsia_sdk = use_repo_rule("//:fake_fuchsia_sdk.bzl", "fake_fuchsia_sdk")
fake_fuchsia_sdk(name = "fuchsia_sdk")

# https://github.com/bazelbuild/rules_python/blob/main/BZLMOD_SUPPORT.md#default-toolchain-is-not-the-local-system-python
register_toolchains("@bazel_tools//tools/python:autodetecting_toolchain")
33 changes: 33 additions & 0 deletions fake_fuchsia_sdk.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""Provides a fake @fuchsia_sdk implementation that's used when the real one isn't available.
This is needed since bazel queries on targets that depend on //:gtest (eg:
`bazel query "deps(set(//googletest/test:gtest_all_test))"`) will fail if @fuchsia_sdk is not
defined when bazel is evaluating the transitive closure of the query target.
See https://github.com/google/googletest/issues/4472.
"""

def _fake_fuchsia_sdk_impl(repo_ctx):
for stub_target in repo_ctx.attr._stub_build_targets:
stub_package = stub_target
stub_target_name = stub_target.split("/")[-1]
repo_ctx.file("%s/BUILD.bazel" % stub_package, """
filegroup(
name = "%s",
)
""" % stub_target_name)

fake_fuchsia_sdk = repository_rule(
doc = "Used to create a fake @fuchsia_sdk repository with stub build targets.",
implementation = _fake_fuchsia_sdk_impl,
attrs = {
"_stub_build_targets": attr.string_list(
doc = "The stub build targets to initialize.",
default = [
"pkg/fdio",
"pkg/syslog",
"pkg/zx",
],
),
},
)
6 changes: 6 additions & 0 deletions googletest_deps.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Load dependencies needed to use the googletest library as a 3rd-party consumer."""

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

def googletest_deps():
"""Loads common dependencies needed to use the googletest library."""
Expand All @@ -20,3 +21,8 @@ def googletest_deps():
strip_prefix = "abseil-cpp-20240116.0",
urls = ["https://github.com/abseil/abseil-cpp/releases/download/20240116.0/abseil-cpp-20240116.0.tar.gz"],
)

if not native.existing_rule("fuchsia_sdk"):
fake_fuchsia_sdk(
name = "fuchsia_sdk",
)

0 comments on commit 3b6d48e

Please sign in to comment.