1 """Provides a fake @fuchsia_sdk implementation that's used when the real one isn't available.
3 GoogleTest can be used with the [Fuchsia](https://fuchsia.dev/) SDK. However,
4 because the Fuchsia SDK does not yet support bzlmod, GoogleTest's `MODULE.bazel`
5 file by default provides a "fake" Fuchsia SDK.
7 To override this and use the real Fuchsia SDK, you can add the following to your
8 project's `MODULE.bazel` file:
10 fake_fuchsia_sdk_extension =
11 use_extension("@com_google_googletest//:fake_fuchsia_sdk.bzl", "fuchsia_sdk")
12 override_repo(fake_fuchsia_sdk_extension, "fuchsia_sdk")
14 NOTE: The `override_repo` built-in is only available in Bazel 8.0 and higher.
16 See https://github.com/google/googletest/issues/4472 for more details of why the
17 fake Fuchsia SDK is needed.
20 def _fake_fuchsia_sdk_impl(repo_ctx):
21 for stub_target in repo_ctx.attr._stub_build_targets:
22 stub_package = stub_target
23 stub_target_name = stub_target.split("/")[-1]
24 repo_ctx.file("%s/BUILD.bazel" % stub_package, """
28 """ % stub_target_name)
30 fake_fuchsia_sdk = repository_rule(
31 doc = "Used to create a fake @fuchsia_sdk repository with stub build targets.",
32 implementation = _fake_fuchsia_sdk_impl,
34 "_stub_build_targets": attr.string_list(
35 doc = "The stub build targets to initialize.",
45 _create_fake = tag_class()
47 def _fuchsia_sdk_impl(module_ctx):
48 create_fake_sdk = False
49 for mod in module_ctx.modules:
50 for _ in mod.tags.create_fake:
51 create_fake_sdk = True
54 fake_fuchsia_sdk(name = "fuchsia_sdk")
56 return module_ctx.extension_metadata(reproducible = True)
58 fuchsia_sdk = module_extension(
59 implementation = _fuchsia_sdk_impl,
60 tag_classes = {"create_fake": _create_fake},