vak: (Default)
[personal profile] vak
Оказывается, Скалу теперь можно компилить непосредственно в бинарный код, без всякой Джавы и прочих виртуальных машин. Неплохой язычок получается.

(1) Сначала устанавливаем sbt по инструкции: https://www.scala-sbt.org/1.x/docs/Setup.html

(2) Создаём проект типа "Hello World":
$ sbt new scala-native/scala-native.g8
На запрос надо будет ввести желаемое имя проекта. Я выбрал hello.

(3) Компилируем и запускаем:
$ cd hello
$ sbt run
[info] welcome to sbt 1.6.2 (Ubuntu Java 11.0.17)
[info] loading settings for project hello-build from plugins.sbt ...
[info] loading project definition from /.../hello/project
[info] loading settings for project hello from build.sbt ...
[info] set current project to hello (in build file:/.../hello/)
[info] compiling 1 Scala source to /.../hello/target/scala-3.1.3/classes ...
[info] Linking (1343 ms)
[info] Discovered 663 classes and 3689 methods
[info] Optimizing (debug mode) (1047 ms)
[info] Generating intermediate code (829 ms)
[info] Produced 12 files
[info] Compiling to native code (1583 ms)
[info] Linking native code (immix gc, none lto) (122 ms)
[info] Total (4968 ms)
Hello, world!
[success] Total time: 9 s, completed Nov 21, 2022, 1:11:59 PM
Смотрим исходник:
$ cat src/main/scala/Main.scala 
object Main {
  def main(args: Array[String]): Unit =
    println("Hello, world!")
}
Смотрим бинарник:
$ size target/scala-3.1.3/hello-out 
text data bss dec hex filename
1625129 223248 4928 1853305 1c4779 target/scala-3.1.3/hello-out

$ ldd target/scala-3.1.3/hello-out
linux-vdso.so.1 (0x00007ffe9492a000)
libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f5817600000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f5817517000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f5817895000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f5817200000)
/lib64/ld-linux-x86-64.so.2 (0x00007f5817a93000)

$ ./target/scala-3.1.3/hello-out
Hello, world!
Подробности здесь: https://scala-native.org/en/stable/user/index.html

Date: 2022-11-22 05:54 (UTC)
cali4nickation: (Default)
From: [personal profile] cali4nickation
Вот еще бы без SBT и было бы совсем хорошо.

Date: 2022-11-22 09:31 (UTC)
juan_gandhi: (Default)
From: [personal profile] juan_gandhi

Да бля...