| # Copyright 2026 The Fuchsia Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| """Module extension wrapper for `fuchsia_clang_repository`. |
| |
| We'd like to be able to use `fuchsia_clang_ext` from `@rules_fuchsia`, but this isn't feasible |
| currently since `@rules_fuchsia` is fetched via module extension and module extensions can be loaded |
| from repos that are instantiated by other module extensions. |
| """ |
| |
| load("@rules_fuchsia//fuchsia:clang.bzl", "fuchsia_clang_repository") |
| |
| def _fuchsia_clang_ext_impl(ctx): |
| cipd_bin = None |
| cipd_ensure_file = None |
| cipd_tag = None |
| sha256 = None |
| |
| for mod in ctx.modules: |
| if mod.tags.cipd_ensure: |
| cipd = mod.tags.cipd_ensure[0] |
| cipd_bin = cipd.cipd_bin |
| cipd_ensure_file = cipd.ensure_file |
| elif mod.tags.cipd_tag: |
| cipd = mod.tags.cipd_tag[0] |
| cipd_tag = cipd.cipd_tag |
| sha256 = cipd.sha256 |
| else: |
| # If `use_repo(fuchsia_clang_ext, "fuchsia_clang")` is called in a repo without a |
| # `fuchsia_clang_ext.<tag>` declaration. |
| continue |
| |
| if len(mod.tags.cipd_ensure + mod.tags.cipd_tag) > 1: |
| fail("Cannot specify multiple tags of `fuchsia_clang_ext.cipd_ensure` or `fuchsia_clang_ext.cipd_tag` within %s." % ( |
| "`@%s`" % mod.name if mod.name else "the root module" |
| )) |
| |
| # Ignore all other lower-precedence declarations. |
| break |
| |
| fuchsia_clang_repository( |
| name = "fuchsia_clang", |
| cipd_bin = cipd_bin, |
| cipd_ensure_file = cipd_ensure_file, |
| cipd_tag = cipd_tag, |
| sha256 = sha256, |
| ) |
| |
| _cipd_ensure_tag = tag_class( |
| attrs = { |
| "cipd_bin": attr.label( |
| doc = "The cipd binary that will be used to fetch clang distribution.", |
| default = "@cipd_tool//:cipd", |
| ), |
| "ensure_file": attr.label( |
| doc = "A cipd ensure file to use to download clang.", |
| mandatory = True, |
| ), |
| }, |
| ) |
| |
| _cipd_tag_tag = tag_class( |
| attrs = { |
| "cipd_tag": attr.string( |
| doc = "CIPD tag for the version to load.", |
| mandatory = True, |
| ), |
| "sha256": attr.string_dict( |
| doc = "Optional SHA-256 hash of the clang archive. Valid keys are mac and linux", |
| ), |
| }, |
| ) |
| |
| fuchsia_clang_ext = module_extension( |
| implementation = _fuchsia_clang_ext_impl, |
| tag_classes = { |
| "cipd_ensure": _cipd_ensure_tag, |
| "cipd_tag": _cipd_tag_tag, |
| }, |
| ) |