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

SBT: native-image settings/plugins for JVM only #4574

Merged
merged 1 commit into from
Nov 21, 2024

Conversation

kitbellew
Copy link
Collaborator

No description provided.

@kitbellew
Copy link
Collaborator Author

@jchyb please let me know if this looks ok.

@@ -1,2 +1,2 @@
set -eux
sbt "cli/nativeImageCopy scalafmt"
sbt "cliNative/nativeImageCopy scalafmt"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think Scala Native has much to do with NativeImage, that's a totally different thing if I am not mistaken totally? If we switch from native image to pure Scala native than we would need to just do nativeLinkReleaseFull and then copy the generated binary from target/scala-2.13.15

Do you want to switch the binaries right now? O after the next release?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

goes to show that i am really up to speed here :) so what is native image, then?

let's fix the current state first, then do what you suggest with the switch.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Native image is developed by Oracle, there is more info here and it's an alternative to Scala Native. From what I've seen native image is usually more complicated to set up and the binaries might be bigger, though not 100% sure about that.

The big plus is that we can always ask the developer(s) to help us with fixing some issue and it's focused on Scala.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how interesting... then would it be correct to say that nativeImage should only be built from JVM (i.e., this change should accomplish the exact opposite), since there's no reason to build a native image from an already native result?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, native image is only for JVM.

Just checked and the scala native binary is almost 2x smaller than the native image one in case of scalafmt. And it works without adding any special options. We could probably also optimize it better, so that's also more efficient that native image, though I haven't yet compared the two.

Copy link
Contributor

@jchyb jchyb Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should mention that the 2.13 scala native version might likely be slower then 2.13 native image for now, since parallel collections are not used there, as the scala-parallel-collections library was not ported to scala native yet (they are built into scala stdlib in 2.12, so it's better there).

build.sbt Outdated
Comment on lines 199 to 201
).nativeSettings(
nativeConfig ~= { _.withMode(Mode.releaseFull) },
nativeImageInstalled := isCI,
nativeImageOptions ++= {
Copy link
Contributor

@jchyb jchyb Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar issue as pointed out above, nativeImage settings will be ignored here (basically Native Image still uses classfiles to make a binary file, so it has to use the JVM target, Scala Native compiler outputs something else with the .nir extension, which then the linker uses that to make a binary file.

@kitbellew kitbellew changed the title SBT: native settings/plugins for native platform SBT: native-image settings/plugins for JVM only Nov 20, 2024
@kitbellew kitbellew merged commit ac15c34 into scalameta:main Nov 21, 2024
21 checks passed
@kitbellew kitbellew deleted the 4574 branch November 21, 2024 13:20
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.

3 participants