buildbuddy-io / buildbuddy-toolchain

Bazel toolchains for BuildBuddy RBE
MIT License
10 stars 11 forks source link

bzlmod support #18

Open keith opened 3 months ago

keith commented 3 months ago

It would be great if you could pull this repo in with bzlmod!

siggisim commented 3 months ago

Agreed - cc @sluongng

siggisim commented 3 months ago

cc @fmeum too in case you're looking for something lightweight to get started with

marvin-hansen commented 1 month ago

Much needed. I am converting a Bazel project and this is the only rule left.

marvin-hansen commented 1 month ago

There is a PR already in the making, so please upvote. Would be great to see this happening.

https://github.com/buildbuddy-io/buildbuddy-toolchain/pull/27

marvin-hansen commented 1 month ago

Ok, you can actually keep using the existing rules in a Bazelmod configuration using the hybrid mode, as documented on the Bazel website.

You just crate a WORKSPACE.bzlmod file and add the rules from your previous WORKSPACE file. I've added an example file here: https://gist.github.com/marvin-hansen/1441191edb8c5385d93f50c2624d9998

For any Bazel version before Bazel 7, you have to enable Bazelmod in the .bazelrc with

common --enable_bzlmod

However, upon the first run on BuildBuddy, you may encounter an error stating that rules_python must run in a non-root environment. I had this and the solution is relatively easy, you just override the error reporting. To do so, you add rules-python to your MODULE.bazel

# https://github.com/bazelbuild/rules_python/releases
bazel_dep(name = "rules_python", version = "0.33.1")

And the configure the python toolchain as following:

# Python toolchain
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
python.toolchain(
    configure_coverage_tool = False,
    ignore_root_user_error = True,
    python_version = "3.11",
)

The python version must match the python version shown in the error trace, which in my case was 3.11.

When rules_python have been configured, the error goes away and the build completes.

In practices, this buys some time until the official Bazelmod rules arrive.

Also, I want to point out that the official migration guide is actually one of the better examples of Bazel documentation and clearly shows that somebody thought this through and came up with a sensible solution to migrate larger projects step by step.

https://bazel.build/external/migration

sluongng commented 1 month ago

@marvin-hansen Hi Marvin.

Yes, the current hybrid mode should unblock you for now.

Me and @fmeum have been discussing internally how to convert BuildBuddy Toolchains to BzlMod. We sent #27 as a POC, but as you discovered, the current UX is not very nice and we want to make it a bit more sane so that our users would not have to switch back and forth between different config knobs. We will be resuming the work on this PR soon. I will update this issue when we have more updates to share.

The rules_python issue is a separate issue, not related to BuildBuddy Toolchains, but I'm glad that you were able to find a solution for it. If you are using BuildBuddy Workflows, you could update your user via this config https://www.buildbuddy.io/docs/workflows-config#action. Feel free to ask questions in our community Slack about this 🤗

marvin-hansen commented 1 month ago

Thanks for the update. I appreciate the detailed elaboration.

I'm good for now, my Bazelmod config plus hybrid is running and humming on BuildBuddy. It's once more a confirmation that I made the right choice to build on BuildBuddy since stuff just works.

Also, it's sensible to give the new Bazelmod design a bit more time and thought.

In the meantime, would be great to add the hybrid workaround in the Readme so people have a working stopgap until things are ready to go.

Thank you for your work!

On Thu, Jun 13, 2024 at 5:07 PM Son Luong Ngoc @.***> wrote:

@marvin-hansen https://github.com/marvin-hansen Hi Marvin.

Yes, the current hybrid mode should unblock you for now.

Me and @fmeum https://github.com/fmeum have been discussing internally how to convert BuildBuddy Toolchains to BzlMod. We sent #27 https://github.com/buildbuddy-io/buildbuddy-toolchain/pull/27 as a POC, but as you discovered, the current UX is not very nice and we want to make it a bit more sane so that our users would not have to switch back and forth between different config knobs. We will be resuming the work on this PR soon. I will update this issue when we have more updates to share.

The rules_python issue is a separate issue, not related to BuildBuddy Toolchains, but I'm glad that you were able to find a solution for it. If you are using BuildBuddy Workflows, you could update your user via this config https://www.buildbuddy.io/docs/workflows-config#action. Feel free to ask questions in our community Slack about this 🤗

— Reply to this email directly, view it on GitHub https://github.com/buildbuddy-io/buildbuddy-toolchain/issues/18#issuecomment-2165071179, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFYR7XGW775IDUQYDJ5WY73ZHFOORAVCNFSM6AAAAABJHVAN3OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNRVGA3TCMJXHE . You are receiving this because you were mentioned.Message ID: @.***>