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

[Feature] Support link debug/release for ScalaJS #384

Open
KristianAN opened this issue Jun 5, 2024 · 8 comments
Open

[Feature] Support link debug/release for ScalaJS #384

KristianAN opened this issue Jun 5, 2024 · 8 comments

Comments

@KristianAN
Copy link
Contributor

Support link debug and release from bloop. this is not exposed through BSP, so there will need to be some bespoke solution or implement support in BSP.

scala-cli has it's own solution for this.
Some files that might be of interest there:
https://github.com/VirtusLab/scala-cli/blob/63db2b1a9c951897dd2b3cd8de01e53024317a76/modules/cli/src/main/scala/scala/cli/commands/package0/Package.scala#L947

https://github.com/VirtusLab/scala-cli/blob/main/modules/options/src/main/scala/scala/build/options/ScalaJsOptions.scala

@KristianAN
Copy link
Contributor Author

I will look into contributing this to BSP/Bloop as a first step.

@oyvindberg
Copy link
Owner

Thanks for looking into this! I really want it myself, just haven't had the need for these platforms in a while. I originally created #14 for this, so it's been in-flight for a quite a while.

Contributing this to BSP should be the preferred option. That way it could (conceptually at least) be shared with scala-cli and others. One particular thing I have noticed which seems unfortunate for us is that bloop seems to treat fastLink/fullLink as part of the project definition instead of something which can be chosen at will. Hopefully a BSP command could at least override that.

Also wanted to note that personally I care much more about getting the functionality I do about BSP itself. So if this looks too hard, I'd be ok with another approach as well.

Two other options we could explore are:

What scala-cli does

basically what you linked to above

Talk to bloop in a non-standard way

Bloop already has this functionality (AFAIU), but it's exposed through the bloop cli interface and not through BSP.
There may be a path where we speak to that directly, though I have not researched if that would be viable.

@KristianAN
Copy link
Contributor Author

I have opened this: build-server-protocol/build-server-protocol#678 as a start.

@KristianAN
Copy link
Contributor Author

KristianAN commented Jun 10, 2024

Also something to note:

template-js:
platform:
jsEmitSourceMaps: false
jsJsdom: false
jsKind: esmodule
jsMode: release
jsNodeVersion: 18.4.0
jsVersion: 1.16.0
name: js
and building with bleep run + vite build produces this:
✓ 6 modules transformed.
../server/webapp/index.html 0.45 kB │ gzip: 0.32 kB
../server/webapp/assets/index-8vwvO0Sm.css 59.59 kB │ gzip: 10.40 kB
../server/webapp/assets/index-zo6RLal9.js 1,894.00 kB │ gzip: 325.85 kB

while this sbt config:
scalaJSLinkerConfig ~= {
_.withModuleKind(ModuleKind.ESModule)
.withModuleSplitStyle(ModuleSplitStyle.SmallModulesFor(List("com.foo.app")))
},

produces:
✓ 70 modules transformed.
../server/webapp/index.html 0.45 kB │ gzip: 0.32 kB
../server/webapp/assets/index-8vwvO0Sm.css 59.59 kB │ gzip: 10.40 kB
../server/webapp/assets/index-v87mSmFM.js 833.13 kB │ gzip: 226.44 kB

.withModuleSplitStyle(ModuleSplitStyle.SmallModulesFor(List("com.foo.app")))

is the key setting here I am guessing.

This is a significant difference in bundle-size. The goal should obviously be that bleep produces as small bundles as sbt. This might be a limitation of bloop though?

@KristianAN
Copy link
Contributor Author

So bloop does not support setting modulesplitstyle, however I do not see any reason why it could not be implemented in bloop. I am guessing it just isn't there because before scalajs 1.16 there was no real reason to use esmodules as closure did not support it, as of 1.16 scalajs has it's own minifier for esmodules.

@KristianAN
Copy link
Contributor Author

I think this issue/bug scalacenter/bloop#1304 is still alive. I think this is blocker? You can hack around it by adding a main object with a main method, however I don't think that is an acceptable experience.

@KristianAN
Copy link
Contributor Author

I have opened this scalacenter/bloop-config#87. Depending on if that get merged I think we can look into using BSP. If it's not merged there is no point in using bloop for JS linking as the bundles will be larger than the scala-cli way.

I have also talked to @tgodzik about supporting linking through bsp, and he had an idea about using the compile interface with an extra argument to link (--with-linking), I have a rough wip branch adding this to the bloop bsp service.

@oyvindberg
Copy link
Owner

nice! Hope we can get that through :)

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