Scala and C – tight as brothers
summary
Scala Native interoperates with C using a binding generator called sbt-bindgen and a growing toolset that already wraps OpenSSL into Java Security, exposes curl as a Java net HTTP client, and provides libpq/SQLite/DuckDB bindings; largest practical limit is 22 C fields for native structs so very large FFmpeg structs (151 fields) are encoded as byte blobs with computed offsets causing alignment pitfalls. There is a tested repo SNBindGen plus a 100% Scala Native web backend using HTTP4s Cats Effect FS2 Skunk and a mono-repo of examples (curl, DuckDB, JNI, Lua, MySQL, OpenSSL, tree-sitter) showing practical but sometimes awkward workarounds like the structs-by-value limitation.
AI-written summary · about
chapters (17)
- 0:00Scala Native and C interop
- 1:08Why Scala Native needs C interop
- 3:13C library integration state
- 4:16C ABI and challenges
- 7:28ABI in action with examples
- 9:36Why C libraries matter
- 10:19Structs and memory layout
- 13:55Recursive definitions and unions
- 16:23Large structs and alignment
- 18:05C enums and macros
- 19:50C macros and attributes complexity
- 21:14Encoding C in Scala
- 22:15C vs Scala Native code
- 23:41C library integration examples
- 24:45SNBindGen introduction
- 25:26SNBindGen demo
- 26:07Conclusion and future
related talks
36mHands-on Scala-Native
29mA brief introduction to systems programming, with Scala Native
49mStarting from Scratch with Scala Native
35mA Deep Dive into Scala Native Internals
41mLessons to Scala Native from Kotlin Native
45mStarting from Scratch with Scala Native
30mExploring JVM Innovations Through the Lens of Scala Native
29mScala on Android
