-
Notifications
You must be signed in to change notification settings - Fork 277
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
Make more use of the toolchain #399
Conversation
relates to #14 |
strange... the OSX has a class not found on the bazel ci, but linux is clear. I wonder if there is some difference in how platforms handle toolchains? Not sure why. Also I tested locally on osx. Will investigate. cc @katre |
well evidently things aren't so reproducible. After running
|
okay, @katre I removed the Why did that work on linux, but not OSX? Should it have worked? |
now, it seems that specs targets fail with strict deps, but not scalatest. It is not clear to me why. Any ideas @ittaiz ? |
Okay, it seems that specs also had a path of bringing in scala-library and scala-compiler. My guess is that somehow, this winds up looking like two separate jars to the strict deps system with the change somehow. Then we get an error. This is pretty hand wavy... but it seems to work if we just remove the dependencies from the specs target and fix an aspect test not to expect them. |
Well done! |
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.
ok.
Re the specs2 test I think it's ok. I think we resolved the underlying reason a while ago and didn't notice.
I think we should roughly define what we'd like the user experience to be and derive back from there.
Ideally I'd like someone to be able to run with either 2.11 or 2.12 toolchains (both supplied by us) which will bring the relevant jars (of std-lib/specs/scalatest/scrooge/proto).
WDYT?
@@ -45,8 +45,6 @@ def _rule_impl(ctx): | |||
"@io_bazel_rules_scala//specs2:specs2", | |||
"@scala//:scala-xml", | |||
"@scala//:scala-parser-combinators", | |||
"@scala//:scala-library", |
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.
@chaoren does this mandate changes in the plugin? So that it will take these dependencies from the toolchain?
@@ -9,6 +9,9 @@ toolchain_type( | |||
scala_toolchain( | |||
name = 'default_toolchain_impl', | |||
scalacopts = [], | |||
library = "//external:io_bazel_rules_scala/dependency/scala/scala_library", |
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.
are you sure this is the way to go? If I understand it correctly this still requires me to change the scala.bzl#scala_repositories method to download 2.12.
@@ -9,6 +9,9 @@ toolchain_type( | |||
scala_toolchain( | |||
name = 'default_toolchain_impl', | |||
scalacopts = [], | |||
library = "//external:io_bazel_rules_scala/dependency/scala/scala_library", | |||
compiler = "//external:io_bazel_rules_scala/dependency/scala/scala_compiler", |
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.
Why are you using //external: dependencies instead of @io_bazel_rules_scala//dependency/scala/scala_compiler?
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.
To make a more minimal change. Before toolchains, we only had bind as a tool that downstream repos could set these values and there are many interchangeable versions that work.
@ittaiz I agree that we want a 2.11 and 2.12 toolchain (heck, maybe even 2.10, I guess). But we are not super close. If we put all the jars in the repo in one toolchain, we kind of forces a lot of jar dependencies on everyone (scala, scalapb, scrooge, specs, etc..). I would prefer to set up each group separately. Do you think we should merge this as a small step, or do we wait until we have it possible to switch out 2.11 for 2.12? |
I think I wasn't clear. |
I don't think there is a way to get data out of the toolchain except in a skylark rule (not macro), since you can't access so, i don't know a good way to store a version string for others to consume. Maybe we output it to a file? i can add |
That's what I mean if we have a way to use it :)
@katre any thoughts how we can solve it?
…On Mon, 22 Jan 2018 at 20:14 P. Oscar Boykin ***@***.***> wrote:
I don't *think* there is a way to get data out of the toolchain except in
a skylark rule (not macro), since you can't access ctx.toolchains unless
you are in a skylark rule.
so, i don't know a good way to store a version string for others to
consume. Maybe we output it to a file?
i can add scala_major_version to the toolchain if you like. Is that what
you mean @ittaiz <https://github.com/ittaiz> ?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#399 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABUIF5Er3-TmlvdWheKwXcl30gEULiisks5tNNAIgaJpZM4RlnCf>
.
|
You're right that macros don't see toolchains (macros are evaluated when the file is loaded, and that's long before a single toolchain is resolved). If something needs to know the version, and the version is in the toolchain, then the "something" needs to be a full rule. |
Going back to the first comment on this PR, are you actually considering adding four more types of toolchains, or are you adding four more types of data to the existing toolchain? I don't have a perference between these, I am just curious about the choices you're making so I can be sure that future toolchains work is taking real world usage into account. |
@katre I don't think we know yet. Basically our challenge is this: pretty much every external jar needs to understand which scala-version we are at. Using select might be useful here, but I guess select can't see the toolchain either? An alternate idea: maybe scala_import can know about the toolchain, and it could get select-like features. Then if we make sure all inputs to scala rules are scala_import, maybe it can handle the multiplexing. |
Oscar, |
@ittaiz but what if Like: scala_import(
name = "foo",
jar_map = {
"jvm_2.11": { jar = "some_jar", sha256 = "... },
"jvm_2.12": ...
}
) or something like this. Its a pain to write it out, but tooling could do it maybe. |
why does |
@ittaiz I think I'm conflating them in my thinking. |
I thought so :) |
closes #380 |
Toolchains are also not available in repository rules. Why does scala_import need the scala version? I'm afraid I don't fully understand this part of the scala rules. |
Also, sorry for the delays in responses, I am in Europe this week so my response times are skewed. |
sure thing, thanks for responding! |
I assume that people won't be using multiple scala versions in the same project. If they are, that gets much more difficult. Based on that assumption, I'd put the scala version into the repository rule as an argument (as I see is proposed). The repository rule can write a BUILD file with a special target (scala_version?) that the toolchain and other rules like scala_import can depend on to learn the expected scala version. Example WORKSPACE:
scala_repository writes a BUILD file in @io_bazel_rules_scala/BUILD:
The scala version rule has a ScalaVersionInfo provider with the version. Then toolchains and other scala rules can depend on @io_bazel_rules_scala//:version, get the ScalaVersionInfo provider, and read the current version string. It's a little complicated, but would that allow defining the version in one place and accessing it from others? |
👍 to @katre's idea. |
1 similar comment
👍 to @katre's idea. |
Sounds like it's our only current choice. |
Unfortunately, repository rules are not part of the analysis phase and will not have access to toolchains. However, a repository rule can write a BUILD file with targets that are part of analysis and can have toolchains. |
so in theory one might be able to say |
Yes, that would be possible. |
ok. I think we have a winner ;) |
Oscar,
What do you think?
…On Thu, 25 Jan 2018 at 12:18 katre ***@***.***> wrote:
Yes, that would be possible.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#399 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABUIF9TvEhhAydvnnZOUB_dLcX_Zf5GZks5tOFTngaJpZM4RlnCf>
.
|
Yes, this sounds like a good plan. |
Toolchains
This is precisely why I've not loved toolchains. This approach is similar to sbt, for which scalaVersion can only be one value at a time. You would then run two separate versions of your build graph.
Explicitly specify in macros In sbt-land, I wound up creating sbt-cross which duplicates sbt projects by scala version (basically, like a Bazel macro). That way, they all live in the same build graph, and I can build them concurrently, etc.
Aspects rules_typescript takes an approach where they use aspects to compute what versions (Ecmascript versions in that case) are needed by downstream targets. It seems complicated to me, but maybe there's something there.
This ties the entire workspace (and this is bazel, so repos/workspaces are large) to a single version. In my experience, the hardest part of upgrading is external dependencies that have not built for you the version you want. And when every project is held up by one, that is challenging. |
Paul,
Have you seen this doc?
https://docs.google.com/document/d/1p7pdEwqnLOC-ATl-FdyHBJdk4Ae-5GzAYDvpJeMh4tU
One of the goals is to allow us to do cross building in what I understand
to be a seamless manner (no macros).
Given the work in the doc will take time to land it sounds reasonable to me
to implement the suggested design for scala and later evolve to full cross
building.
@katre do you think that if we do the design we talked about here a lot of
the work will be redone once configurability lands?
…On Fri, 6 Apr 2018 at 22:57 Paul Draper ***@***.***> wrote:
** Toolchains **
This is essentially saying that Scala version will be wired into
bootstrapping bazel.
This is precisely why I've not loved toolchains.
This approach is similar to sbt, for which scalaVersion can only be one
value at a time. You would then run two separate versions of your build
graph.
A (2.11)
|
C (2.11) B (2.11)
\ /
E (2.11)
A (2.12)
|
B (2.12)
\
F (2.12)
** Explicitly specify in macros **
In sbt-land, I wound up creating sbt-cross
<https://github.com/lucidsoftware/sbt-cross> which automatically
duplicates sbt projects, by scala version. That way, they all live in the
same build graph, and I can build them concurrently, etc.
A (2.11 + 2.12)
|
C (2.11) B (2.11 + 2.12)
\ / \
E (2.11) F (2.12)
** Aspects **
rules_typescript takes an approach where they use aspects to compute what
versions (Ecmascript versions in that case) are needed by downstream
targets. It seems complicated to me, but maybe there's something there.
------------------------------
I assume that people won't be using multiple scala versions in the same
project.
This ties the entire workspace (and this is bazel, so repos/workspaces are
large) to a single version. In my experience, the hardest part of upgrading
is external dependencies that have not built for you the version you want.
And when every project is held up by one, that is challenging.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#399 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABUIFxatu_1by2iRont5pQcU002aGQwHks5tl8i-gaJpZM4RlnCf>
.
|
@ittaiz Sorry, I'm not sure what you mean by "the design" at this point (I admit I haven't been fully following this thread). My understanding is that the major issue is with imported libraries, which implicitly depend on a specific scala version (due to binary incompatbility). Is this correct? I would advise you to go with a design that serves your users now, and once more configurability options become available, we can work together on how to re-implement your rules using the new features. |
replaced by #530 |
This is a small change that I think sets us up to make a scala 2.12 toolchain and merge scala 2.12 into master.
I think the next steps are: