-
Notifications
You must be signed in to change notification settings - Fork 281
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
Toolchain deps infra #1072
Toolchain deps infra #1072
Conversation
Thanks for this! I think there's a lot of sense in having a unified mechanism. |
@@ -0,0 +1,153 @@ | |||
# Developing Toolchains for Deps |
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.
@katre is there a chance you can take a look at this toolchains pattern?
I think this might be valuable for rulesets in general and not only rules_scala.
If you think we're abusing toolchains or just misunderstanding it we'd also love to know that.
One concrete question is whether using a map here is the best solution?
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.
I looked over the PR and the docs, and I'm afraid I don't fully understand what's being implemented. You are adding dependencies to the toolchain that will then also be provided to other, non-toolchain-aware rules, via the normal transitive dependencies? Can you give a concrete example of where this would be useful?
As for the map, I am also confused about why it is a map from a label (which seems to always be a declare_deps_provider) to a string (which is a unique provider id?). Why this direction and not a map of provider id to label?
Lastly, if you are updating your toolchains, have you seen the design for Toolchain Transitions, including the migration steps? This will allow you to declare some toolchain dependencies as being in the target config (for the target being built with the toolchain), and others in the exec config, which may be useful with these deps.
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.
I looked over the PR and the docs, and I'm afraid I don't fully understand what's being implemented. You are adding dependencies to the toolchain that will then also be provided to other, non-toolchain-aware rules, via the normal transitive dependencies? Can you give a concrete example of where this would be useful?
Example: scalac target is java_binary
which isn't aware of scala_toolchain
.
As for the map, I am also confused about why it is a map from a label (which seems to always be a declare_deps_provider) to a string (which is a unique provider id?). Why this direction and not a map of provider id to label?
I haven't found a type for string to label mapping (https://docs.bazel.build/versions/master/skylark/lib/attr.html). I don't like having inverted dict as a compromise, but I failed to find a better alternative.
Lastly, if you are updating your toolchains, have you seen the design for Toolchain Transitions, including the migration steps? This will allow you to declare some toolchain dependencies as being in the target config (for the target being built with the toolchain), and others in the exec config, which may be useful with these deps.
I've looked at toolchain transitions, but I do not see how it fits into our case. Are there good examples to learn from?
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.
If scalac is a java_binary, why doesn't it have a complete set of deps? Can it only be built as a dependency of a scala target? Or have I misunderstood the build graph?
Instead of a string_to_label dict, the typical approach is to use a label_list, and when you get the DepInfo providers (is that the right provider from this attribute?) from the attribute, each DepsInfo has the provider id. Are you ever actually using the same target as different provider ids in different toolchains?
Toolchain transitions are new, and we're still in the migration period. The basic idea is that it allows your toolchain to separate out the tool dependencies (like scalac), which need to run on the execution platform, from your library dependencies (which are actually linked into your final target), and which need to be in the target configuration.
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.
I'll move provider id to DepsInfo. I don't like this approach, but it is semantically more correct. Mapping ids to labels feels more declarative and would be good for mapping the same targets more than once, but inverted map does not allow the same label twice 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.
Thanks, I agree that the previous labe->id map was odd. Feel free to reach out to the Starlark API team on bazel-users and ask about this, but I suspect the answer will be that the label_list system you have is more "bazel-y".
In general, I really like this approach for solving the problem of adding transitive deps to things that consume scala targets. I think linking future toolchain authors to your docs will definitely be useful. Would it be possible for the author to also write a blog post or some other article with a high-level discussion to point other rule authors to? I realize this is even more work, but it could really help the community.
I have migrated |
Can you elaborate on why? |
Mostly to have less changes in current phases. Also scala deps have "special" meaning in scala rules which are design around them. Maybe this needs to be redesigned but I would prefer to do it outside toolchains scope, which is already quite big. |
To make sure I understand- the problem is only priorities and breaking down tasks? I'm treating scalac provider as another validation of your design and want to understand if we got negative signals |
I have refactored dep_providers to label list |
The question is if we want to change current phases. Now there's single phase which brings three depsets with ScalacProvider. Maybe it makes sense to split it into three new phases per depset and get rid of ScalacProvider. I didn't do it as I have no strong opinion about it and it was very easy to hook into existing phase. In general it's no a complicated change, but will touch quite a few places in the current code. |
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 for tagging me in, this is really interesting to see.
scala/providers.bzl
Outdated
"default_repl_classpath": attr.label_list(allow_files = True), | ||
"default_macro_classpath": attr.label_list(allow_files = True), | ||
"deps": attr.label_list(allow_files = True), | ||
"depset_id": attr.string(mandatory = True), |
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.
Unless this is actually somehow a depset, I would suggest renaming.
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 will rename it
@@ -0,0 +1,153 @@ | |||
# Developing Toolchains for Deps |
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 agree that the previous labe->id map was odd. Feel free to reach out to the Starlark API team on bazel-users and ask about this, but I suspect the answer will be that the label_list system you have is more "bazel-y".
In general, I really like this approach for solving the problem of adding transitive deps to things that consume scala targets. I think linking future toolchain authors to your docs will definitely be useful. Would it be possible for the author to also write a blog post or some other article with a high-level discussion to point other rule authors to? I realize this is even more work, but it could really help the community.
scala/toolchains/README.md
Outdated
declare_deps_toolchain( | ||
name = "my_toolchain_impl", | ||
dep_providers = { | ||
":my_compile_deps_provider": "compile_deps", |
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.
I think this is outdated
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 for catching, I will update docs
seems as lint fails |
07f87cf
to
8e6375a
Compare
@ittaiz, I have fixed lint error and issues mentioned in the comments |
This is the first actual PR from Deps Toolchains Infrastructure (#1067)
Opinionated decisions (welcome to discuss!):
Question: maybe we also want to migrate ScalacProvider to DepsInfo map?
N.B. This is a breaking change for users who do not use repositories macros