前提
- 筆者の環境は Ubuntu 24.04 系の Linux Mint です。
- AtomVM ドキュメントの Building for Generic UNIX に沿っています。
前準備
$ git clone https://github.com/atomvm/AtomVM.git
...
$ cd AtomVM/
$ git checkout 0220c78ee9e7cf6c763a278b44d81ce309fcf1ab
以下のコミットを指定しているのは、この記事を作成している2026/08/03時点の最新を使うためです。
ビルド
AtomVM の README.md に
AtomVM is tested with code compiled with any version from OTP 21 to 27 (29 is supported only in main branch).
の記載があるので Between Elixir and Erlang/OTP を参照して、 Erlang は 27、 Elixir 1.18 の執筆時点の最新を使うようにしています。
$ pwd
/home/pojiro/Sandbox/AtomVM
$ mkdir build
$ cd build
$ mise use erlang@27.3.4.15
...
$ mise mise use elixir@1.18.3-otp-27
...
$ mix local.hex
$ mix local.rebar
$ cmake ..
-- The C compiler identification is GNU 13.3.0
-- The CXX compiler identification is GNU 13.3.0
...
-- Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so (found version "1.3")
CMake Error at tools/packbeam/CMakeLists.txt:34 (message):
rebar3 is required but was not found
-- Configuring incomplete, errors occurred!
rebar3 is required but was not found
$ which rebar3
$ type rebar3
-bash: type: rebar3: 見つかりません
ないです!
$ which erl
/home/pojiro/.local/share/mise/installs/erlang/27.3.4.15/bin/erl
$ find /home/pojiro/.local/share/mise/installs/ -name "rebar3"
/home/pojiro/.local/share/mise/installs/elixir/1.18.3-otp-27/.mix/elixir/1-18/rebar3
あります!パスが通ってないので一時的にパスを通してこれを使います。
$ export PATH="$MIX_HOME/elixir/1-18:$PATH"
再トライ
$ cmake ..
Found Erlang OTP 27
Found Elixir
...
-- Build files have been written to: /home/pojiro/Sandbox/AtomVM/build
ビルドファイルができました!ので、ビルドします。
$ make
...
[100%] Built target MultiBlink
make -j とすると早くでビルドできますが、どのようなファイルがコンパイルされているか眺めためにつけていません。
眺めていると、
-
*.c.oのビルド -
*.erl、*.exのコンパイル -
*.avmファイルのパッキング
等がされています。*.c.o は最終的に
[ 3%] Built target libAtomVMLinux-x86_64
[ 3%] Building C object src/platforms/generic_unix/CMakeFiles/AtomVM.dir/main.c.o
[ 3%] Linking C executable ../../AtomVM
AtomVM にまとめられるので、 *.c.o は VM のオブジェクトファイルです。
*.erl は例えば以下で
[ 47%] Compiling ssl.erl
[ 47%] Compiling string.erl
[ 47%] Compiling timer.erl
[ 47%] Compiling unicode.erl
[ 47%] Packing archive estdlib.avm
[ 47%] Packing archive estdlib.avm
[ 47%] Built target estdlib_emu
これは名前から推測するに VM 上で動作する Erlang の標準モジュールです。
estdlib.avm としてパックされています。
*.ex は例えば以下で
[ 71%] Compiling String.Chars.Integer.ex
[ 71%] Compiling String.Chars.List.ex
[ 71%] Compiling json.ex
[ 71%] Built target exavmlib_beams
[ 71%] Packing archive exavmlib.avm
[ 77%] Built target exavmlib
これは名前から推測するに VM 上で動作する Elixir の標準モジュールです。
exavmlib.avm としてパックされています。
どこにできたのか?
$ pwd
/home/pojiro/Sandbox/AtomVM/build
$ find ../ -name "AtomVM" -type f
../build/src/AtomVM
ls -lah src/AtomVM
-rwxrwxr-x 1 pojiro pojiro 2.4M 8月 3 16:08 src/AtomVM
2.4M の AtomVM が手に入りました。
実行
$ pwd
/home/pojiro/Sandbox/AtomVM/build
$ src/AtomVM -h
Syntax:
src/AtomVM [-h] [-v] <path-to-avm-or-beam-file>+
Options:
-h Print this help and exit.
-v Print the AtomVM version and exit.
Supply one or more AtomVM packbeam (.avm) files to start your application.
Example:
$ src/AtomVM /path/to/my/application.avm /path/to/atomvmlib.avm
実行できそうです。build ディレクトリの直下には examples ディレクトリができていてそこを調べるといかにもなファイルがあるので実行します。
$ ./src/AtomVM examples/elixir/HelloWorld.avm
Hello World
Console.puts() and Console.print() work with binary or charlist strings.
Return value: ok
このソースファイルはどこにあるのでしょうか?
$ find ../ -name "HelloWorld.ex"
../examples/elixir/HelloWorld.ex
ありました!
$ cat ../examples/elixir/HelloWorld.ex
#
# This file is part of AtomVM.
#
# Copyright 2018 Davide Bettio <davide@uninstall.it>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
#
defmodule HelloWorld do
# this compiler option is to suppress warnings when compiling the VM
# it is not needed or recommended for user apps.
@compile {:no_warn_undefined, [Console]}
def start() do
Console.print("Hello World\n")
Console.puts("Console.puts() and Console.print() work with binary ")
Console.puts(~c"or charlist strings.\n")
Console.flush()
end
end
今日はここまで。