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

binary distribution: package information about jars required for scalac classpath in a separate file #20413

Closed
unkarjedy opened this issue May 15, 2024 · 10 comments

Comments

@unkarjedy
Copy link
Contributor

unkarjedy commented May 15, 2024

Context:

In IntelliJ IDEA, you can use a plain IntelliJ project without build system SBT/Maven/Gradle/BSP.
In Scala Plugin we have a concept of "Scala SDK" which simply represents the scala compiler (classpath) and scala version.
In case the user already has Scala "installed" (whatever that means) IntelliJ has some logic to detect it.
We have multiple kinds of detectors for Brew, SDKMAN, Coursier, Maven, Ivy.

We also have a "System" detector which can detect Scala SDK from the unzipped binary Scala distribution (see Assets at github)
To construct Scala Compiler classpath, we read some jars from lib directory.

In Scala2 the code of constructing the classpath was quite simple. We just search for a fixed set of compiler jars: scala-compiler-2.X.Y.jar, scala-library-2.X.Y.jar, scala-reflect-2.X.Y.jar:

image

Issue

In Scala3 things get different. Scala 3 compiler classpath has more dependencies on more libraries.
In general, each minor/major Scala 3 version can have dependencies on different libraries with different versions.
We can't just include all jars from lib folder. We need an explicit list of compiler classpath dependencies because lib folder contains a lot of other jar files, not required for the compiler. AFAIU most of them are needed for scaladoc, not scalac.

image

With Maven/Coursier/Ivy detectors, we can live with it because we can resolve transitive dependencies for scala3-compiler_3 and get the classpath.
However, with System detector we can't do it.
Three years ago I provided a hardcoded solution for Scala 3.0.0 (see the code)
It worked up to Scala 3.3.1 but shot back in 3.3.2 & 3.4.x (see https://youtrack.jetbrains.com/issue/SCL-22510).

Proposal

I think the only reliable solution is that along with the jar files, scala compiler publishes the classpath required for scalac.
For consistency, it could also publish the classpath for Scaladoc.
For example, it could be just two files:

  • lib/scalac-classpath
  • lib/scaladoc-classpath

Those files could contain a list of jar names or even jar name patterns on every line.
Then in IntelliJ we could simply read that file content.
If you have better ideas on the file names/format, we can discuss it.

Notes

Note that the information about scalac/scaladoc classpath is already known to the code which does the binary distribution packaging. It's already present in bin/common, bin/common.bat, bin/scaladoc, bin/scaladoc.bat.
However, it would be a too fragile solution to rely on those files as their structure can change and our parsing logic can break.

@unkarjedy
Copy link
Contributor Author

Note that the information about scalac/scaladoc classpath is already known to the code which does the binary distribution packaging. It's already present in bin/common, bin/common.bat, bin/scaladoc, bin/scaladoc.bat

I also notice that the classpath used in those scripts has one suspicious extra jar scala3-staging_3*.jar
It's not a transitive dependency of scala3-compiler_3, also it's not reported by SBT (show scalaInstance).

What is that jar? Is it indeed required for scalac classpath?

@bishabosha
Copy link
Member

bishabosha commented May 15, 2024

we were proposing to heavily change the lib directory currently in #20351 (e.g. removing it or perhaps converting the contents to alias links) - so would be good to know if its actually used by other tooling - it seems it is - it would be good to work together on this

@unkarjedy
Copy link
Contributor Author

@bishabosha
Could you please point to the particular place in the discussion mentioning "potential removing of lib folder"?

or perhaps converting the contents to alias links

Alias links to where?

it would be good to work together on this

Is there anything else we can provide from our side?

@bishabosha
Copy link
Member

Is there anything else we can provide from our side?

I updated the PR description of #20351. otherwise you can download the zip from 3.5.0-RC1 release

@bishabosha
Copy link
Member

bishabosha commented May 23, 2024

I also notice that the classpath used in those scripts has one suspicious extra jar scala3-staging_3*.jar
It's not a transitive dependency of scala3-compiler_3, also it's not reported by SBT (show scalaInstance).

What is that jar? Is it indeed required for scalac classpath?

there is also a scala3-tasty-inspector_3 jar to go alongside scala3-staging_3 - these are not normally on the classpath for scala/scalac, but are added to the classpath if the user passes the -with-compiler argument to the launcher. (Typically the user would need to add explicit libraryDependencies to use them in sbt/mill)

@bishabosha
Copy link
Member

@unkarjedy what do you think of the change in #20631 which would add files which provide the classpath?

@unkarjedy
Copy link
Contributor Author

@bishabosha Looks good. Do you already have some nightly/rc build to try it our on our side?

@bishabosha
Copy link
Member

bishabosha commented Jun 21, 2024

Do you already have some nightly/rc build to try it our on our side?

@unkarjedy no but you can build it yourself with sbt dist/packArchive. I hope that this will be coming in 3.5.0-RC3 but that is a long time

@unkarjedy
Copy link
Contributor Author

I think we can close this one.
I've fixed it on IntelliJ side
https://youtrack.jetbrains.com/issue/SCL-22975
https://youtrack.jetbrains.com/issue/SCL-22510

So far it's in 2024.3 Nightly Scala Plugin channel.
It will later be available in EAP/Release

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

No branches or pull requests

2 participants