-
Notifications
You must be signed in to change notification settings - Fork 49
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
BSP control plugin #465
BSP control plugin #465
Conversation
Created as "Draft" coz I would like to do some additional checks first. But any feedback is welcome! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I think we are fairly desperate for some relief in this area. Not your fault of course—but I just wish this wasn't so "clunky" for the non-vanilla usecases.
I wonder if it's worth going upstream to the CrossPlugin
to try and expose some additional information e.g. all of a projects cross targets, whether it is a pure/full cross, etc.
Alternatively, I wonder if this is a problem that IDEs should solve, instead of us. Arguably it's a bit weird to hard-code BSPs into the build. Which BSPs should be enabled or disabled depends precisely on what the user is doing at that moment, so it seems like they should configure this via UI in the IDE. To give an example: http4s-core is 99% a pure cross-build, but it has a very small amount of JS-specific sources. On the occasional bad day I have to poke at those, and it would be extremely annoying to have to futz the build to get BSP support. But it would be even worse to force JS BSP onto everyone because of like 3 source files I touch every 6 months when a new Node.js drops and everything breaks /rant.
// Keep `bspEnabled := true` for non-sbtcrossproject projects. | ||
bspEnabled := crossProjectPlatform.?.value.forall(tlBspPlatforms.value.contains) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is good, but to confirm my understanding this plugin will only be enabled for CrossProject
s anyway right? Because of the requires: Plugins = CrossPlugin
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's correct (sorry for the delay). So it should be pretty much safe simply to reference it via
crossProjectPlatform.value
I'm just not sure though if it is possible to have CrossPlugin
required but crossProjectPlatform
not defined.
Strictly saying, it is all up to the CrossPlugin
implementation.
So I think maybe it makes sense to handle such a possibility, just in case.
Yeah, I wish if it was on IDEs too. Unfortunately neither IntelliJ nor VSCode seem to provide such kind of filtering.
I think I can go ahead and create an issue in the sbt-crossproject repo and link this PR as a possible solution example. So we will see if there is any interest in such a feature. Wdyt, does it make sense to give it a try? |
I opened scalameta/metals-feature-requests#332. Update: which I discovered is a duplicate of scalameta/metals#6782 :) |
9514406
to
486abf9
Compare
Finally, I've made the setting less invasive and verified all the cases I was concerned about. However, there's a potential catch with this approach (as a follow up of this discussion): if we define the following combination of settings: ThisBuild / tlBspExcludePlatforms += NativePlatform // disable BSP in all projects for the "Native" platform
LocalProject("fooJS") / bspEnabled := false // also disable for the "JS" platform in the "foo" project specifically then such a combination won't work. In other words, if The issue can be solved though in this way: ThisBuild / tlBspExcludePlatforms += NativePlatform
LocalProject("fooJS") / tlBspExcludePlatforms += JSPlatform So the new setting shouldn't expose any blocker at the last. |
Thanks Sergey! Will take a closer look soon. Did you happen to see portable-scala/sbt-crossproject#152, can we still make use of that here? |
@armanbilge sorry, I overlooked your question. Could you throw in a hint please? |
I thought at some point we had discussed using the |
066eb67
to
62dbe06
Compare
@satorg I think I'd like to move ahead with this, thanks for all your work! Did you have any thoughts on #465 (comment)? |
6091f1c
to
d054a63
Compare
@armanbilge I added one more commit to the PR. It preserves To you question:
Honestly, I'm not sure if it can be utilized here somehow. Currently, the idea is that I think, the best usage pattern of this plugin could be adding a separate file like
It should be a simple and quite harmless approach, I think. Let me know what you think please. Thank you! |
Ah, I missed this. I thought it might be reasonable for the default to disable BSP for alternate platforms in pure crosses. The goal would be to lower the burden for casual contributors, who are unlikely to have a |
@armanbilge
It looks like |
We can have a setting for the "blessed" platform (defaults to JVM). then if it's a pure cross, it will only enable bsp if it's that blessed platform ... yeah, it's not great, but I think it would work in practice. idk, what do you think? |
@armanbilge, personally, I do not mind. But to be honest the "blessed platform" approach would work for me even for CrossProject.Full repos :) So I am not the best judge on that. My only concern though is that if we take a look at a real big repo like Cats for an example, we will find out that roughly a half of its modules are CP.Pure whereas the second half is PC.Full. That means that the "blessed platform" approach will be only a half useful for Cats (or half useless, depending on your perception :) ) Also, maybe it'd make sense to add yet another settings:
Yeah, we can opt-out with Let me know what you think please. Thanks! |
Ok, thanks for that exposition, I see what you are saying!
I propose a slight revision to this. The best usage pattern of this plugin is that:
Does that sound about right? With that in mind can we just have one setting |
Yes, I think it would work even better (because looks simpler). The only caveat though, I think it should be set to empty by default, which would mean that it is not configured and the default logic applies per se. Once it is set to some non-empty value, it should supersede the default logic. |
Hmm, it feels weird to special-case an empty value. We could either use an |
Yes agree, I think it would work too (maybe even better).
it does indeed, but on the other hand, an empty value for |
That means they don't want any BSP 😛 you are right, there are better ways to indicate that. Also, I just realize this setting only works for Ok, enough bike-shed 😁 I'm okay with any of the approaches, even just the empty value. I trust your judgement! |
d054a63
to
f553243
Compare
@armanbilge I've made the change, check it out. To summarize, the last behavior is the following:
|
|
||
object BspControlPlugin extends AutoPlugin { | ||
override def trigger = allRequirements | ||
override def requires: Plugins = CrossPlugin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the CrossPlugin
is enabled for all projects anyway.
There was a problem hiding this 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 all the iterations on this. This is great!
Addresses #405.
Note: targets the
main
branch currently!Introduces a new
tlBspPlatforms
setting ofSet[Platform]
type that controls for which cross-project platforms thebspEnabled
setting should be set totrue
. By default it becomes enabled forJVMPlatform
only.The new setting can be useful to reduce BSP activity for re-compiling projects while editing their code files. Platforms like
JSPlatform
andNativePlatform
usually recompile slower and consume more resources (JVM heap, in particular) upon compilation.How to change the default
How to opt out
.disablePlugins(BspControlPlugin)