|
| 1 | +"""Module extension for sanitizer libraries configuration in bzlmod.""" |
| 2 | + |
| 3 | +load(":sanitizer_libs.bzl", "setup_sanitizer_libs") |
| 4 | + |
| 5 | +def _sanitizer_libs_impl(module_ctx): |
| 6 | + """Implementation of the sanitizer_libs module extension. |
| 7 | +
|
| 8 | + This extension allows configuring sanitizer libraries in MODULE.bazel using |
| 9 | + the same setup_sanitizer_libs() function used in WORKSPACE. |
| 10 | + """ |
| 11 | + |
| 12 | + # Collect all setup tags from all modules |
| 13 | + # Only use the first tag found (sanitizer repos have fixed names) |
| 14 | + setup_tag = None |
| 15 | + for mod in module_ctx.modules: |
| 16 | + for tag in mod.tags.setup: |
| 17 | + if setup_tag == None: |
| 18 | + setup_tag = tag |
| 19 | + else: |
| 20 | + # Fail if multiple tags are found |
| 21 | + fail("Multiple setup() calls found for sanitizer_extension. Only one configuration is allowed since repository names are fixed to @msan_libs and @tsan_libs.") |
| 22 | + |
| 23 | + # Call setup_sanitizer_libs once with the configuration |
| 24 | + if setup_tag: |
| 25 | + setup_sanitizer_libs( |
| 26 | + msan_version = setup_tag.msan_version, |
| 27 | + msan_sha256 = setup_tag.msan_sha256, |
| 28 | + tsan_version = setup_tag.tsan_version, |
| 29 | + tsan_sha256 = setup_tag.tsan_sha256, |
| 30 | + ) |
| 31 | + else: |
| 32 | + # Use default configuration if no tags specified |
| 33 | + setup_sanitizer_libs() |
| 34 | + |
| 35 | +_setup = tag_class( |
| 36 | + attrs = { |
| 37 | + "msan_version": attr.string( |
| 38 | + doc = "Version of MSAN release to use (default: VERSIONS['bins_release'] from //:versions.bzl)", |
| 39 | + ), |
| 40 | + "msan_sha256": attr.string( |
| 41 | + doc = "SHA256 hash of the MSAN libs archive (default: VERSIONS['msan_libs_sha256'] from //:versions.bzl)", |
| 42 | + ), |
| 43 | + "tsan_version": attr.string( |
| 44 | + doc = "Version of TSAN release to use (default: VERSIONS['bins_release'] from //:versions.bzl)", |
| 45 | + ), |
| 46 | + "tsan_sha256": attr.string( |
| 47 | + doc = "SHA256 hash of the TSAN libs archive (default: VERSIONS['tsan_libs_sha256'] from //:versions.bzl)", |
| 48 | + ), |
| 49 | + }, |
| 50 | +) |
| 51 | + |
| 52 | +sanitizer_extension = module_extension( |
| 53 | + implementation = _sanitizer_libs_impl, |
| 54 | + tag_classes = { |
| 55 | + "setup": _setup, |
| 56 | + }, |
| 57 | +) |
0 commit comments