Skip to content

an example of how to build C code as part of a Scala Native project using sbt-jni

Notifications You must be signed in to change notification settings

nadavwr/scala-native-sbt-jni-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sbt-jni's nativeCompile will compile and link a dynamic library used from Scala code. Scala Native's nativeLink and run will "just work" (with a tiny nudge so that the dynamic library is picked up).

Packaging is somewhat of an issue: package works just fine, and you'll see that the dynamic library is packaged as native/${your_platform}/libprintln0.dylib, but additional work will be needed to be able to use it as part of a dependency jar. Cross-compilation is also not addressed.

Given its stated purpose (JNI...), it is understandable that sbt-jni expects us to build a dynamic library. However, building and linking against a static library is perfectly possible (albeit alongside a dynamic library, so that sbt-jni doesn't complain). See comment at bottom of CMakeLists.txt. It doesn't handle packaging of static libraries out-of-the-box, but all that seems to be within easy reach.

About

an example of how to build C code as part of a Scala Native project using sbt-jni

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published