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

Don't require scalalib to depend on javalib in the build. #3566

Merged

Conversation

WojciechMazur
Copy link
Contributor

This change changes hierarchy of Scala Native projects.
Previously scalalib had dependency on javalib which transitively forced its dependeny on not directly used posixlib, windowslib, even though all it requires is nativelib and clib for atomic ops.

At the time of linking both scalalib and javalib have cyclic dependency on each other, however, at compile time non of each does emit .class or .tasty files and we only have a "weak" dependency enforced by used version of Scala compiler and provided JDK.

New layout does reflect this change

                 ┌───────────┐
                 │Native lib ├──────────────────────────────────┐
                 └─────▲─────┘                                  │
                       │                                        │
       ┌───────────────┼────────────────┐                       │
       │               │                │                       │
   ┌───┴───┐     ┌─────┴────┐    ┌──────┴──────┐                │
   │ C lib │     │POSIX lib │    │ Windows lib │                │
   └───────┘     └──────────┘    └─────────────┘   Bytecode only│
       ▲  ▲            ▲                 ▲                      │
       │  │            │                 │                      │
       │  └────────────┴────────────┬────┘                      │
       │                            │                           │
┌──────┴────────┐                   │                           │
│(Scala)Aux lib │                   │                           │
└───────────────┘                   │                           │
        ▲                           │                           │
        │NIR only                   │                           ▼
   ┌────┴─────┐               ┌─────┴─────┐              ┌──────▼────────┐
   │Scala lib │               │ Java lib  ├─────────────►│ Java lib intf │
   └──────────┘               └───────────┘Bytecode-only └───────────────┘
         ▲                           ▲
         │                           │
         │NIR only                   │NIR only
         │                           │
         └────┬────────────────┬─────┴───────────┬──────────────┐
              │                │                 │              │
        ┌─────┴────┐   ┌───────┴───────┐   ┌─────┴─────┐  ┌─────┴────────┐
        │  Sandbox │   │ TestInterface │   │ UsersMain │  │JUnit runtime │
        └──────────┘   └───────────────┘   └───────────┘  └──────────────┘
                               ▲                 ▲              ▲
                               │                 │              │
                               └─────────────────┼──────────────┘
                                                 │
                                          ┌──────┴─────┐
                                          │ UsersTests │
                                          └────────────┘

What changes here is that scalalib no longer depends on javalib. Dependencies of scalalib need to explictly add dependency on javalib (done automatically in SBT plugin).
Motivation:
At some point we might follow the Scala.js path, and make javalib implementation independent form Scala standard library. (With minimal exceptions, like scala.Predef.classOf[T] at that point we would no longer need to cross compile Javalib for each Scala binary version. Instead, we would be able to compile it once, publish without Scala cross version and use it with any Scala standard library combination

Immidiete improvement comming from this change is speedup of Scalalib publishing when using new model (artifact per each Scala version)

@LeeTibbert
Copy link
Contributor

LeeTibbert commented Oct 11, 2023

This change looks like a huge improvement. The diagram is quite helpful, to the point of being
essential.

When this PR merges, I could put copy of the layout in the Contributing Guide. Yes, the former will change
in time.

I suspect/believe that this PR does away with a whole whack, well a hundred or more whole wacks, of
"There are probably bugs here, but if I look away long enough and turn out the lights, they probably will
not come out on my watch" bugs.

At least as of this PR, I will not have to tweak whenever I see a piece of Scala Collection code or an "Oh, someday
Option will be special cased; just like Scala.js, so I do not have to worry about that bit of code."

The bits of code I wrote whilst trying to avoid Scala collections but where they slipped in anyway, cause
me particular guilt, now unnecessary.

This PR may not look like it, but I think it is a major improvement. Thank you, you have lightened my
burden.

@WojciechMazur WojciechMazur merged commit 3bf21e9 into scala-native:main Oct 12, 2023
80 of 81 checks passed
@WojciechMazur WojciechMazur deleted the build/javalib-hierarchy branch October 12, 2023 11:16
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.

None yet

2 participants