Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/nadavwr/scala-native-sbt-jni-example

an example of how to build C code as part of a Scala Native project using sbt-jni
https://github.com/nadavwr/scala-native-sbt-jni-example

cmake sbt-jni scala-native

Last synced: 25 days ago
JSON representation

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

Awesome Lists containing this project

README

        

[sbt-jni](https://github.com/jodersky/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.