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

[feature] add support for lucidsoftware/rules_scala #209

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ryan28561
Copy link

This should make it possible to run bazel-bsp with metals on projects that rely on lucidsoftware's fork of rules_scala. The main changes are:

  • Tweaked the scala_info aspect and related code to support rules_scala
  • Restored the dependencySources build server protocol feature (because metals is still using it)
  • Added the --norun_validations flag to the aspect run to avoid accidentally pulling in slower actions as a part of the aspect run

As a note, I have tried running metals + bazel-bsp against a few different open source scala projects that were using bazel_io_rules_scala, and I couldn't get any of them to work. I did my best to "do no harm" with these changes if people are using this successfully, but if someone can provide me with steps to get a working setup, I'd appreciate any pointers. Similar comment on tests, I found and ran tests, most passed, but I'm not sure how I could have effected the ones that failed locally, so I'm hoping it's a problem with my environment and not a mistake I made with my changes.

@agluszak
Copy link
Contributor

Hi! Thank you very much for your contribution. Please run bazel run format because CI is failing because of that.

Regarding upstream rules_scala support: our codebase has suffered from a bit of bitrot in this area to be honest, because we mostly focused on java + kotlin. But we absolutely want to restore full scala support in the future.

@agluszak
Copy link
Contributor

LGTM, but perhaps @abrams27 wants to have a second look

@agluszak
Copy link
Contributor

Do you know in which Bazel version this flag was introduced exactly? Google plugin seems to use --noexperimental_run_validations

Copy link
Member

@abrams27 abrams27 left a comment

Choose a reason for hiding this comment

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

thanks a lot for the contribution! I found some issues and they probably explain why some tests are failing and upstream rules import is broken

@abrams27 abrams27 changed the title add support for lucidsoftware/rules_scala [feature] add support for lucidsoftware/rules_scala Jan 16, 2025
@@ -53,7 +56,23 @@ class JavaLanguagePlugin(
private fun getJdk(): Jdk = jdk ?: throw RuntimeException("Failed to resolve JDK for project")

override fun dependencySources(targetInfo: TargetInfo, dependencyGraph: DependencyGraph): Set<URI> =
emptySet() // Provided via workspace/libraries
targetInfo.getJvmTargetInfoOrNull()?.run {
Copy link
Member

Choose a reason for hiding this comment

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

and I'd do this calculation conditional as well - it's quite heavy calculation executed for each target, what can add quite some overhead for us (we use a separate mechanism for it, because this one is too slow for us).

By "conditional" everywhere I meant that it's possible to check what rules are imported (org/jetbrains/bsp/bazel/server/sync/ProjectResolver.kt:69), it's a list of all rules in the workspace, and then you can use this list to check if the fork rules are loaded

Copy link
Author

Choose a reason for hiding this comment

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

Ok, so on this one I have a question. As far as I can tell, the workspace/libraries command isn't a part of the build server protocol that I can see, and more practically speaking, metals lsp doesn't seem to consume it. All that is to say, I enabled this more for metals support than for rules_scala_annex support.

I'm happy to do what you recommended just to make my use case work, but is it possible we could make this something configurable instead? I see there are some FeatureFlags in the repo, would that be a viable place to add a toggle for something like this?

Copy link
Member

Choose a reason for hiding this comment

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

indeed workspace/libraries are only in our "extension", we use it because dependencySources is too slow for us (and uses too much memory), so we have an endpoint which returns globally all the libraries which are referenced from modules.

You can add a feature flag to org.jetbrains.bsp.protocol.FeatureFlags (calculateDependencySources or useLibraries) with a default which should work for a generic bsp implementation, and override it only in our client, so server will do it only if it's connected to our server which supports custom endpoint

@ryan28561
Copy link
Author

Thanks for your feedback! I'm a little slow, but I'll get to work on these!

@ryan28561
Copy link
Author

Do you know in which Bazel version this flag was introduced exactly? Google plugin seems to use --noexperimental_run_validations

It looks to me like it was renamed in 5.0. https://blog.bazel.build/2022/01/19/bazel-5.0.html

@abrams27
Copy link
Member

It looks to me like it was renamed in 5.0

nice, so we dont have to worry about it, bazel 5 is deprecated

@ryan28561 ryan28561 requested a review from abrams27 January 28, 2025 17:14
Copy link
Member

@abrams27 abrams27 left a comment

Choose a reason for hiding this comment

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

and it seems like not everything is building

Language.Scala ->
when (ruleLanguage.ruleName) {
"rules_scala_annex" -> Label.parse("@rules_scala_annex//rules/scala:toolchain_type")
else -> Label.parse("@${ruleLanguage.ruleName}//scala:toolchain_type")
Copy link
Member

Choose a reason for hiding this comment

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

it

Suggested change
else -> Label.parse("@${ruleLanguage.ruleName}//scala:toolchain_type")
else -> Label.parse("@io_bazel_rules_scala//scala:toolchain_type")

even in bzlmod, it's still prefixed with io_bazel

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.

3 participants