<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/55924>55924</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [bazel] Add support for bzlmod module system
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          aaronmondal
      </td>
    </tr>
</table>

<pre>
    We are currently working on making the Clang/LLVM Bazel overlay available via the `bzlmod` system. We noticed that parts of this may be desirable to have in the Clang/LLVM overlay in this repo.

## What works
* We have a partially working `MODULE.bazel`  file [here](https://github.com/eomii/rules_ll/blob/main/MODULE.bazel) (ignore the `rules_ll` specific stuff). When importing via `local_path_override` it works. For registries it does not work (see below).
* An `extensions.bzl` file to apply the overlay etc. is [here](https://github.com/eomii/rules_ll/blob/main/ll/extensions.bzl), mostly copied from [`configure.bzl`](https://github.com/llvm/llvm-project/blob/main/utils/bazel/configure.bzl).

## What doesn't work
I would expect that we would need to fix the following issues before something like this would be acceptable for upstreaming:
* Users will need to be able to specify whether they want `zlib` etc. This should be simple to fix by exposing related functionality as extensions.
* Importing via remote registries does not work yet. `bzlmod` suffixes remotely fetched imports as `<name>.<version>`. This breaks copt includes in `@llvm-project//clang:ast` https://github.com/llvm/llvm-project/blob/fb6627fa0c6eafa0270491f65ceb7e897faa1b07/utils/bazel/llvm-project-overlay/clang/BUILD.bazel#L704-L715 and the outputs of `@llvm-project//clang:builtin_headers_gen` https://github.com/llvm/llvm-project/blob/fb6627fa0c6eafa0270491f65ceb7e897faa1b07/utils/bazel/llvm-project-overlay/clang/BUILD.bazel#L1468-L1480 Manually patching this works, but is not really maintainable as one would have to change the patches for every version tracked in a registry. We are still looking for an easily maintainable solution that is backwards-compatible with `WORKSPACE`s.
* `local_path_override` omits the version number.  Requiring users to clone Clang/LLVM and manually overriding via `local_path_override` works. Feels a little hacky though ðŸ˜Ÿ
* Registries do not work with labels in `http_archive` because of this bug: https://github.com/bazelbuild/bazel/issues/14659. Workarounds are possible, but not pretty.

## Conclusion
The main issues we encountered so far come from the fact that it is hard to test this stuff with remote bazel registries. Certain bugs only occur when fetching from remote registries, so local development does not ensure that things work as intended.

Please let me know whether `bzlmod` support is something that would have a place in the bazel overlay in this repository. If it is, please also let me know which issues, apart from those already mentioned we would have to address.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzVVttu20YQ_RrpZWFCom7Wgx4cOQKMOkiQJs2jsSSH4tbLXXZ3KVn5-p5ZirrYaYMWfSlgi_eZMzPnzExmi8PqGwnpSOStc2SCPoi9dc_KbIU1opbxLFQk1lqa7SDdPD7-9kG8k99JC7sjp-VByJ1UWmaaxE7J-PJgPsq-69oWOBH-4APViYAjY4PKqcA7MohGuuCFLXGlPFwdREaiIK9ctBWsqOSOhDJv_fee4zN87KixyWB0PxjdHX_TCf7EN_bD8fj-9h3DiHZlBKCkvggZcD98vP_6-D7JOEJGL0oFMIPZu4ocDWb3g_S2CqHxgwmsbfC3VaFqsyS3NS7I1krh6FpN_klrnGbaZjjUUhkcrsynSwFzamssCnDM2-lLzlxDuSpVLnxoyxKvI4kVGaHqxgI6AHPC8aa2udRPjQzVE6fGqYL4e3UMPhEb65CkrfLBKfL8oLA4oh7xDYbhiVAAbffs55yuO8MO6CWQ8coan6CwbDumBTWSTYMEMvi-KBTyRKAo_1nO4q1XCNLlIF2L2npmbG4bBVaVztbsFfBya0q1bR0d4f4UhNa7_nDTOPs75eENjjYo7fluV7zNtZNz1t4wkHMNA4su2d3zB5y3uhD0giKHThF7Ot40xCKxSPJLTG1pNQrDBVfetyhcRiVzxtuaIADc1-qZOi10FiAlmefUhKglvCzaBsUnWeNtTsGpwF89OXyltD655Y-PEuwoCIVUcESO0eBCmsCs-K5VxlyIFf_Czn3Ve_cgaWeCg8gOHKj1DNWRloHL1Zo8oKBSq4Am4sVFic_wHq647qi2gS6pfM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