首先用 scala-native 的 g8 模板创建一个脚手架:
$ sbt new scala-native/scala-native.g8
...
A minimal project that uses Scala Native.
name [Scala Native Seed Project]: scala-native-playground
Template applied in /path/to/scala-native-playground
只要输入你想创建的工程的名字,整个脚手架就搭建起来了。
我们试着编译运行一下这个脚手架:
$ cd scala-native-playground
$ sbt
sbt:scala-native-playground> compile
[info] Non-compiled module 'compiler-bridge_2.11' for Scala 2.11.12. Compiling...
[info] Compilation completed in 6.179s.
[info] Done compiling.
[success] Total time: 177 s, completed 2019-2-24 10:24:54
sbt:scala-native-playground> run
[error] no clang60, clang-6.0, clang50, clang-5.0, clang40, clang-4.0, clang39, clang-3.9, clang38, clang-3.8, clang37, clang-3.7, clang found in $PATH. Install clang ( http://www.scala-native.org/en/latest/user/setup.html)
[error] no clang++60, clang++-6.0, clang++50, clang++-5.0, clang++40, clang++-4.0, clang++39, clang++-3.9, clang++38, clang++-3.8, clang++37, clang++-3.7, clang++ found in $PATH. Install clang ( http://www.scala-native.org/en/latest/user/setup.html)
[error] (nativeClang) no clang60, clang-6.0, clang50, clang-5.0, clang40, clang-4.0, clang39, clang-3.9, clang38, clang-3.8, clang37, clang-3.7, clang found in $PATH. Install clang ( http://www.scala-native.org/en/latest/user/setup.html)
[error] (nativeClangPP) no clang++60, clang++-6.0, clang++50, clang++-5.0, clang++40, clang++-4.0, clang++39, clang++-3.9, clang++38, clang++-3.8, clang++37, clang++-3.7, clang++ found in $PATH. Install clang ( http://www.scala-native.org/en/latest/user/setup.html)
[error] Total time: 0 s, completed 2019-2-24 10:26:01
能正常编译,但是运行的时候会报错。按照提示,我们需要安装一些依赖:
$ sudo apt install clang libunwind-dev
然后,在重新在 sbt 的 REPL 里面敲 Run 就可以了。大概是这样:
sbt:scala-native-playground> run
[info] Linking (534 ms)
[info] Discovered 800 classes and 4709 methods
[info] Optimizing (debug mode) (742 ms)
[info] Generating intermediate code (242 ms)
[info] Produced 39 files
[info] Compiling to native code (332 ms)
[info] Linking native code (immix gc) (60 ms)
Hello, world!
[success] Total time: 3 s, completed 2019-2-24 10:27:45
整个过程还是比较流畅的,没有遇到特别浪费时间的事情,by the way,我所用的 Scala Native 版本是 0.3.8,这一点从project/plugins.sbt
可以知道。
$ cat project/plugins.sbt
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.3.8")
====> 点我返回文章目录 <====
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.