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

Draft: Add bzlmod minimal support #1541

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

mateuszkuta256
Copy link
Contributor

Description

This is the first step of migration to Bzlmod, see https://bazel.build/external/migration

I'm gonna create a few further pull requests to bring all the changes described here: #1482 (comment)
The migration process will finish once WORKSPACE.bzlmod is empty

Motivation

Resolve #1482

@@ -85,11 +85,11 @@ def _get_unused_deps_mode(ctx):

def _is_target_included(target, includes, excludes):
for exclude in excludes:
if target.startswith(exclude):
if target.startswith(exclude) or target.startswith("@" + exclude):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

https://bazel.build/external/overview#canonical-repo-name
for blzmod labels can be like "@@..."

Copy link
Collaborator

Choose a reason for hiding this comment

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

If I don't miss anything, you don't need to do anything here - it'll be easier for users to just specify correct prefix themselves. It's a sloppy implementation to support label prefixes, I think let's not add more logic to it.

@@ -64,7 +64,7 @@ def _jvm_import_external(repository_ctx):
if (repository_ctx.attr.generated_linkable_rule_name and
not repository_ctx.attr.neverlink):
fail("Only use generated_linkable_rule_name if neverlink is set")
name = repository_ctx.attr.generated_rule_name or repository_ctx.name
name = repository_ctx.attr.repo_name or repository_ctx.attr.generated_rule_name or repository_ctx.name
Copy link
Contributor Author

Choose a reason for hiding this comment

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

names of repositories issued by bzlmod module extensions will look like:
_main~non_module_deps~new_repo
this is why I added explicit parameter to achieve: @new_repo

@@ -18,7 +18,7 @@ test_classpath_contains_2_13() {

test_scala_config_content() {
bazel build --repo_env=SCALA_VERSION=0.0.0 @io_bazel_rules_scala_config//:all 2> /dev/null
grep "SCALA_MAJOR_VERSION='0.0'" $(bazel info output_base)/external/io_bazel_rules_scala_config/config.bzl
grep "SCALA_MAJOR_VERSION='0.0'" $(bazel info output_base)/external/*/config.bzl
Copy link
Contributor Author

Choose a reason for hiding this comment

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

when built with bzlmod target will be in sth like:
/external/~main_non_module_deps~io_bazel_rules_scala_config/config.bzl

@@ -516,4 +516,16 @@ artifacts = {
"artifact": "org.typelevel:kind-projector_%s:0.13.2" % scala_version,
"sha256": "8f7287973f7f8fc9372b59d36120e3fac5839344f65c8f640351794e8907145c",
},
"io_bazel_rules_scala_scala_interfaces": {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

looks kinda odd, but I couldn't figure out a better solution
the thing is we have to specify all the possible repos in a MODULE.bazel file
there's no access to SCALA_VERSION property from there, so cannot do sth like "use this repo only if scala_version == 3"
I made a doc comment in scala/scala_maven_import_external.bzl repository def which is meant to be used only for bzlmod

@mateuszkuta256
Copy link
Contributor Author

I turn into a draft because will surely cause conflicts with these changes:

SCALA_VERSION dependent code has to be refactored to read this information from the toolchain

@mateuszkuta256 mateuszkuta256 marked this pull request as draft January 29, 2024 15:11
@simuons
Copy link
Collaborator

simuons commented Feb 7, 2024

Hi, @mateuszkuta256, thanks for taking this. So as I understand this is somewhat "blocked" by required changes to toolchains and SCALA_VERSION. I'll reply in multi scala issue shortly. This change and multi scala are the big ones. So maybe lets first solve multi scala and toolchains and then bzlmod (i have a hunch that proper toolchains would make bzlmod migration easier).

@mateuszkuta256 mateuszkuta256 changed the title Add bzlmod minimal support Draft: Add bzlmod minimal support Feb 13, 2024
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.

Support Bzlmod and add rules_scala to bazel-central-registry
3 participants