Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use LLVM toolchain in a module which can be used as both a dependency and a root module #243

Closed
mering opened this issue Jan 3, 2024 · 3 comments

Comments

@mering
Copy link
Contributor

mering commented Jan 3, 2024

I have a Bzlmod module "A" which I want to be able to build standalone but also be depended on by module "B".

If I define

bazel_dep(name = "toolchains_llvm", version = "0.10.3")
llvm = use_extension("@toolchains_llvm//toolchain/extensions:llvm.bzl", "llvm")
llvm.toolchain(
    llvm_version = "14.0.0",
    sysroot = {
        "linux-x86_64": "chromium_x64_sysroot",
    },
    sysroot_label_map = {
        "@com_googleapis_storage_chrome_linux_amd64_sysroot//:all_files": "chromium_x64_sysroot",
    },
)
use_repo(llvm, "llvm_toolchain")
register_toolchains("@llvm_toolchain//:all")

in MODULE.bazel of both module "A" and "B", then I get the following error when compiling module "B" which depends on module "A":

ERROR: Traceback (most recent call last):
        File "/home/USER/.cache/bazel/_bazel_builder/395eea75460def8a11dd35795d615210/external/toolchains_llvm~override/toolchain/extensions/llvm.bzl", line 13, column 17, in _llvm_impl_
                fail("Only the root module can use the 'llvm' extension")
Error in fail: Only the root module can use the 'llvm' extension

But if I remove it from module "A", I can no longer build module "A" correctly standalone.

How can I define the llvm_toolchain such that I can use it in both modules "A" and "B"?


Based on #235.

@mering
Copy link
Contributor Author

mering commented Jan 3, 2024

Would it be possible to just ignore non-root tool chain calls and print a warning instead of the fail()? This is what the Python tool chain is doing as well.

@fmeum
Copy link
Member

fmeum commented Jan 11, 2024

You can add dev_dependency = True to your use_extension and register_toolchains calls. Then the toolchain definition in A will be ignored when building from B. If needed, B can define its own toolchain in this way.

@mering
Copy link
Contributor Author

mering commented Jan 15, 2024

Using dev_dependency worked. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants