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

Add support for bzlmod #198

Merged
merged 41 commits into from
Sep 12, 2023
Merged

Add support for bzlmod #198

merged 41 commits into from
Sep 12, 2023

Conversation

gferon
Copy link
Contributor

@gferon gferon commented May 15, 2023

This is a fairly straightforward change that adds support for using bazel-toolchain with bzlmod. We've been using this patch on a rather large checkout with success.

The llvm.toolchain extension is only a wrapper around the existing llvm_toolchain repository rule and supports the same attributes.

For trying it out, add the following to your MODULE.bazel:

bazel_dep(name = "com_grail_bazel_toolchain", version = "0.8")
git_override(module_name = "com_grail_bazel_toolchain", remote = "https://github.com/grailbio/bazel-toolchain", commit = "cf915e5c7cfcd19a3e71de54e385e01240b865dc")

llvm = use_extension("@com_grail_bazel_toolchain//toolchain:extensions.bzl", "llvm")
llvm.toolchain(
    llvm_version = "15.0.0"
)

use_repo(llvm, "llvm_toolchain")

register_toolchains("@llvm_toolchain//:all")

Copy link
Contributor

@siddharthab siddharthab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for this. Unsure about how version strings work in this, but otherwise all good.

MODULE.bazel Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
toolchain/extensions.bzl Outdated Show resolved Hide resolved
MODULE.bazel Outdated Show resolved Hide resolved
toolchain/rules.bzl Outdated Show resolved Hide resolved
toolchain/rules.bzl Outdated Show resolved Hide resolved
@gferon
Copy link
Contributor Author

gferon commented May 15, 2023

I would also be more comfortable if we immediately add CI to verify that it works as intended.

@gferon gferon requested a review from jsharpe May 15, 2023 16:22
@siddharthab
Copy link
Contributor

Thank you so much @jsharpe for reviewing this. I have not been active with Bazel for a few years now and am not caught up with modules. I will leave it to you to merge this.

toolchain/extensions.bzl Outdated Show resolved Hide resolved
@gferon
Copy link
Contributor Author

gferon commented May 16, 2023

@jsharpe thanks for the thorough review, is there a way you can approve GitHub workflows for this PR so that I can iterate on the tests until everything passes?

EDIT: maybe you approved, it's running now

@jsharpe
Copy link
Member

jsharpe commented May 16, 2023

@jsharpe thanks for the thorough review, is there a way you can approve GitHub workflows for this PR so that I can iterate on the tests until everything passes?

I don't think there is unfortunately. I think its a limitation as this is your first PR against this repo. We could get this merged and use a subsquent PR to setup CI and then I don't think we'd have the same limitation?

@gferon
Copy link
Contributor Author

gferon commented May 16, 2023

We could get this merged and use a subsquent PR

Sounds good, I know there are more adjustments to be made, for example all flags aren't forwarded to llvm_toolchain and CI will need adjusting. I'm definitely up to finish adding support for bzlmod.

@gferon gferon changed the title Add support for bzlmod Add initial support for bzlmod May 16, 2023
@gferon gferon marked this pull request as ready for review May 16, 2023 08:54
@gferon
Copy link
Contributor Author

gferon commented May 16, 2023

@jsharpe I excluded Bazel 5.1.0 from the CI job matrix with bzlmod but I think a better solution would be to bump to 5.4.0 which supports the --enable_bzlmod flag. Otherwise, I believe this is ready to merge and improve upon.

@jsharpe
Copy link
Member

jsharpe commented May 16, 2023

FYI, When i've had similar failures to those in CI its been due to redefinitions of the platforms repo in the WORKSPACE.bzlmod file

@fmeum
Copy link
Member

fmeum commented Jul 11, 2023

Let me know if you want me to look into particular failures.

https://github.com/grailbio/bazel-toolchain/actions/runs/5361378105/jobs/9727258799?pr=198 is difficult to migrate as is: The abseil-cpp BCR module only defines the deps needed to use it, not to test it. This may require adding it as an http_archive in the same extension as com_google_googletest instead of using the BCR module.

.github/workflows/tests.yml Outdated Show resolved Hide resolved
tests/WORKSPACE Outdated Show resolved Hide resolved
Comment on lines 53 to 56
srcs = [("@grail_llvm_toolchain//tests/openssl:" + f) for f in CONF_FILES],
outs = CONF_FILES,
cmd = "\n".join([
"cp $(location @com_grail_bazel_toolchain//tests/openssl:{0}) $(location {0})".format(f)
"cp $(location @grail_llvm_toolchain//tests/openssl:{0}) $(location {0})".format(f)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name will need to be conditionally selected based on whether BZLMOD is enabled.

Copy link
Contributor Author

@gferon gferon Sep 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, how about renaming the original name of the repository to also match the new one with bzlmod, it's not really a breaking change IMO. EDIT: Using repo_name for tests is also an easier option.

@jsharpe
Copy link
Member

jsharpe commented Sep 8, 2023

Something isn't quite right with the external_test as it seems to be running the non-bzlmod version for the bzlmod testcase.

Otherwise the changes look good to me - we're soo close to getting this landed.

@gferon
Copy link
Contributor Author

gferon commented Sep 8, 2023

Something isn't quite right with the external_test as it seems to be running the non-bzlmod version for the bzlmod testcase.

I switched from --experimental_enable_bzlmod to --enable_bzlmod in the external tests shell script and it looks like it works now (tested locally).

@jsharpe
Copy link
Member

jsharpe commented Sep 8, 2023

Something isn't quite right with the external_test as it seems to be running the non-bzlmod version for the bzlmod testcase.

I switched from --experimental_enable_bzlmod to --enable_bzlmod in the external tests shell script and it looks like it works now (tested locally).

That won’t work for the 5.1.0 tests..

@siddharthab
Copy link
Contributor

A recent change has upped the minimum supported version to 6.0.0 from 5.1.0, if it helps.

MODULE.bazel Outdated
@@ -0,0 +1,9 @@
module(
name = "grail_llvm_toolchain",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it will be OK to call it simply "llvm_toolchain". I am trying to get this project moved to the bazel-contrib repo, where the simpler name would make more sense.

Copy link
Contributor Author

@gferon gferon Sep 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! I would love to see this moved to bazel-contrib.

@gferon
Copy link
Contributor Author

gferon commented Sep 11, 2023

So, in theory I have fixed (after breaking them) the last few CI issues, except https://github.com/grailbio/bazel-toolchain/actions/runs/6124327795/job/16624119392 that I haven't taken enough time to understand.

EDIT: I excluded one more rules_go test for the time being, it should work now!

@gferon gferon changed the title Add initial support for bzlmod Add support for bzlmod Sep 11, 2023
Copy link
Contributor

@siddharthab siddharthab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very good. Just some final nits.

tests/scripts/run_external_tests.sh Show resolved Hide resolved
toolchain/internal/configure.bzl Show resolved Hide resolved
tests/scripts/run_external_tests.sh Outdated Show resolved Hide resolved
@siddharthab
Copy link
Contributor

Let me merge this for you now, and I can iterate on the failing tests on my side.

@siddharthab siddharthab merged commit 5c6f806 into bazel-contrib:master Sep 12, 2023
23 of 27 checks passed
@siddharthab
Copy link
Contributor

Thank you so much for all your hard work on this.

@gferon gferon deleted the bzlmod branch September 12, 2023 17:13
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

Successfully merging this pull request may close these issues.

4 participants