4

I have not been able to understand if a project intended to be compiled by scala-native can:

  1. Use Java libraries? If yes, does it make scala-native an ahead of time compiler for Java as well as Scala?
  2. Use Scala libraries (compiled to JVM bytecode)

I understand only part of the Scala standard library is available. Is it because there are parts of the implementation using Java standard library?
In case it can't, wouldn't this drawback make it almost impossible for a [non-trivial] project to compile to both the JVM and native using a single code base? Are there plans in this direction?

3 Answers 3

4

I'm far from an expert here but I asked a similar question on Reddit and received the answer that scala-native does not interact with Java libraries (so I took it that it could not compile them either).

It can connect to native ('c') libraries instead.

I don't know of any plans for this to change.

Sign up to request clarification or add additional context in comments.

2 Comments

Any link to the Reddit question? May help a reader follow up if looking for more information.
Is there any update to this as version 0.1 has been released
1

From scale-native.org it should support "fat" jar files, with classifies and NIR files--for example scalaz has added support for scala-native:

Publishing Scala Native supports sbt’s standard workflow for the package distribution:

Compile your code. Generate a jar with all of the classfiles and NIR files. Publish the jar to sonatype, bintray or any other 3rd party hosting service. Once the jar has been published, it can be resolved through sbt’s standard package resolution system.

1 Comment

This means that you CANNOT use Java JARs; you CAN use Scala JARs ONLY if they have been cross-compiled to Scala Native and include NIR files (you cannot use Scala JARs that were not specially cross-compiled to Scala Native)
0

Conceivably JVM-executed Java libraries or Scala libraries could be invoked via JNI analogous to C/C++ invoking those libraries via JNI. The times to do so would be precisely when C/C++ would have needed to do so, which should be somewhere between rare (near zero) and anathema (vilely absolute zero).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.