├── .gitignore ├── README.md ├── build.sbt ├── project ├── build.properties └── plugins.sbt └── src └── main └── scala └── Hello.scala /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | project/project/ 3 | index.html 4 | index.js 5 | index.wasm 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Scala Native on WebAssembly Demo 2 | First, locally publish https://github.com/scala-native/scala-native/pull/1363 with `sbt rebuild_x32`. 3 | 4 | Then, run the Scala Native linker with `sbt nativeLink`, this will produce errors during compilation and linking, but this is okay because we only care about the generated LLVM. 5 | 6 | Finally, run [Emscripten](https://kripken.github.io/emscripten-site/index.html) to compile to WebAssembly: 7 | 8 | ```bash 9 | emcc target/scala-2.11/native/lib/*.c target/scala-2.11/native/lib/gc/none/**.c target/scala-2.11/native/lib/*.cpp target/scala-2.11/native/*.ll -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s ERROR_ON_UNDEFINED_SYMBOLS=0 -o index.html 10 | ``` 11 | 12 | Then open up `index.html` in a web browser (you may need to serve the directory as a local server due to security restrictions). 13 | -------------------------------------------------------------------------------- /build.sbt: -------------------------------------------------------------------------------- 1 | enablePlugins(ScalaNativePlugin) 2 | 3 | name := "scala-native-wasm" 4 | 5 | scalaVersion := "2.11.12" 6 | 7 | nativeTargetArchitecture := TargetArchitecture.i386 8 | 9 | import scala.scalanative.sbtplugin.ScalaNativePluginInternal.nativeTarget 10 | nativeTarget in Compile := "i386-none-none" 11 | 12 | nativeGC := "none" 13 | 14 | nativeMode := "debug" 15 | -------------------------------------------------------------------------------- /project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version = 0.13.17 2 | -------------------------------------------------------------------------------- /project/plugins.sbt: -------------------------------------------------------------------------------- 1 | addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.3.9-SNAPSHOT") 2 | -------------------------------------------------------------------------------- /src/main/scala/Hello.scala: -------------------------------------------------------------------------------- 1 | object Hello extends App { 2 | println("Hello, World from Scala Native in WebAssembly!") 3 | } 4 | --------------------------------------------------------------------------------