Help us understand the problem. What is going on with this article?

Graal VMのnative-imageでscalac-nativeをビルドする

More than 1 year has passed since last update.

基本的にはこちらのページの手順を再現するだけで良いので簡単でした。

環境:
- Mac OS Sierra
- JDK 1.8.0_171
- Scala 2.12.6(brewでインストール)

  • Graal VMをダウンロードして適当に展開する
  • 環境変数JAVA_HOMEを設定する(Java 8でないと動かない?(要確認)ので注意)
$ export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home
  • 環境変数GRAALVM_HOMEを設定する
$ export GRAALVM_HOME=$HOME/graalvm-ce-1.0.0-rc5/Contents/Home
  • 以下を実行する
$ git clone https://github.com/graalvm/graalvm-demos
$ cd graalvm-demos/scala-days-2018/scalac-native/scala-substitutions
$ sbt package
$ cd ../
  • 環境変数SCALA_HOMEを設定する(brewでインストールしたため、通常と違う場所にある点に注意)
$ export SCALA_HOME=/usr/local/Cellar/scala/2.12.6/libexec
  • $ ./scalac-image.sh #時間がかかるのでしばし待つ
$ ./scalac-image.sh                                           
Shutdown Server(pid: 48659, port: 61012)
Build on Server(pid: 51113, port: 62944)*
   classlist:   7,329.88 ms
       (cap):   1,539.01 ms
       setup:   2,721.47 ms
  (typeflow):  44,765.91 ms
   (objects):  14,196.04 ms
  (features):     268.88 ms
    analysis:  61,275.37 ms
    universe:   2,039.23 ms
     (parse):  11,110.12 ms
    (inline):   6,877.22 ms
   (compile):  32,331.02 ms
     compile:  52,528.67 ms
       image:   3,955.90 ms
       write:  20,390.24 ms
     [total]: 150,422.60 ms
  • 起動スクリプト scalac-native で Scalaプログラムをビルドする
$ cat HelloWorld.scala 
object HelloWorld {
  def main(args: Array[String]): Unit = {
    println("Hello, world!")
  }
}

$ time ./scalac-native HelloWorld.scala 
./scalac-native HelloWorld.scala  0.14s user 0.07s system 90% cpu 0.227 total
$ ls *.class
HelloWorld$.class  HelloWorld.class

HelloWorldとはいえ、Scalaプログラムが0.1秒でビルドできるのはちょっと感動です。

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away